Skip to content

Instantly share code, notes, and snippets.

@RobotGrrl
Created June 25, 2014 23:53
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 RobotGrrl/e62904165728c33681ce to your computer and use it in GitHub Desktop.
Save RobotGrrl/e62904165728c33681ce to your computer and use it in GitHub Desktop.
Nice sounds on an Arduino
// (spkr is the output pin to your speaker)
void playTone(int tone, int duration) {
for (long i = 0; i < duration * 1000L; i += tone * 2) {
digitalWrite(spkr, HIGH);
delayMicroseconds(tone);
digitalWrite(spkr, LOW);
delayMicroseconds(tone);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment