Tactile Push Button – 7mm

$0.99

173 in stock

Description

Tactile buttons are great way to add interactive elements to all sorts of projects. The pins fit directly into a breadboard.

Tactile Push Button Code


/* SETUP

Button         Arduino
S       -      D2
        -      5V
-       -      GND
*/
 
// set pin numbers
const int buttonPin = 2;    // the number of the pushbutton pin
const int ledPin =  13;   // the number of the LED pin

// changing variables
int buttonState = 0;    // variable for reading the pushbutton status

void setup() {
  pinMode(ledPin, OUTPUT);    // initialize the LED pin as an output
  pinMode(buttonPin, INPUT);    // initialize the pushbutton pin as an input
}

void loop() {
  buttonState = digitalRead(buttonPin);   // read the state of the pushbutton value
  
  if (buttonState == HIGH) {    // if button is pressed, the buttonState is HIGH
    digitalWrite(ledPin, HIGH);   // turn LED on
  } else {
    digitalWrite(ledPin, LOW);    // turn LED off
  }
}

 

There are no reviews yet.

Be the first to review “Tactile Push Button – 7mm”

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