Many thanks for your help Melanie, almost there.
I have tried to set up a visual represenattion of where the variable is at. To make things easier i have set it from 1 to 9. Depending on what number it is, depends what LEDs are lit.
I have used PWM on each LED so 1-3 is RED, lit dim for 1 and bright for 3. Then GREEN 4-6 and BLUE 7-9.
After the 5 second time out, i thought it would goto to the MAIN code, again this is signalled by a flashing LED sequence so i know it has times out on the 5 seconds.
A couple of problems at the moment, the code seems slow to show the coloured PWM LED. Also after the 5 second time out, it doesn't goto the main code.
I would like the coloured LED to stay lit at whatever stage until the next button push or unitl the time out occurs. Does the code below look right to you to achieve this? I'm sure i have done something wrong.
The idea is there, just not the practicle side of things for me yet!!
Thanks again,Code:TRISB = %00000001 MyNumber VAR Byte ' Variable 1-10 MyTimeOut VAR Byte ' 5 second Timeout (100 loops of 50mS) Red VAR PORTB.1 ' All LEDs Green VAR PORTB.2 ' Connected between Blue VAR PORTB.3 ' RC pins and ground Orange VAR PORTB.4 MyButton VAR PortB.0 ' Pin goes LOW when Button pressed MyNumber=1 ' Power-On with this starting value MyTimeOut=0 ' TimeOut starts from zero at Power-Up While MyTimeOut<100 If MyButton=0 then MyNumber=MyNumber+1 If MyNumber>9 then MyNumber=1 gosub MyNumberPWM MyTimeOut=0 Pause 50 ' This Pause DEBOUNCES Button - do not remove it While MyButton=0:Wend ' Wait here if Button held down else MyTimeOut=MyTimeOut+1 Pause 50 ' This Pause is the Timeout Pause endif Wend main: high Orange pause 500 low Orange pause 500 goto main MynumberPWM: If Mynumber = 1 then PWM Red,1,255 If Mynumber = 2 then PWM Red,25,255 If Mynumber = 3 then PWM Red,255,255 If Mynumber = 4 then PWM green,1,255 If Mynumber = 5 then PWM green,25,255 If Mynumber = 6 then PWM green,255,255 If Mynumber = 7 then PWM BLUE,1,255 If Mynumber = 8 then PWM BLUE,25,255 If Mynumber = 9 then PWM BLUE,255,255 RETURN
Steve




Bookmarks