'Stamp code used on Color Mixer ' {$STAMP BS2} '{$PBASIC 2.5) A2Ddata CON 4 A2Dclock CON 5 A2Dcs CON 6 A2DdataPulse CON 7 A2DclockPulse CON 8 A2DcsPulse CON 9 REDled CON O GREENled CON 1 BLUEled CON 2 result VAR Byte resultPulse VAR Byte LOOPS VAR Byte Red VAR Byte Green VAR Byte Blue VAR Byte UltraRed VAR Byte Colors VAR Byte ColorDelay VAR Byte Btn PIN 15 Btn2 PIN 14 KnobSelect PIN 10 btnWrk VAR Byte btnWrk2 VAR Byte Setup: DIR0 = %1 'make P0,1,2 output pin’S DIR1 = %1 DIR2 = %1 DIR3 = %1 'ultra red pin DIR15 = %0 'make P15 an input pin used to toggle through colors DIR14 = %0 'make P14 an input - used to switch between toggle mode and scan through color mode D|R10 = %0 'make P10 an lnput p|n to read swltch to selected between knob control or control via flash and toggle swntch control HIGH A2Dcs HIGH A2DcsPulse Main: Colors = 0 'Red ..start off red and cycle through rainbow on press of buttton ColorDelay = 0 Loopper: 'Check for button press GOSUB Read_the_A2D_Pulse 'DEBUG HOME 'DEBUG "Ado for Pulse DEC resultPulse, " ", CR 'will show value between 0 To 255 IF (Knobselect = 1 )THEN GOSUB Read_the_A2D_Color 'DEBUG HOME 'DEBUG "Adc for Color...", DEC result, " ", CR 'will show value between O To 255 GOTO knob_Control ENDIF BUTTON Btn2, 0, 4, 1, btnWrk2, 0, No_Press2 IF (Colors >= 252 )THEN Colors = 0 ENDIF Colors = Colors + 12 result = Colors ColorDelay = 0 PAUSE 50 'DEBUG "Flash color change made" 'GOTO ByPassColorTogg|eBtn 'ELSE 'ColorDe|ay = ColorDelay +1 'DEBUG "coloredelay incremented" 'GOTO ByPassColorToggleBtn 'ENDIF No_Press2: 'BUTTON Btn, 0, 255, 1, btnWrk, O, No_Press ' Colors = Colors +12 ' result=Colors 'ByPassColorToggleBtn: 'DEBUG "Bypasscolortogglebtn " 'IF (Colors >= 246) THEN 'Colors = 3 ‘reset color seq to start...red 'result = Colors 'ENDIF Knob_Control: No_Press: IF (resultPulse >= 3)THEN ‘Causes pulsing of leds LOW REDled LOW GREENled LOW BLUEled PAUSE resultPulse/2 'O-64k in msec ENDIF 'DEBUG HOME 'DEBUG "Adc for Color. DEC resultPulse/2, " ", CR 'will show value between O To 255 'DEBUG "no press " IF (result <= 12 ) THEN 'red GOSUB Red_1 ELSEIF (result <= 24)THEN 'red-orange GOSUB Red_Orange ELSEIF (result <= 36)THEN 'orange GOSUB Orange_1 ELSEIF (result <= 48) THEN 'orange-yellow GOSUB Orange_Yellow ELSEIF (result <= 60) THEN 'yellow GOSUB Yellow ELSEIF (result <= 72) THEN 'yellow-green GOSUB Yellow_Green ELSEIF (result <= 84) THEN 'green GOSUB Green_1 ELSEIF (result <= 96) THEN 'green-blue GOSUB Green_Blue ELSEIF (result <= 108)THEN 'cyan GOSUB Cyan ELSEIF (result <= 12O)THEN 'pastel blue GOSUB Pastel_Blue ELSEIF (result <= 132) THEN 'blue GOSUB Blue_1 ELSEIF (result <= 144) THEN 'blue-purple GOSUB Blue_Purple ELSEIF (result <= 156) THEN 'purple GOSUB Purple ELSEIF (result <= 168) THEN 'purple-pink GOSUB Purple_Pink ELSEIF (result <= 180) THEN 'pink GOSUB Pink ELSEIF (result <= 192) THEN 'hot pink GOSUB Hot_Pink ELSEIF (result <= 204)THEN 'white GOSUB White_1 ENDIF 'had to use other if else combonation due to limitation of Stamp IF (result <= 204) THEN 'null ELSEIF (result <= 216)THEN 'Super Pink GOSUB Super_Pink ELSEIF (result <= 228) THEN 'Ultra Hot Pink GOSUB Ultra_Hot_Pink ELSEIF (result <= 240) THEN 'Ultra Orange GOSUB Ultra_Orange ELSEIF (result <= 255) THEN 'Ultra Red GOSUB Ultra_Red ENDIF GOTO Loopper 'subroutine to read the Analog to Digital Converter Read_the_A2D_Color: LOW A2Dcs SHIFTIN A2Ddata, A2Dclock, MSBPOST, [result\9] HIGH A2Dcs RETURN 'subroutine to read the Analog to Digital Converter Read_the_A2D_Pulse: LOW A2DcsPulse SHIFTIN A2DdataPulse, A2DclockPulse, MSBPOST, [resultPulse\9] HIGH A2DcsPulse RETURN Red_1: OUTA = %0001 OUTA = %0001 OUTA = %O001 OUTA = %0001 OUTA = %0001 OUTA = %0001 OUTA = %0001 OUTA = %0001 OUTA = %0001 OUTA = %0001 RETURN Red_Orange: OUTA = %0001 OUTA = %0011 OUTA = %0001 OUTA = %0001 OUTA = %0011 OUTA = %0001 OUTA = %0001 OUTA = %0011 OUTA = %0001 OUTA = %0011 RETURN Orange_1: OUTA = %0011 OUTA = %0001 OUTA = %0011 OUTA = %0001 OUTA = %0011 OUTA = %0001 OUTA = %0011 OUTA = %0001 OUTA = %0011 OUTA = %0011 RETURN Orange_Yel|ow: OUTA = %0011 OUTA = %0011 OUTA = %0011 OUTA = %0001 OUTA = %0011 OUTA = %0001 OUTA = %0011 OUTA I %0011 OUTA = %0001 OUTA = %0011 RETURN Yellow: OUTA = %0011 OUTA = %0011 OUTA = %0011 OUTA = %0011 OUTA = %0011 OUTA = %0011 OUTA = %0011 OUTA = %0011 OUTA = %0011 OUTA = %0011 RETURN Ye||ow_Green: OUTA = %0011 OUTA = %0010 OUTA = %0011 OUTA = %0011 OUTA = %0010 OUTA = %0011 OUTA = %0010 OUTA = %0011 OUTA = %0010 OUTA = %0011 RETURN Green_1: OUTA = %0010 OUTA = %0010 OUTA = %0010 OUTA = %0010 OUTA = %0010 OUTA = %0010 OUTA = %0010 OUTA = %0010 OUTA = %0010 OUTA = %0010 RETURN Green_Blue: OUTA = %0110 OUTA = %0010 OUTA = %0110 OUTA = %0010 OUTA = %0110 OUTA = %0010 OUTA = %0110 OUTA = %0010 OUTA = %0110 OUTA = %0110 RETURN Cyan: OUTA = %0110 OUTA = %0110 OUTA = %0110 OUTA = %0110 OUTA = %0110 OUTA = %0110 OUTA = %0110 OUTA = %0110 OUTA = %O110 OUTA = %0110 RETURN Pastel_Blue: OUTA = %0110 OUTA = %0110 OUTA = %0110 OUTA = %0100 OUTA = %0100 OUTA = %0100 OUTA = %0100 OUTA = %0110 OUTA = %0110 OUTA = %0110 RETURN Blue_1: OUTA = %0100 OUTA = %0100 OUTA = %0100 OUTA = %0100 OUTA = %0100 OUTA = %0100 OUTA = %0100 OUTA = %0100 OUTA = %0100 OUTA = %0100 RETURN Blue_Purple: OUTA = %0101 OUTA = %0101 OUTA = %0100 OUTA = %0100 OUTA = %0100 OUTA = %0100 OUTA = %0100 OUTA = %0100 OUTA = %O101 OUTA = %0101 RETURN Purple: OUTA = %0101 OUTA = %0101 OUTA = %0101 OUTA = %0101 OUTA = %0100 OUTA = %0100 OUTA = %0100 OUTA = %0100 OUTA = %0101 OUTA = %0101 RETURN Purple_Plnk: OUTA = %0101 OUTA = %0101 OUTA = %0101 OUTA = %0101 OUTA = %0101 OUTA = %0101 OUTA = %0100 OUTA = %0100 OUTA = %0101 OUTA = %0101 RETURN Pink: OUTA = %O101 OUTA = %0101 OUTA = %0101 OUTA = %0101 OUTA = %0101 OUTA = %0101 OUTA = %0101 OUTA = %0101 OUTA = %0101 OUTA = %0101 RETURN Hot_Pink: OUTA = %0101 OUTA = %0101 OUTA = %0101 OUTA = %0001 OUTA = %0001 OUTA = %0001 OUTA = %0001 OUTA = %0001 OUTA = %0101 OUTA = %0101 RETURN White_1: OUTA = %0111 OUTA = %0111 OUTA = %0111 OUTA = %0111 OUTA = %0111 OUTA = %0111 OUTA = %0111 OUTA = %0111 OUTA = %0111 OUTA = %0111 RETURN Super_Pink: OUTA = %1111 OUTA = %1111 OUTA = %1111 OUTA = %1111 OUTA = %1111 OUTA = %1111 OUTA = %1111 OUTA = %1111 OUTA = %1111 OUTA = %1111 RETURN Ultra_Hot_Pink: OUTA = %1101 OUTA = %1101 OUTA = %1101 OUTA = %1101 OUTA = %1101 OUTA = %1101 OUTA = %1101 OUTA = %1101 OUTA = %1101 OUTA = %1101 RETURN Ultra_Orange: OUTA = %1011 OUTA = %1011 OUTA = %1011 OUTA = %1011 OUTA = %1011 OUTA = %1011 OUTA = %1011 OUTA = %1011 OUTA = %1011 OUTA = %1011 RETURN Ultra_Red: OUTA = %1001 OUTA = %1001 OUTA = %1001 OUTA = %1001 OUTA = %1001 OUTA = %1001 OUTA = %1001 OUTA = %1001 OUTA = %1001 OUTA = %1001 RETURN END