Hello all,
I have a piece of code for PBP that i guess i need help with and am hoping someone will be able to point out the issue. Its a simple RGB LED circuit that when you push the button, should flip to the next color in a subroutine then at the end of the colors, go back to the start. Posting my code below, it may be the incorrect way to do it. It just sits on 'Red' as its the value for ButtonCount. I can change that value to 1,2,3 & compile/program and get ir to display the correct color, but it will not switch colors. Any suggestions will be much appreciated. Thanks in advance.
Code:
Red var GPIO.0
Green var GPIO.1
Blue var GPIO.2
SwitchPin var GPIO.3
ButtonCount VAR BYTE
ButtonCount = 1
;Make sure LEDs are off
HIGH Red
HIGH Green
HIGH Blue
MAIN:
IF SwitchPin = 1 THEN ButtonCount = ButtonCount + 1
GOTO SWITCHLOOP
END
SWITCHLOOP:
If ButtonCount = 1 THEN GOSUB RedProgram
If ButtonCount = 2 THEN GOSUB GreenProgram
If ButtonCount = 3 THEN GOSUB BlueProgram
If ButtonCount = 4 THEN ButtonCount = 1
GOTO SWITCHLOOP
END
RedProgram:
PWM Red,127,100
RETURN
GreenProgram:
PWM Green,127,100
RETURN
BlueProgram:
PWM Blue,127,100
RETURN
END
Bookmarks