Created
July 27, 2012 23:46
-
-
Save nakajima/3191097 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Speaker Clicker | |
int maxIndicatorPin = 1; | |
int okayIndicatorPin = 2; | |
int speakerPin = 13; | |
int pitchPin = 0; | |
int pitch = 750; | |
void setup() { | |
pinMode(speakerPin, OUTPUT); | |
pinMode(maxIndicatorPin, OUTPUT); | |
pinMode(okayIndicatorPin, OUTPUT); | |
} | |
void loop() { | |
pitch = analogRead(pitchPin); | |
int pitchDelay = map(pitch, 0, 1023, 500, 1000); | |
digitalWrite(speakerPin, HIGH); | |
delayMicroseconds(pitchDelay); | |
digitalWrite(speakerPin, LOW); | |
delayMicroseconds(pitchDelay); | |
if (pitchDelay <= 501) { | |
digitalWrite(maxIndicatorPin, HIGH); | |
digitalWrite(okayIndicatorPin, LOW); | |
} else { | |
digitalWrite(maxIndicatorPin, LOW); | |
digitalWrite(okayIndicatorPin, HIGH); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment