Once you enter switchloop, you seem to never leave
Once you enter switchloop, you seem to never leave
-Bert
The glass is not half full or half empty, Its twice as big as needed for the job!
http://foamcasualty.com/ - Warbird R/C scratch building with foam!
At the start up you going straight to the SWITCHLOOP routine, light up the red, then you never go back to the Main routine to check when SwitchPin became 1 (to increment the ButtonCount to change the color)
Last edited by bogdan; - 14th August 2011 at 01:47.
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 THEN If ButtonCount = 1 THEN GOSUB RedProgram If ButtonCount = 2 THEN GOSUB GreenProgram If ButtonCount = 3 THEN GOSUB BlueProgram If ButtonCount = 4 THEN ButtonCount = 1 ButtonCount = ButtonCount + 1 endif GOTO MAIN RedProgram: PWM Red,127,100 RETURN GreenProgram: PWM Green,127,100 RETURN BlueProgram: PWM Blue,127,100 RETURNCode: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 THEN If ButtonCount = 1 THEN PWM Red,127,100 ENDIF If ButtonCount = 2 THEN PWM Green,127,100 ENDIF If ButtonCount = 3 THEN PWM Blue,127,100 ENDIF If ButtonCount = 4 THEN ButtonCount = 1 ButtonCount = ButtonCount + 1 endif GOTO MAIN
Last edited by mister_e; - 14th August 2011 at 01:51.
Steve
It's not a bug, it's a random feature.
There's no problem, only learning opportunities.
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: IF SwitchPin = 1 THEN If ButtonCount<3 THEN PWM GPIO.0(ButtonCount),127,100 ButtonCount = ButtonCount + 1 ELSE ButtonCount = 0 ENDIF endif GOTO MAIN
Last edited by mister_e; - 14th August 2011 at 02:05.
Steve
It's not a bug, it's a random feature.
There's no problem, only learning opportunities.
Steve, wonderful examples, I think th OP may have a few questions for you, especially in the last with port indexing. But why doesn't his work after he moved the IF into the switchloop section? BTW, he will still have problems with button press being 1 for a zillion loop iterations, don't ya think?
@Brian, if you press the switch repeatedly, will that make the other LED's light? If so, does it seem to be random as to which will light?
-Bert
The glass is not half full or half empty, Its twice as big as needed for the job!
http://foamcasualty.com/ - Warbird R/C scratch building with foam!
Mistake in my 2 first example. Change made in RED
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 THEN If ButtonCount = 1 THEN GOSUB RedProgram If ButtonCount = 2 THEN GOSUB GreenProgram If ButtonCount = 3 THEN GOSUB BlueProgram If ButtonCount = 4 THEN ButtonCount = 1 else ButtonCount = ButtonCount + 1 endif endif GOTO MAIN RedProgram: PWM Red,127,100 RETURN GreenProgram: PWM Green,127,100 RETURN BlueProgram: PWM Blue,127,100 RETURNsorryCode: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 THEN If ButtonCount = 1 THEN PWM Red,127,100 ENDIF If ButtonCount = 2 THEN PWM Green,127,100 ENDIF If ButtonCount = 3 THEN PWM Blue,127,100 ENDIF If ButtonCount = 4 THEN ButtonCount = 1 else ButtonCount = ButtonCount + 1 endif endif GOTO MAIN![]()
Last edited by mister_e; - 14th August 2011 at 02:12.
Steve
It's not a bug, it's a random feature.
There's no problem, only learning opportunities.
Bookmarks