User:Megan Hoogenboom/assignment5
< User:Megan Hoogenboom
Revision as of 17:11, 9 November 2010 by Megan Hoogenboom (talk | contribs) (Created page with "== Counting time of button press, with Natasa == <source lang="C"> const int buttonPin = 2; // the number of the pushbutton pin const int speakerPin = 13; // the numb...")
Counting time of button press, with Natasa
const int buttonPin = 2; // the number of the pushbutton pin
const int speakerPin = 13; // the number of the SPEAKER pin
// variables will change:
int buttonInput = 0; // variable for reading the pushbutton status
int buttonState = 0;
int s1;
int s2;
void setup() {
// initialize the speaker pin as an output:
pinMode(speakerPin, OUTPUT);
// initialize the pushbutton pin as an input:
pinMode(buttonPin, INPUT);
Serial.begin(9600);
tone(13, 400, 10);
}
void loop(){
// read the state of the pushbutton value:
while (digitalRead(buttonPin) == LOW) {
}
s1 = millis();
while (digitalRead(buttonPin) == HIGH) {
s2 = millis();
}
Serial.println(s2 - s1, DEC);
delay(1000);
}