/* This program is free software: you can redistribute it and/or modify it under the terms of the GNU Affero General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Affero General Public License for more details. You should have received a copy of the GNU Affero General Public License along with this program. If not, see . */ // pin 13 controls the arduino's built-in LED int led_pin = 13; // connect the button to pin 2 int button_pin = 2; // initially, the button is not pressed. // 0 means not pressed, 1 means pressed int button_value = 0; void setup(){ Serial.begin(9600);} void loop(){ // see if you can figure out how this logic works if(digitalRead(button_pin) != button_value){ Serial.println("button state changed!");} // read the value of the button pin during this loop, // and save it in a box named "button_value" button_value = digitalRead(button_pin); // write the value to the led pin digitalWrite(led_pin, button_value);}