Skip to content

Instantly share code, notes, and snippets.

@nakajima
Created July 27, 2012 23:46
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save nakajima/3191097 to your computer and use it in GitHub Desktop.
Save nakajima/3191097 to your computer and use it in GitHub Desktop.
// 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