| Electronic Components Datasheet Search |
|
DEV-09760 Datasheet(PDF) 6 Page - SparkFun Electronics |
|
|
|||||||||||||||||||||||||||||
DEV-09760 Datasheet(HTML) 6 Page - SparkFun Electronics |
|
6 / 9 page ![]() } else { // y_direction == 1 Serial.println("rightup"); } } How do I set up the Arduino so I can know when a button has been pushed on the Joystick Shield? Before you can know if a button on the shield has been pushed you need to set up your Arduino to recognize the buttons. Unsurprisingly you will perform this setup in the... setup() function! First we define constants for the Arduino pin associated with each button: // Select button is triggered when joystick is pressed const byte PIN_BUTTON_SELECT = 2; const byte PIN_BUTTON_RIGHT = 3; const byte PIN_BUTTON_UP = 4; const byte PIN_BUTTON_DOWN = 5; const byte PIN_BUTTON_LEFT = 6; If you've used a pushbutton switch before you may have noticed a resistor is normally required in order to detect a known voltage when the button is not pressed. To reduce the number of parts required this shield has been designed not to require resistors on the shield itself. Are you thinking to yourself "if push buttons require resistors and the shield has no resistors how can we get the shield to work?"? If you're not thinking that then you can probably skip reading this bit. (And if you're thinking "I'm really hungry" it might be time to put down the electronics and get some food.) It turns out your Arduino actually has internal resistors connected to the pins inside the microcontroller. In order to use the internal resistors we need to "enable the internal pull-up resistors". If that sounds to you like "hoist the jib and unfurl the main stay" then I can explain some more: When a "pull-up" resistor is connected to a push button it means that the voltage level when the button is not pressed will be HIGH because the resistors "pulls the voltage level up" to HIGH when the button is not pressed. On a typical Arduino a pin that is HIGH will be at 5 volts. When the push button is pressed the pin will read as LOW because there is less resistance between the pin and ground than there is between the pin and 5 volts. To enable a pin's pull-up resistor you first set the pin as an input and then enable the pull-up: pinMode(PIN_BUTTON_RIGHT, INPUT); digitalWrite(PIN_BUTTON_RIGHT, HIGH); The actual code to enable the pull-up doesn't really make any sense if you read it literally but that's the way it works. Other than remembering that an unpressed button will read as HIGH with a pull-up resistor and a pressed button will read as LOW you don't need to remember or understand the other details. In order to configure each pin to be an input and enable the pull up resistors we use the following code: Page 6 of 9 |
|
|
Link URL |
| Does ALLDATASHEET help your business so far? [ DONATE ] |
About Alldatasheet | Advertisement | Contact us | Privacy Policy | Link to Datasheet | Link Exchange | Manufacturer List All Rights Reserved©Alldatasheet.com |
| Russian : Alldatasheetru.com | Korean : Alldatasheet.co.kr | Spanish : Alldatasheet.es | French : Alldatasheet.fr | Italian : Alldatasheetit.com Portuguese : Alldatasheetpt.com | Polish : Alldatasheet.pl | Vietnamese : Alldatasheet.vn Indian : Alldatasheet.in | Mexican : Alldatasheet.com.mx | British : Alldatasheet.co.uk | New Zealand : Alldatasheet.co.nz |
|
Family Site : ic2ic.com |
icmetro.com |