TinkerKit Button Module

The Pushbutton Module is possibly the simplest sensor available. It detects when a person or an object presses on its circular cap.

Output:This module outputs 5v when the button is pressed and 0v when released. Pressing the button closes the circuit. When connected to an input on the Arduino using the TinkerKit Shield, you can expect a value of 1023 while the button is pressed and 0 when released.

Module Description: This module features a 12mm pushbutton , the standard TinkerKit 3pin connector, a green LED that signals that the module is correctly powered and a yellow LED that is lit only when the button is pressed.

This module is a SENSOR. The connector is an OUTPUT which must be connected to one of the INPUT connectors on the TinkerKit Shield.

Available methods

TKButton button(I0);
read() return the button reading. HIGH if is pressed, LOW if is released
pressed() trigger the instant when the button is being pressed and return the HIGH value
released() trigger the instant when the button is being released and return the HIGH value
held() this method compares the state of the button with the previous one and return HIGH if is held
readSwitch() with this method the button acts like a switch. Each press change the return value, that can be HIGH or LOW
Example:

/*
 Turns on and off a T010111 LED Module connected to O0,
 when pressing a T000180 Button Module attached to I0.

 This example code is in the public domain.

 created in Dec 2011
 by Federico Vanzati
 modified in Jun 2013
 by Matteo Loglio<http://matlo.me> 

 based on  http://www.arduino.cc/en/Tutorial/Button
 */

// include the TinkerKit library
#include <TinkerKit.h>

// make a'button' object that belongs to the 'TKButton' class 
TKButton button(I0);

// make a'button' object that belongs to the 'TKLed' class 
TKLed led(O0);

void setup() {
//nothing here
}

void loop()
{
  // check the switchState of the button
  if (button.readSwitch() == HIGH) {      
    led.on();            
  } 
  else {            
    led.off();          
  }
}

Leave a Reply

Your email address will not be published. Required fields are marked *