PDA

View Full Version : Using buttons



Steve-O
06-04-2005, 11:43 AM
I'm trying to make a servo activate by a button push. So far it's not going well... I'm using the BUTTON command inside a loop in main. When the button is activated it goes to an outside function in order to activate the servo. Here is the code I have so far...it clears the tokenizer and I have inserted several debugs inorder to see where the program is at. Disregard the counter...that's for a later project (which im sure I'll need help on too..haha)
If all this looks ok, how do you go about the circuit for this?

dandreae
06-05-2005, 03:50 AM
You may be able to use an "IF THEN" command based on the condition of the input pin.· Example:

Do

·IF IN1=1 THEN Arm_Servo

Main:
· DEBUG "main 1",CR
· DEBUG "counter modulus: ", SDEC counter // 2 ,CR
· DO
· PAUSE 1000
· BUTTON Btn, 0, 255, 20, btnWrk, 0, Arm_Servo
· DEBUG "main 2",CR
· LOOP


Arm_Servo:
· DEBUG "arm 1",CR
· IF counter // 2 > 0 THEN x = 260 ELSE x = 1240
··· ra = 7: ch = 11
··· pw = x
··· DEBUG "pulse width: ", SDEC pw,CR
··· SEROUT Sdat, Baud+$8000,["!SC",ch,ra,pw.LOWBYTE,pw.HIGHBYTE,CR]
··· PAUSE 1000
··· pw = 760
··· DEBUG "pulse width at rest: ", SDEC pw,CR
· counter = counter + 1
· DEBUG "counter: ", SDEC counter,CR
RETURN

Dave

▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Dave Andreae

Tech Support
dandreae@parallax.com (mailto:dandreae@parallax.com)
www.parallax.com (http://www.parallax.com)

·