I believe it wasn't working properly due to the Interrupt settings which i have now disabled on PortB.0.
I have it working the way i want apart from one thing.
It recognises the push switch, displays the appropriate PWM and then if it reaches 9 goes to 1 again. Also, if no input for 5 seconds it starts the flashing sequence (just to signal the end of the 5 seconds).
How does one get the LEDs to stay in their PWM routine until the switch is pressed again, without using Interrupts. When the swicth is pushed it goes to the appropriate PWM routine but after the PWM cycle, the LED goes off.
Here is the code.
Code:
MyNumber VAR Byte ' Variable 1-9
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
DISABLE INTERRUPT
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
gosub mynumberpwm
MyNumber=MyNumber+1
If MyNumber>9 then MyNumber=1
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
Many thanks,
Steve
Bookmarks