add pushbutton example
authordaniel watson <ozzloy@gmail.com>
Fri, 25 Oct 2013 15:00:58 +0000 (08:00 -0700)
committerdaniel watson <ozzloy@gmail.com>
Fri, 25 Oct 2013 15:00:58 +0000 (08:00 -0700)
pushbutton/README [new file with mode: 0644]
pushbutton/pushbutton.ino [new file with mode: 0644]

diff --git a/pushbutton/README b/pushbutton/README
new file mode 100644 (file)
index 0000000..dab6975
--- /dev/null
@@ -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 (file)
index 0000000..407c649
--- /dev/null
@@ -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 <http://www.gnu.org/licenses/>.
+ */
+
+// 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);}