Skip to content

Instantly share code, notes, and snippets.

@podstawek
Created April 25, 2021 14:29
Show Gist options
  • Save podstawek/3544b9d7f36222d31f8c4043e1efb5ef to your computer and use it in GitHub Desktop.
Save podstawek/3544b9d7f36222d31f8c4043e1efb5ef to your computer and use it in GitHub Desktop.
Fast arpeggios played to simulate chords C a d G
int speakerPin = 26; // speaker on digital pin 26
float frequencies[] = {
130.8, 164.8, 196, 130.8, 164.8, 196, 130.8, 164.8, 196, 130.8, 164.8, 196, 130.8, 164.8, 196, 130.8, 164.8, 196, 130.8, 164.8, 196, 130.8, 164.8, 196, 130.8, 164.8, 196, 130.8, 164.8, 196,
220, 261.6, 329.6, 220, 261.6, 329.6, 220, 261.6, 329.6, 220, 261.6, 329.6, 220, 261.6, 329.6, 220, 261.6, 329.6, 220, 261.6, 329.6, 220, 261.6, 329.6, 220, 261.6, 329.6, 220, 261.6, 329.6,
146.8, 174.6, 220, 146.8, 174.6, 220, 146.8, 174.6, 220, 146.8, 174.6, 220, 146.8, 174.6, 220, 146.8, 174.6, 220, 146.8, 174.6, 220, 146.8, 174.6, 220, 146.8, 174.6, 220, 146.8, 174.6, 220,
196, 247, 293.7, 196, 247, 293.7, 196, 247, 293.7, 196, 247, 293.7, 196, 247, 293.7, 196, 247, 293.7, 196, 247, 293.7, 196, 247, 293.7, 196, 247, 293.7, 196, 247, 293.7};
float durations[] = {
0.06, 0.06, 0.06, 0.06, 0.06, 0.06, 0.06, 0.06, 0.06, 0.06, 0.06, 0.06, 0.06, 0.06, 0.06, 0.06, 0.06, 0.06, 0.06, 0.06, 0.06, 0.06, 0.06, 0.06, 0.06, 0.06, 0.06, 0.06, 0.06, 0.06,
0.06, 0.06, 0.06, 0.06, 0.06, 0.06, 0.06, 0.06, 0.06, 0.06, 0.06, 0.06, 0.06, 0.06, 0.06, 0.06, 0.06, 0.06, 0.06, 0.06, 0.06, 0.06, 0.06, 0.06, 0.06, 0.06, 0.06, 0.06, 0.06, 0.06,
0.06, 0.06, 0.06, 0.06, 0.06, 0.06, 0.06, 0.06, 0.06, 0.06, 0.06, 0.06, 0.06, 0.06, 0.06, 0.06, 0.06, 0.06, 0.06, 0.06, 0.06, 0.06, 0.06, 0.06, 0.06, 0.06, 0.06, 0.06, 0.06, 0.06,
0.06, 0.06, 0.06, 0.06, 0.06, 0.06, 0.06, 0.06, 0.06, 0.06, 0.06, 0.06, 0.06, 0.06, 0.06, 0.06, 0.06, 0.06, 0.06, 0.06, 0.06, 0.06, 0.06, 0.06, 0.06, 0.06, 0.06, 0.06, 0.06, 0.06};
int musicLength = sizeof(frequencies) / sizeof(frequencies[0]);
float delayInMicroseconds;
int numberOfIterations;
float frequency;
float duration;
void setup() {
pinMode(speakerPin, OUTPUT);
for (int y=0; y < 4; y++) {
for (int x=0; x < musicLength; x++) {
frequency = frequencies[x];
duration = durations[x];
delayInMicroseconds = 1/frequency*1000000/2;
numberOfIterations = duration*frequency;
for (int f=0; f < numberOfIterations; f++) {
digitalWrite(speakerPin, HIGH);
delayMicroseconds(delayInMicroseconds);
digitalWrite(speakerPin, LOW);
delayMicroseconds(delayInMicroseconds);
}
}
}
}
void loop() {
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment