Skip to content

Instantly share code, notes, and snippets.

View brooksware2000's full-sized avatar

Curtis Brooks brooksware2000

View GitHub Profile
@brooksware2000
brooksware2000 / jingle_bells.cc
Created November 16, 2017 03:17 — forked from elubow/jingle_bells.cc
Using a Piezo Element and Arduino, you can play jingle bells using this code sample.
int speakerPin = 5;
int length = 26;
char notes[] = "eeeeeeegcde fffffeeeeddedg";
int beats[] = { 1, 1, 2, 1, 1, 2, 1, 1, 1, 1, 4, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 2, 2};
int tempo = 300;
void playTone(int tone, int duration) {
for (long i = 0; i < duration * 1000L; i += tone * 2) {
digitalWrite(speakerPin, HIGH);
delayMicroseconds(tone);