read 3 buttons in parallel
I have 3 buttons and i want to read the pulse in 3 different pins... but in parallel
i think how to but my code dosen't work
here is what i do
i think how to but my code dosen't work
here is what i do
CON
_clkmode = rcfast
high = 1
low = 0
out = %111
in = %000
VAR
BYTE cogIzq
BYTE cogDer
BYTE cogCen
LONG stack0[20]
LONG stack1[20]
LONG stack2[20]
PUB Start
dira[0] := 1
dira[1] := 1
dira[2] := 1
dira[3] := 0
dira[4] := 0
dira[5] := 0
cognew(girarizq(0,3),@stack0)
cognew(girarder(1,4),@stack1)
cognew(centrar(2,5),@stack2)
PRI girarizq(Pin, Puls1)
repeat while true
if ina[Puls1] == high
outa[Pin] := high
PRI girarder(Pin, Puls2)
repeat while true
if ina[Puls2] == high
outa[Pin] := high
PRI centrar(Pin, Puls3)
repeat while true
if ina[Puls3] == high
outa[Pin] := high

Comments
CON _clkmode = rcfast high = 1 low = 0 out = %111 in = %000 VAR BYTE cogIzq BYTE cogDer BYTE cogCen LONG stack0[20] LONG stack1[20] LONG stack2[20] PUB Start dira[0] := 1 dira[1] := 1 dira[2] := 1 dira[3] := 0 dira[4] := 0 dira[5] := 0 cognew(girarizq(0,3),@stack0) cognew(girarder(1,4),@stack1) cognew(centrar(2,5),@stack2) PRI girarizq(Pin, Puls1) repeat if ina[Puls1] == 1 outa[Pin] := 1 else outa[Pin] := 0 PRI girarder(Pin, Puls2) repeat if ina[Puls2] == 1 outa[Pin] := 1 else outa[Pin] := 0 PRI centrar(Pin, Puls3) repeat if ina[Puls3] == 1 outa[Pin] := 1 else outa[Pin] := 0Maybe this will help... But I am not sure I completely understand what you are wanting to do...
so... i have 3 pulses pin 3, pin 4 and pin 5 i need to check the 3 of them at the same time
i simulate the movement of the crane with 3 leds if pin 3 is high the left leds goes on and so one...
CON _clkmode = rcfast VAR LONG stack0[20] PUB Start dira := %00000000_00000000_00000000_00000111 cognew(girarizq,@stack0) PRI girarizq repeat outa[0..2] := ina[3..5] >> 3Do you need each button to go into a different cog to run completely independently?
If not you can have one cog read all the buttons then start other cogs to carry out actions.
The code here should read the port pins then shift the bits to align with the out put pins and set them.
I am however new to propeller! I just got a demo board but don't have it with me as I am in Malaysia this week, but live in England so I have not tried this code!!
VAR long stack0[20] long stack1[20] long stack2[20] PUB Start cognew(response(0,3), @stack0{0}) cognew(response(1,4), @stack1{0}) cognew(response(2,5), @stack2{0}) PRI response(Pin, Puls1) [COLOR="red"]dira[Pin]~~[/COLOR] repeat outa[Pin] := ina[Puls1] DATSo if I wanted to read the port and write it in just one cog would my code be correct if I move the dira statement?
Does spin manage the bit operations in outa[0..2] := ina[3..5] >> 3 or would I need individually test and set the bits?
Many thanks for your assistance!
(I have many years of programming experience in PIC16, 18 and 24 in assembler and C, so I have to learn to think differently for the Propeller.).
Andy
VAR LONG stack0[20] PUB Start cognew(response,@stack0) PRI response dira := %00000000_00000000_00000000_00000111 repeat outa[0..2] := ina[3..5] >> 3 DAT ....VAR LONG stack0[20] PUB Start cognew(response,@stack0) PRI response dira[0..2] := %111 repeat outa[0..2] := ina[3..5] DAT ....With the dira setup in the right cog it will work provided you remove the >> operation. outa[0..2] as well as ina[3..5] are considered 3bit values. So there is no point shifting the latter right be 3. You could also reverse the pin order, i.e. outa[0..2] := ina[5..3]. This preserves the assignment for pin 1 (4) but swaps the assignments for pins 0 (5) and 2 (3). HTH