Shop OBEX P1 Docs P2 Docs Learn Events
One Switch and 6 led's — Parallax Forums

One Switch and 6 led's

Jimm2Jimm2 Posts: 16
edited 2010-01-29 01:23 in Propeller 1
[noparse][[/noparse]∑CODE∑ ]
CON
_clkmode = xtal1 + pll16x
_xinfreq = 5_000_000


LEDPin1 = 0
LEDPin2 = 1
SwitchPin = 23

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 := 100_000_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]LEDPin2]~~
else 'switch was not pressed

outa[noparse][[/noparse]LEDPin2]~

else 'the switch is changing faster than the threshold rate

outa[noparse][[/noparse]LEDPin1]~~
[noparse][[/noparse]∑/CODE∑]


This Program works like this.......


State of Switch(11111111111111111)
(ON=1) and (OFF=0) power going to switch and led's
(Ledpin1)(00000000000000000)
(Ledpin2)(11111111111111111)

State of Switch(10010010010010010)
(Ledpin1)(11111111111111111)
(Ledpin2)(11111111111111111)

State of Switch(00000000000000000)
(Ledpin1)(00000000000000000)
(Ledpin2)(00000000000000000)

What I need help with is how can I make (ledpin1) and (ledpin2), not just trun on two Led's, but turn on A set of led's.

Like this..........................


PUB ((((((((((((((((((((((((((((((Ledpin2)))))))))))))))))))))))))))))))))))))))))))))))))))))

dira[noparse][[/noparse]4..9] := %111111
outa[noparse][[/noparse]4..9] := %111111
waitcnt(clkfreq/4 + cnt)
outa[noparse][[/noparse]4..9] := %011111
waitcnt(clkfreq/4 + cnt)
outa[noparse][[/noparse]4..9] := %001111
waitcnt(clkfreq/4 + cnt)
outa[noparse][[/noparse]4..9] := %000111
waitcnt(clkfreq/4 + cnt)
outa[noparse][[/noparse]4..9] := %000011
waitcnt(clkfreq/4 + cnt)
outa[noparse][[/noparse]4..9] := %000001
waitcnt(clkfreq/4 + cnt)
outa[noparse][[/noparse]4..9] := %000000


PUB ((((((((((((((((((((((((((((((((((((((((((((((((((((((((((ledpin1))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))

dira[noparse][[/noparse]4..9] := %111111
outa[noparse][[/noparse]4..9] := %111111
waitcnt(clkfreq/4 + cnt)
outa[noparse][[/noparse]4..9] := %000000


What I am trying to do, that I don't know how to do it. When switch is held down..[noparse][[/noparse]4..9] := %111111 led's are turned on. When switch is held on and held off and on and off and on and off.

It will make it do this..........



dira[noparse][[/noparse]4..9] := %111111
outa[noparse][[/noparse]4..9] := %111111
waitcnt(clkfreq/4 + cnt)
outa[noparse][[/noparse]4..9] := %011111
waitcnt(clkfreq/4 + cnt)
outa[noparse][[/noparse]4..9] := %001111
waitcnt(clkfreq/4 + cnt)
outa[noparse][[/noparse]4..9] := %000111
waitcnt(clkfreq/4 + cnt)
outa[noparse][[/noparse]4..9] := %000011
waitcnt(clkfreq/4 + cnt)
outa[noparse][[/noparse]4..9] := %000001
waitcnt(clkfreq/4 + cnt)
outa[noparse][[/noparse]4..9] := %000000

Comments

Sign In or Register to comment.