How do I take one program, Add to the other program....
Jimm2
Posts: 16
This is the Program. What I need help with is. If I hold down switch (23). It will make A bank of Led's, stay on for the time the switch is held down. If that same switch, is hit off and on and off and on. (Turn) It will make A bank of Led's switch on and off. So what I don't know how to do is. Make two program into one...........
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]~~
My program to add to the other one up here................................................................................
PUB (((((Down)))))))
dira[noparse][[/noparse]4..9] := %111111
outa[noparse][[/noparse]4..9] := %111111
waitcnt(clkfreq/4 + cnt)
outa[noparse][[/noparse]4..9] := %000000
PUB (((((Turn)))))))
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
Thank you much.
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]~~
My program to add to the other one up here................................................................................
PUB (((((Down)))))))
dira[noparse][[/noparse]4..9] := %111111
outa[noparse][[/noparse]4..9] := %111111
waitcnt(clkfreq/4 + cnt)
outa[noparse][[/noparse]4..9] := %000000
PUB (((((Turn)))))))
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
Thank you much.
Comments
Either open both programs and use cut and paste to combine them,
OR ALSO start a new Cog.
Someone else would have to remind us what the command to do that is,
because although it is easy, I don't remember how to start a new cog with for a SPIN program,
because I usually run PASM programs in the other Cogs.
Post Edited (VIRAND) : 1/28/2010 1:31:52 AM GMT
First, when you post your code, you need to copy it from your editor and then paste it into your message to the forum by starting it with [noparse][[/noparse]∑CODE∑ ] and ending it with [noparse][[/noparse]∑/CODE∑] but remove the ∑'s so the browser doesn't freak out.
As for solving your specific problem, you can totally re-write the program into one, of course. Orrrr....
I suppose you could make a Method out of your second program and have the first program (Main) call up that Method. Look up, for example, page 67 of this:
www.parallax.com/Portals/0/Downloads/docs/prod/prop/PELabsFunBook-v1.1.pdf
And of course there is the manual, in which you can investigate all the glories of COGNEW, etc, if you must:
www.parallax.com/Portals/0/Downloads/docs/prod/prop/WebPM-v1.1.pdf
hope that helps,
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Watching the world pass me by, one photon at a time.
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
It's not the size of the dog in the fight, but the size of the fight in the dog.
If the button is pressed down LEDs on
If button is not pressed down LEDs off
so this could be reduced to the following code
what I understand what you want to do in the second program is
if the SwitchPin changes its state for 3 times On-Off-On-Off-On-Off within 1 second the outputs 4..9 should light up ONE time with the pattern
is this correct?
If this is correct answer yes. If it is not correct you have to specify how the thing should work
best regards
Stefan
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. What 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
them by typing: led.Down or led.Turn}
Where do I put this in the program to make it work......................................................................................................
by giving it a name such as LEDBlink. Save this file in the Parallax folder.
Make an Object block above your VAR block by typing this: OBJ led: "LEDBlink"
Then, every time you want to use one of these blinking methods, just put in a call to
them by typing: led.Down or led.Turn}
Where in the program do I put the (led.down or led.turn) to make it work.............I don't know..................................