' ' Simple color blending for Bi-color LED with a bit of power saving thrown in. ' ' picaxe08m connected drive 2 leds (in one package) via approx 330 ohm resistor ' ' use with BlendLight v1 schematic, note that outputs are inverted because of ' LED diode direction (tied to +5v) ' ' Dec 2006 A. Stein, MedCosm, LLC. ' symbol LEDred=1 'LED1 (red) pinout symbol LEDgreen=2 'LED2 (green) pinout symbol redValue=b0 'red value symbol greenValue=b1 'green value symbol randomw=w1 'allocate storage for random variable symbol randomb1=b2 symbol randomb2=b3 symbol k=b6 symbol intensity=b8 symbol numberColorChanges=4 symbol blendStep=b9 symbol blendValue=b11 'current blend value (0-255) symbol newBlendValue=b12 symbol oldBlendValue=b13 symbol debugMode=1 ' eliminate powersave for debug purposes 'init variables init: blendstep=5 '1 for smooth blend, 10 for stepped blend randomw=1234 blendValue=128 'start of execution loop startexec: startColorChange: setfreq m8 'double clock freq to mitigate flickering gosub rampup random randomw blendStep=randomb2 % 10 + 1 'pick step to get there for k = 1 to numberColorChanges random randomw 'get new random values newBlendValue=randomb1 'for new blend ' debug 'and step to new value if newBlendValue > oldBlendValue then for blendValue=oldBlendValue to newBlendValue step blendStep gosub glowBlend next blendValue else for blendValue=oldBlendValue to newBlendValue step -blendStep gosub glowBlend next blendValue endif oldBlendValue=newBlendValue 'set blend value for next time next k gosub rampdown setfreq m4 'set clock to normal in case we want to download new code ' goto startColorChange 'debug mode gosub LEDsoff 'turn off sleep 12 'sleep about 30 secs ' nap 7 goto startexec rampup: for intensity=1 to 100 step 1 gosub glowBlend next intensity return rampdown: for intensity=100 to 1 step -1 gosub glowBlend next intensity return 'display blended colors on LED '(blendValue, intensity) glowBlend: redValue=blendValue * intensity / 100 redValue=255 - redValue greenValue=255-blendvalue * intensity / 100 greenValue=255-greenValue pwm LEDgreen, greenValue, 1 pwm LEDred, redValue, 1 return LEDsoff: high LEDgreen high LEDred return