' {$STAMP BS2} ' {$PBASIC 2.5} i VAR Byte color VAR Nib rand VAR Byte dr VAR Byte dg VAR Byte db VAR Byte r VAR Byte g VAR Byte b VAR Byte rr VAR Byte rg VAR Byte rb VAR Byte Red PIN 2 Green PIN 1 Blue PIN 0 'GOTO RandomColors GOTO ShiftingColors 'GOTO LEDTest ShiftingColors: rand = 188 r = 200 g = 200 b = 200 dr = 2 dg = 2 db = 2 DO 'DEBUG "(", DEC r, ",", DEC g, ",", DEC b, ") d: (", DEC dr, ",", DEC dg, ",", DEC db, ")",CR PWM Red, r, 1 PWM Green, g, 1 PWM Blue, b, 1 ' Only go through the delta change sequence ~96% of the time. ' I doubt that's actually 96% as RANDOM is a PRNG.. Experimentation picked 10 ' This is b/c the stamp is so damn SLOW. =) IF rand > 10 THEN RANDOM rand IF rand < 85 THEN dr = -dr ELSEIF rand < 170 THEN dg = -dg ELSE db = -db ENDIF ENDIF r = r + dr g = g + dg b = b + db IF r = 2 OR r = 254 THEN dr = -dr r = r + dr ENDIF IF g = 2 OR g = 254 THEN dg = -dg g = g + dg ENDIF IF b = 2 OR b = 254 THEN db = -db b = b + db ENDIF LOOP RandomColors: rr = 188 rg = 143 rb = 8 DO FOR i = 0 TO 50 PWM Red, rr, 1 PWM Green, rg, 1 PWM Blue, rb, 1 NEXT RANDOM rr RANDOM rg RANDOM rb LOOP LEDTest: FOR color = Red TO Blue FOR i = 255 TO 200 'DEBUG " - Duty: ", DEC i, CR PWM Color, i, 20 NEXT NEXT END