Shop OBEX P1 Docs P2 Docs Learn Events
Push Button — Parallax Forums

Push Button

whitelancerwhitelancer Posts: 23
edited 2006-06-20 19:31 in General Discussion
To anyone that can help,

I want to have my code run only when a button on the starter kit breadboard is pressed and then stop when it is pressed again. I was wondering what code and setup would be needed to complete this idea. Thank you for any help.

Sincerely,

Comments

  • Peter VerkaikPeter Verkaik Posts: 3,956
    edited 2006-06-19 14:50
    See attachement for demo program.
    regards peter
  • whitelancerwhitelancer Posts: 23
    edited 2006-06-19 15:27
    Thank you,

    I appreciate all of the help. I was hoping someone could explain the wiring on the breadboard to make a button work with the posted program. Thanks.

    Sincerely,
  • Peter VerkaikPeter Verkaik Posts: 3,956
    edited 2006-06-19 16:51
    Connect a 10k resistor between +5V and javelin I/O pin 0.
    Connect a normally open button between GND and javelin I/O pin 0.

    regards peter
  • whitelancerwhitelancer Posts: 23
    edited 2006-06-19 18:03
    What do you mean by the +5V. I am using the Starter Kit with Power Supply. Thanks
  • Peter VerkaikPeter Verkaik Posts: 3,956
    edited 2006-06-19 18:16
    The starterkit comes with the javelin demoboard.
    Connection VDD is the +5V. The demoboard
    is described in the manual.

    regards peter
  • whitelancerwhitelancer Posts: 23
    edited 2006-06-20 17:24
    I have button hooked up and coded so that it starts and stops when the button is pressed. However, I am having trouble now sending data to the servo controller. Is there a problem with the program or does the connection for the serial input need to be at the button or the pin that is sending the data. Thank you again for you time and consideration.

    Sincerely,

    ·
  • Peter VerkaikPeter Verkaik Posts: 3,956
    edited 2006-06-20 17:33
    You must use different pins for the pushbutton and servo controller.
    You will get better responses·if you attached your entire program and a detailed
    description of your hardware setup.

    regards peter
  • whitelancerwhitelancer Posts: 23
    edited 2006-06-20 18:11
    The code is attached and the setup description is also attached. Let me know if this clarifies things for you and what I need to do to get the best response from the system. Thanks!
  • Peter VerkaikPeter Verkaik Posts: 3,956
    edited 2006-06-20 18:43
    Replace the 1 in the
    while (!isButtonPressed(1))
    by
    while (!isButtonPressed(CPU.pin1))

    Change isButtonPressed by

    ··· private static boolean isButtonPressed( int pinNumber ) {
    ······· return !CPU.readPin(pinNumber); //return true if pin low (eg. button pressed)
    ··· }

    regards peter
  • whitelancerwhitelancer Posts: 23
    edited 2006-06-20 19:20
    Okay so everything seems to be working well with the button but using the diagram where does the serial input go?

    Sincerely,
  • Peter VerkaikPeter Verkaik Posts: 3,956
    edited 2006-06-20 19:23
    The servo board serial input goes to javelin I/O pin 0,
    that is the pin used in the Uart declaration.
    Make sure the javelin GND is connected to the servo board GND.

    regards peter
  • whitelancerwhitelancer Posts: 23
    edited 2006-06-20 19:31
    Thanks its working great. Again I really appreciate your help and support.

    Sincerely,
    Jon
Sign In or Register to comment.