Im making an open sign that needs to behave in 2 different ways. when first turned on, i was it to cycle thought O P E N flashing though and repeating, but i also want a second option when i flip a switch i would like it to change all the lights to on solid. but if the switch is turned off agian, start flashing. I think the code i have so far would work, i just want to get a second opinion on the code just to make sure.
Device = 18F2550
Clock = 20
Include "utils.bas"
Dim Switch As PORTA.0
Dim letter1 As PORTB.7
Dim letter2 As PORTB.6
Dim letter3 As PORTB.5
Dim letter4 As PORTB.4
Dim Box As PORTB.3
Sub Debounce()
DelayMS(10)
While Switch = 1
Wend
End Sub
SetAllDigital
Input(Switch)
Low(letter1)
Low(letter2)
Low(letter3)
Low(letter4)
Low(Box)
While True
Repeat
letter1 = 1
DelayMS(1000)
letter2 = 1
DelayMS(1000)
letter3 = 1
DelayMS(1000)
letter4 = 1
DelayMS(1000)
Box = 1
DelayMS(500)
Box = 0
DelayMS(500)
Box = 1
DelayMS(500)
Box = 0
DelayMS(500)
Box = 1
DelayMS(5000)
Box = 0
DelayMS(250)
letter4 = 0
DelayMS(250)
letter3 = 0
DelayMS(250)
letter2 = 0
DelayMS(250)
letter1 = 0
Until Switch = 1
letter1 = 1
letter2 = 1
letter3 = 1
letter4 = 1
Box = 1
Debounce
Wend
Thanks for any help
Change of state with switch
Moderators: David Barker, Jerry Messina
-
- Posts: 2
- Joined: Fri Apr 18, 2008 5:16 pm
- Location: romulus
Change of state with switch
Joshua
Hi, just a quick glance... so I can't comment on functionality or intitialisation.
You'll be using a toggle or rocker switch I assume?
And you'll have alias pin 'Switch' (PortA.0) pulled to Gnd via a resistor?
And toggle switch goes from PortA.0 to V+?
If so, why that Debounce sub?
It'll get stuck.
When switch makes pin high then it pops out of the Repeat-Until loop and will get stuck in Debounce While Switch = 1
Wend
If you are worried about bounce on a toggle just have a 50mS delay.
T0 keep it simple I'd be tempted to use IF structure.
IF Switch=1 then
' Do
Else
' Do flashy thing.
Endif
Also, as an aside if you indent your code and use the code /code in square brackets it makes it easier for others to read.
Just select your code and click the 'Code' button when doing your message.[/code]
But, ultimately the best way is simply to try it . I'm sure it won't explode will it?
You'll be using a toggle or rocker switch I assume?
And you'll have alias pin 'Switch' (PortA.0) pulled to Gnd via a resistor?
And toggle switch goes from PortA.0 to V+?
If so, why that Debounce sub?
It'll get stuck.
When switch makes pin high then it pops out of the Repeat-Until loop and will get stuck in Debounce While Switch = 1
Wend
If you are worried about bounce on a toggle just have a 50mS delay.
T0 keep it simple I'd be tempted to use IF structure.
IF Switch=1 then
' Do
Else
' Do flashy thing.
Endif
Also, as an aside if you indent your code and use the code /code in square brackets it makes it easier for others to read.
Just select your code and click the 'Code' button when doing your message.
Code: Select all
[code]
My Code
But, ultimately the best way is simply to try it . I'm sure it won't explode will it?