text: //
  // automatically generated by spin2cpp v1.93 on Tue Aug 11 09:49:47 2015
  // spin2cpp --ccode --main demo.spin 
  //
  
  //   MMA7660 accelerometer
  // =================================================================================================
  //
  //   File....... light.spin
  //   Purpose.... Charlieplex driver for Parallax Open Source eBadge
  //   Author..... Jon "JonnyMac" McPhalen
  //               Copyright (C) 2015 Jon McPhalen
  //               -- see below for terms of use
  //   E-mail..... jon@jonmcphalen.com
  //   Started....
  //   Updated.... 06 JUL 2015
  //
  // =================================================================================================
  /* 
  
     Blue LEDs (enable bits in ledbits.byte[0] as %00543210)      
  
         B5   B4   B3   B2   B1   B0                                      Layout       
         ---  ---  ---  ---  ---  ---                              --------------------
     P8   Z    Z    H    L    H    L                               B5                B0
     P7   L    H    L    Z    Z    H                               B4                B1
     P6   H    L    Z    H    L    Z                               B3                B2
  
  
     RGB LEDs (enable bits in ledbits.byte[1] as %00RGBrgb)
  
         R2   G2   B2   r1   g1   b1                                      Layout   
         ---  ---  ---  ---  ---  ---                              -------------------- 
     P3   H    Z    L    L    Z    H                                   G2        g1  
     P2   L    L    Z    H    H    Z                                                   
     P1   Z    H    H    Z    L    L                                 R2  B2    r1  b1
  
   */
  #include <propeller.h>
  #include "badgetools.h"
  
  /*
  #ifdef __GNUC__
  #define INLINE__ static inline
  //define PostEffect__(X, Y) __extension__({ int32_t tmp__ = (X); (X) = (Y); tmp__; })
  #else
  #define INLINE__ static
  static int32_t tmp__;
  #define PostEffect__(X, Y) (tmp__ = (X), (X) = (Y), tmp__)
  #define waitcnt(n) _waitcnt(n)
  #define coginit(id, code, par) _coginit((unsigned)(par)>>2, (unsigned)(code)>>2, id)
  #define cognew(code, par) coginit(0x8, (code), (par))
  #define cogstop(i) _cogstop(i)
  #endif
  */
  
  uint8_t leddat[] = {
    0xf0, 0xd7, 0xbc, 0xa0, 0x6b, 0xd8, 0xbc, 0x08, 0x6c, 0xbc, 0xbc, 0xa0, 0x1f, 0xbc, 0xfc, 0x60, 
    0x6c, 0xbe, 0xbc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e, 0x00, 0x7c, 0x5c, 
  };
  
  light badgeLight;
  light *ledsself;
  
  int32_t 	cpcog;
  
  int32_t light_start(void)
  {
    ledsself = &badgeLight;
    // Start conference badge charlieplex driver
    // stop cog if running
    light_stop();
    // base of blue group
    ((uint8_t *)(int32_t)(&ledsself->ledbits))[0] = BLU_CP0;
    // base of rgb group
    ((uint8_t *)(int32_t)(&ledsself->ledbits))[1] = RGB_CP0;
    // update LEDs at 300Hz 
    ledsself->cycleticks = (CLKFREQ / 300) / 6;
    // start pasm cog
    ledsself->cog = cognew((int32_t)(&(*(int32_t *)&leddat[0])), (int32_t)(&ledsself->ledbits)) + 1;
    return ledsself->cog;
  }
  
  /* 
  
    Copyright (C) 2015 Jon McPhalen
  
    Terms of Use: MIT License
  
    Permission is hereby granted, free of charge, to any person obtaining a copy of this
    software and associated documentation files (the "Software"), to deal in the Software
    without restriction, including without limitation the rights to use, copy, modify,
    merge, publish, distribute, sublicense, and/or sell copies of the Software, and to
    permit persons to whom the Software is furnished to do so, subject to the following
    conditions:
  
    The above copyright notice and this permission notice shall be included in all copies
    or substantial portions of the Software.
  
    THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
    INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A
    PARTICULAR PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
    HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF
    CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE
    OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
  
   */
  