/* Pit box v2 this application will program the arduino to turn on an LED using a switch. the length of time the LED will remain on is determined by how long the switch is depressed once the arduino is first powered on. to reset the on time of the LED, reset the arduino by cycling powering off and on. It is used for a pit timer... v2 dec 2011 */ // initialize the digital pin as an output. // Pin 13 has an LED connected on most Arduino boards: #define BUTTON 6 //digital input for button aka foot switch int val = 0; int time = 0; int beeptime = 150; void setup() { pinMode(13, OUTPUT); pinMode(2, OUTPUT); //pin for timer indicator LED array on pinMode(3, OUTPUT); //pin for timer buzzer on pinMode(BUTTON, INPUT); digitalWrite(BUTTON, HIGH); // turn on pullup resistor pin 6 Serial.begin(9600); } void loop() { val = digitalRead(BUTTON); //read input value and store it //check if button is pressed if ((val == HIGH) && (time == 0)) { /* digitalWrite(3, HIGH); delay(beeptime); digitalWrite(3, LOW); delay(beeptime); digitalWrite(3, HIGH); delay(beeptime); digitalWrite(3, LOW); Serial.println(time); Serial.println(val); */ } if ((val == LOW) && (time == 0)) { digitalWrite(13, LOW); // set the LED off while (val == LOW) { time = time + 10; Serial.println(time); delay (10); Serial.println(val); val = digitalRead(BUTTON); } } if ((val == LOW) && (time > 0)) { Serial.println(time); digitalWrite(3, HIGH); delay(100); digitalWrite(3, LOW); digitalWrite(2, HIGH); delay(time); digitalWrite(2, LOW); digitalWrite(3, HIGH); delay(beeptime); digitalWrite(3, LOW); delay(beeptime); digitalWrite(3, HIGH); delay(beeptime); digitalWrite(3, LOW); } }