Program work's ok, But I need it to work better.
What I want is, First thing is when I push down on the switch (pin 23) and hold it down. All the led's go on, then when I let go of the switch, they go the (left to right or (turn in the program). I want it to just turn off the Led's. Is there A way I can put in A [noparse][[/noparse]goto100] and go to the end of the (left to right Led's or (turn in the program) And just turn off the led's?
The next thing is I hold down on the switch and let go of the switch, and thing's work ok. I let the chip sit, for A bit and the led's (left to right or (turn in program)) come on sometime and turn off sometimes. Why is this doing this and what can I do to stop it?
Here is the Program...........................
Thank you and have A good one.............
The next thing is I hold down on the switch and let go of the switch, and thing's work ok. I let the chip sit, for A bit and the led's (left to right or (turn in program)) come on sometime and turn off sometimes. Why is this doing this and what can I do to stop it?
Here is the Program...........................
CON
_clkmode = xtal1 + pll16x
_xinfreq = 1_000_000
LEDpin1 = 0
LEDPin2 = 17
SwitchPin = 23
OBJ led: "LEDBlink"
Var
long LastSwitchChange
long RateThreshold
long LastCNTValue
long ResultCNT
byte SwitchStatus
Pub start
Dira[noparse][[/noparse]LEDPin1]~~
Dira[noparse][[/noparse]LEDPin2]~~
Dira[noparse][[/noparse]SwitchPin]~
RateThreshold := 000_500_000
LastCNTValue := cnt
repeat
ResultCNT := cnt - LastCNTValue
if Ina[noparse][[/noparse]SwitchPin] <> SwitchStatus 'is the state of the switch different from the last time it changed?
LastCNTValue := cnt 'lets record this time
SwitchStatus := Ina[noparse][[/noparse]SwitchPin] 'store this as the current switch status
if ResultCNT > RateThreshold 'we have gone over our threshold with no change in the SwitchStatus
'this means either the switch was held down or not pressed
outa[noparse][[/noparse]LEDpin1]~
If SwitchStatus == 1 'Switch was held
outa[noparse][[/noparse]LED.down]~~
else 'switch was not pressed
outa[noparse][[/noparse]LEDpin2]~
'the switch is changing faster than the threshold r
else 'the switch is changing faster than the threshold rate
outa[noparse][[/noparse]LED.turn]~~
PUB Turn dira[noparse][[/noparse]0..19] := %11111111111111111111 outa[noparse][[/noparse]0..19] := %11111111111111111111 waitcnt(clkfreq/4 + cnt) outa[noparse][[/noparse]0..19] := %01111111111111111111 waitcnt(clkfreq/4 + cnt) outa[noparse][[/noparse]0..19] := %00111111111111111111 waitcnt(clkfreq/4 + cnt) outa[noparse][[/noparse]0..19] := %00011111111111111111 waitcnt(clkfreq/4 + cnt) outa[noparse][[/noparse]0..19] := %00001111111111111111 waitcnt(clkfreq/4 + cnt) outa[noparse][[/noparse]0..19] := %00000111111111111111 waitcnt(clkfreq/4 + cnt) outa[noparse][[/noparse]0..19] := %00000111111111111111 waitcnt(clkfreq/4 + cnt) outa[noparse][[/noparse]0..19] := %00000011111111111111 waitcnt(clkfreq/4 + cnt) outa[noparse][[/noparse]0..19] := %00000001111111111111 waitcnt(clkfreq/4 + cnt) outa[noparse][[/noparse]0..19] := %00000000111111111111 waitcnt(clkfreq/4 + cnt) outa[noparse][[/noparse]0..19] := %00000000011111111111 waitcnt(clkfreq/4 + cnt) outa[noparse][[/noparse]0..19] := %00000000001111111111 waitcnt(clkfreq/4 + cnt) outa[noparse][[/noparse]0..19] := %00000000000111111111 waitcnt(clkfreq/4 + cnt) outa[noparse][[/noparse]0..19] := %00000000000011111111 waitcnt(clkfreq/4 + cnt) outa[noparse][[/noparse]0..19] := %00000000000001111111 waitcnt(clkfreq/4 + cnt) outa[noparse][[/noparse]0..19] := %00000000000000011111 waitcnt(clkfreq/4 + cnt) outa[noparse][[/noparse]0..19] := %00000000000000001111 waitcnt(clkfreq/4 + cnt) outa[noparse][[/noparse]0..19] := %00000000000000000111 waitcnt(clkfreq/4 + cnt) outa[noparse][[/noparse]0..19] := %00000000000000000011 waitcnt(clkfreq/4 + cnt) outa[noparse][[/noparse]0..19] := %00000000000000000001 waitcnt(clkfreq/4 + cnt) outa[noparse][[/noparse]0..19] := %00000000000000000000 waitcnt(clkfreq/4 + cnt) PUB Down dira[noparse][[/noparse]0..19] := %11111111111111111111 outa[noparse][[/noparse]0..19] := %11111111111111111111 waitcnt(clkfreq/4 + cnt) outa[noparse][[/noparse]0..19] := %00000000000000000000
Thank you and have A good one.............
