Button – TinkerKit

A button is a digital input. This means that it can have two states, you read these as either HIGH (5V) or LOW (0V).

Materials

  • 1 Arduino Uno board
  • 1 Education shield
  • 1 TinkerKit Button
  • 1 TinkerKit wire

Instructions


  1. Attach the shield onto the top of the Arduino board.
  2. Connect the TinkerKit button to D9 using the TinkerKit wire.
  3. Connect the board to the computer and upload example ‘Button’.

Code

Find the code in Example>EducationShield>Help>Button

You should now open the serial monitor and follow the printed instructions. Each time you execute an instruction the serial monitor should print ‘1’.

Commands

  • Button( digitalPin ) / Button( digitalPin,  pressedState): creates a button object.
    • Parameters
      • (int) digitalPin: The digital pin to which the button is connected.
      • (boolean) pressedState: can be HIGH or LOW. HIGH means that when the button is pressed it will be read as HIGH, when released it will be read as LOW. LOW means the other way around. When pressed it will be read as LOW and when released it will be read as HIGH. Default is HIGH.

  • begin(): Initializes the component. Must be called in setup()
  • pressed( timeout ): checks if the button is pressed.
    • Parameters
      • (int) timeout: milliseconds within which the button needs to be pressed. Default is 0.
    • Return
      • (boolean): returns 1 if pressed within time, otherwise 0. If timeout is not used the program pauses here until the button is pressed.

  • released( timeout ): checks if the button is released.
    • Parameters
      • (int) timeout: milliseconds within which the button needs to be released. Default is 0.
    • Return
      • (boolean): returns 1 if released within time, otherwise 0. If timeout is not used, the program pauses here until the button is released.

  • doublePressed( timeout, tolerance ): checks if the button is double pressed.
    • Parameters
      • (int) timeout: milliseconds within which the button needs to be double pressed.
      • (int) tolerance: milliseconds before the button should be pressed a second time. Default is 500.
    • Return
      • (boolean) Returns 1 if double pressed within time, otherwise 0. If timeout is not used, the program pauses here until the button is double pressed.

 

Troubleshooting

  • First of all make sure that the connection between button, wire and board is correct.
  • On the back of the TinkerKit button there is a small LED that lights up when the button is connected. If you are sure that it is connected correctly and the LED still does not light up, the button is probably broken.
  • Make sure that the program is reading from the dame digital pin as you have connected it to.