From: daniel watson Date: Fri, 25 Oct 2013 15:00:58 +0000 (-0700) Subject: add pushbutton example X-Git-Url: http://challenge-bot.com/repos/?p=challenge-bot;a=commitdiff_plain;h=4f4ae93381173f165bd44963f39b99307cad94ad add pushbutton example --- diff --git a/pushbutton/README b/pushbutton/README new file mode 100644 index 0000000..dab6975 --- /dev/null +++ b/pushbutton/README @@ -0,0 +1,11 @@ +(how to use this + (connect your robot to your computer via usb cable) + (open arduino ide) + (in arduino ide, open pushbutton.ino) + (hit the upload button) + (hit control+shift+m, + or go to the menu item tools, and down to serial monitor) + (in the bottom right, select "9600 baud") + (connect the breadboard and pushbutton as shown in "pushed.jpg") + (hit the upload button in the arduino ide) + (press the )) \ No newline at end of file diff --git a/pushbutton/pushbutton.ino b/pushbutton/pushbutton.ino new file mode 100644 index 0000000..407c649 --- /dev/null +++ b/pushbutton/pushbutton.ino @@ -0,0 +1,35 @@ +/* + 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);}