/* Button Counter * ----------- * * Detects if the button has been pressed and lights up an LED * It also sends out how many times the button has been pressed via the serial port. * * Christian Nold & Erica Calogero * */ int LED = 13; int Button = 10; int value = 0; int counter = 0; int lastbuttonstate = 0; void setup() { beginSerial(9600); // Sets the baud rate to 9600 pinMode(LED, OUTPUT); // initializes digital pin 13 as output pinMode(Button, INPUT); // initializes digital pin 10 as input } void loop() { value = digitalRead(Button); // reads the value at a digital input digitalWrite(LED, value); if(value != lastbuttonstate){ //debounce code if(value == 1){ delay(20); if(value == 1){ counter++; printInteger(counter); serialWrite(10); serialWrite(13); } } } lastbuttonstate = value; }