/* Button Turns on and off a light emitting diode(LED), when pressing a pushbutton attached with internal pull up register. Code optimised for the ATTiny44 The circuit: - LED attached from pin 7 to ground - pushbutton attached to pin 3 from VCC created 2005 by DojoDave modified 30 Aug 2011 by Tom Igoe modified 12 March 2019 by Joey van der Bie This example code is in the public domain. http://www.arduino.cc/en/Tutorial/Button */ // constants won't change. They're used here to set pin numbers: const int BUTTON_PIN = 3; // the number of the pushbutton pin const int LED_PIN = 7; // the number of the LED pin // variables will change: int buttonState = 0; // variable for reading the pushbutton status void setup() { // initialize the LED pin as an output: pinMode(LED_PIN, OUTPUT); //configure pin 3 as an input and enable the internal pull-up resistor pinMode(BUTTON_PIN, INPUT_PULLUP); } void loop() { // read the state of the pushbutton value: buttonState = digitalRead(BUTTON_PIN); // check if the pushbutton is pressed. If it is, the buttonState is HIGH: if (buttonState == LOW) { // turn LED on: digitalWrite(LED_PIN, HIGH); } else { // turn LED off: digitalWrite(LED_PIN, LOW); } }