User:Natasa Siencnik/prototyping/counting: Difference between revisions
(Created page with "== Counting time of button press == together with Megan <source lang="C"> const int buttonPin = 2; // the number of the pushbutton pin const int speakerPin = 13; // th...") |
|||
Line 1: | Line 1: | ||
== Counting time of button press == | == Counting time of button press == | ||
together with Megan | together with Megan | ||
[[File:SKETCH_Counter.jpg|720px]] | |||
<source lang="C"> | <source lang="C"> |
Latest revision as of 17:30, 16 December 2010
Counting time of button press
together with Megan
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);
}