One Switch and 6 led's
Jimm2
Posts: 16
[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
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
Firstly, welcome to this forum
Now, please use the code section icon to paste your code - this keeps the indentation which is required. Otherwise we cannot read your code.
The next issue is that a switch will bounce when it changes state. So you need some debounce code. The simplest form is a delay after it switches state. Start with 1 second so you can see the change in your leds.
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Links to other interesting threads:
· Home of the MultiBladeProps: TriBlade,·RamBlade,·SixBlade, website
· Single Board Computer:·3 Propeller ICs·and a·TriBladeProp board (ZiCog Z80 Emulator)
· Prop Tools under Development or Completed (Index)
· Emulators: CPUs Z80 etc; Micros Altair etc;· Terminals·VT100 etc; (Index) ZiCog (Z80) , MoCog (6809)·
· Prop OS: SphinxOS·, PropDos , PropCmd··· Search the Propeller forums·(uses advanced Google search)
My cruising website is: ·www.bluemagic.biz·· MultiBlade Props: www.cluso.bluemagic.biz
To find your problem, firstly I suggest you simplify your code to just output the LED state depending on the switch. Then hold your switch on and check to make sure the LED is then on (or off). Then release your switch and make sure the LED changes state. You should not notice the LED flash with the switch bouncing as that is quite fast. Once this works, I suggest you then build up your code from there is small stages until you get the hang of it.
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Links to other interesting threads:
· Home of the MultiBladeProps: TriBlade,·RamBlade,·SixBlade, website
· Single Board Computer:·3 Propeller ICs·and a·TriBladeProp board (ZiCog Z80 Emulator)
· Prop Tools under Development or Completed (Index)
· Emulators: CPUs Z80 etc; Micros Altair etc;· Terminals·VT100 etc; (Index) ZiCog (Z80) , MoCog (6809)·
· Prop OS: SphinxOS·, PropDos , PropCmd··· Search the Propeller forums·(uses advanced Google search)
My cruising website is: ·www.bluemagic.biz·· MultiBlade Props: www.cluso.bluemagic.biz
eiplanner·- posted some code for you in the 1st thread you posted about this today, he says he tried it and it works, have yu tried it?
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
PrEditor·- Text Editor
NYC Area Prop Club
·