Determining status of input
ahage16
Posts: 1
I am writing a program using the Propeller proto board. The purpose is to allow the user to set a variable equal to a certain number using a switch. After this, a motor is started and revolutions are counted and the motor stays on until the number of revolutions is equal to the number times the switch is pressed. Here is the full code which I could not get to work.
I tried breaking it down to figure out what is wrong and this is the simplest code that doesn't work, and here it is:
essentially, my question is, can the bolded part be used to determine the status of an input? or is that only for outputs?
VAR word state word desrev word miss word turn CON LED = 0 Motor = 1 SwitchOutput = 5 PUB Toggle dira := %00000000_00000000_00000000_00010111 'P0=LED, P1=Motor, P2=Hall Effect Input, P3=Hall Effect Output, P4=Switch Input, P5=Switch Output outa := %00000000_00000000_00000000_00010100 repeat waitcnt (15_000_000 + cnt) state := outa[noparse][[/noparse]SwitchOutput] 'set state = to 1 if switch is pressed If state == 1 'if pin5 = 1 desrev++ 'add one to desrev outa[noparse][[/noparse]LED]~~ 'turn LED on to show it is counted waitcnt (15_000_000+ cnt) Elseif state == 0 'if pin5 = 0 miss++ 'add one to miss If miss == 4 'if miss = 4 quit 'quit loop repeat while turn < desrev outa[noparse][[/noparse]Motor]~~ 'turn motor on waitpeq ( %00000000_00000000_00000000_00000100, %00000000_00000000_00000000_00000100, 0) turn++
I tried breaking it down to figure out what is wrong and this is the simplest code that doesn't work, and here it is:
VAR word state PUB Toggle dira := %00000000_00000000_00000000_00000101 'P0=Switch Input, P1=Switch Output, P2=LED outa := %00000000_00000000_00000000_00000001 repeat [b]state := outa 'set state = to pin position[/b] If state == 1 'if pin1 = 1 outa~~ waitcnt (7_000_000 + cnt)
essentially, my question is, can the bolded part be used to determine the status of an input? or is that only for outputs?
Comments
You might also look at page 98 in the Propeller Manual. It discusses using ! to toggle a pin.
Post Edited (Chuck Rice) : 7/3/2008 4:10:40 AM GMT