Hi Brian
Take a look at this code. ButtonCount starts with 0 and then loops between 1 and 3 depending on your button presses. You may want it to roll over to 0 and have an all off program too. EDIT : My post assumes you are using a high input as indication of switch being pressed.
Code:Red var GPIO.0 Green var GPIO.1 Blue var GPIO.2 SwitchPin var GPIO.3 ButtonCount VAR BYTE ButtonCount = 0 ;Make sure LEDs are off HIGH Red HIGH Green HIGH Blue MAIN: SWITCHLOOP: if SwitchPin = 1 then ButtonCount = ButtonCount+1 if ButtonCount > 3 then ButtonCount = 1 while SwitchPin = 1: wend ' wait here while the switch remains pressed endif If ButtonCount = 1 THEN GOSUB RedProgram If ButtonCount = 2 THEN GOSUB GreenProgram If ButtonCount = 3 THEN GOSUB BlueProgram GOTO SWITCHLOOP END RedProgram: PWM Red,127,100 RETURN GreenProgram: PWM Green,127,100 RETURN BlueProgram: PWM Blue,127,100 RETURN END




Bookmarks