Last active
August 29, 2015 14:10
-
-
Save vasmani/2c2ee7410222014448fa to your computer and use it in GitHub Desktop.
Arduino FDD Music
This file contains hidden or 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
| // http://www.classicpianosolos.com/sheetmusic/bach/bach-bwv-784-invention-no.-13-719 | |
| #define Dir 3 | |
| #define Step 6 | |
| int DD = HIGH; | |
| int current = 0; | |
| int c1 = 7000; | |
| int d1 = 6500; | |
| int dsharp1 = 6250; | |
| int e1 = 6000; | |
| int f1 = 5600; | |
| int fsharp1 = 5300; | |
| int g1 = 5000; | |
| int gsharp1 = 4700; | |
| int a1 = 4400; | |
| int b1 = 3900; | |
| int c2 = 3600; | |
| int csharp2 = 3400; | |
| int d2 = 3200; | |
| int dsharp2 = 3050; | |
| int e2 = 2900; | |
| int f2 = 2700; | |
| int fsharp2 = 2550; | |
| int g2 = 2400; | |
| int gsharp2 = 2300; | |
| int a2 = 2200; | |
| int bflat2 = 2075; | |
| int b2 = 1950; | |
| int c3 = 1800; | |
| int d3 = 1700; | |
| int e3 = 1500; | |
| void setup() { | |
| Serial.begin(9600); | |
| pinMode(Dir, OUTPUT); | |
| pinMode(Step, OUTPUT); | |
| digitalWrite(Dir, DD); | |
| doSteps(80, 1500); | |
| current = 80; | |
| delay(500); | |
| initHead(); // move header half way | |
| } | |
| void initHead() { | |
| play(9900); | |
| play(e1); | |
| play(a1); | |
| play(c2); | |
| play(b1); | |
| play(e1); | |
| play(b1); | |
| play(d2); | |
| play(c2); play(c2); | |
| play(e2); play(e2); | |
| play(gsharp1); play(gsharp1); | |
| play(e2); play(e2); | |
| play(a1); | |
| play(e1); | |
| play(a1); | |
| play(c2); | |
| play(b1); | |
| play(e1); | |
| play(b1); | |
| play(d2); | |
| play(c2); play(c2); | |
| play(a1); play(a1); | |
| mute(); | |
| mute(); | |
| mute(); | |
| mute(); | |
| play(c1); | |
| play(e2); | |
| play(c2); | |
| play(e2); | |
| play(a1); | |
| play(c2); | |
| play(e1); | |
| play(g1); | |
| play(f1); play(f1); | |
| play(a1); play(a1); | |
| play(d2); play(d2); | |
| play(f2); play(f2); | |
| play(f2); | |
| play(d2); | |
| play(b1); | |
| play(d2); | |
| play(g1); | |
| play(b1); | |
| play(d1); | |
| play(f1); | |
| play(e1);play(e1); | |
| play(g1);play(g1); | |
| play(c2);play(c2); | |
| play(e2);play(e2); | |
| play(e2); | |
| play(c2); | |
| play(a1); | |
| play(c2); | |
| play(f1);play(f1); | |
| play(d2);play(d2); | |
| play(d2); | |
| play(b1); | |
| play(g1); | |
| play(b1); | |
| play(e1);play(e1); | |
| play(c2);play(c2); | |
| play(c2); | |
| play(a1); | |
| play(f1); | |
| play(a1); | |
| play(d1);play(d1); | |
| play(b1);play(b1); | |
| play(c2);play(c2); | |
| mute(); | |
| mute(); | |
| mute(); | |
| mute(); | |
| mute(); | |
| mute(); | |
| mute(); | |
| play(g1); | |
| play(c2); | |
| play(e2); | |
| play(d2); | |
| play(g1); | |
| play(d2); | |
| play(f2); | |
| play(e2);play(e2); | |
| play(g2);play(g2); | |
| play(b1);play(b1); | |
| play(g2);play(g2); | |
| play(c2); | |
| play(g1); | |
| play(c2); | |
| play(e2); | |
| play(d2); | |
| play(g1); | |
| play(d2); | |
| play(f2); | |
| play(e2);play(e2); | |
| play(c2);play(c2); | |
| play(g2);play(g2); | |
| play(e2);play(e2); | |
| play(c3); | |
| play(a2); | |
| play(e2); | |
| play(a2); | |
| play(c2); | |
| play(e2); | |
| play(a1); | |
| play(c2); | |
| play(d2);play(d2); | |
| play(fsharp2);play(fsharp2); | |
| play(a2);play(a2); | |
| play(c3);play(c3); | |
| play(b2); | |
| play(g2); | |
| play(d2); | |
| play(g2); | |
| play(b1); | |
| play(d2); | |
| play(g1); | |
| play(b1); | |
| play(c2);play(c2); | |
| play(e2);play(e2); | |
| play(g2);play(g2); | |
| play(b2);play(b2); | |
| play(a2); | |
| play(fsharp2); | |
| play(dsharp2); | |
| play(fsharp2); | |
| play(b1); | |
| play(dsharp2); | |
| play(fsharp1); | |
| play(a1); | |
| play(g1); play(g1); | |
| play(g2); play(g2); | |
| play(g2); | |
| play(e2); | |
| play(c2); | |
| play(e2); | |
| play(a1); play(a1); | |
| play(fsharp2); play(fsharp2); | |
| play(fsharp2); | |
| play(d2); | |
| play(b1); | |
| play(d2); | |
| play(g1); play(g1); | |
| play(e2); play(e2); | |
| play(e2); | |
| play(c2); | |
| play(a1); | |
| play(c2); | |
| play(fsharp1); | |
| play(g2); | |
| play(fsharp2); | |
| play(e2); | |
| play(dsharp2); | |
| play(fsharp2); | |
| play(b1); | |
| play(dsharp2); | |
| play(e2); play(e2); | |
| play(b2); | |
| play(g2); | |
| play(e2); | |
| play(b1); | |
| play(g1); | |
| play(b1); | |
| // page 1 end | |
| mute(); | |
| play(g2); | |
| play(bflat2); | |
| play(g2); | |
| play(e2); | |
| play(g2); | |
| play(csharp2); | |
| play(e2); | |
| play(g2); | |
| play(e2); | |
| play(csharp2); | |
| play(e2); | |
| play(a1); | |
| play(g2); | |
| play(f2); | |
| play(e2); | |
| //-- | |
| mute(); | |
| play(f2); | |
| play(a2); | |
| play(f2); | |
| play(d2); | |
| play(f2); | |
| play(b1); | |
| play(d2); | |
| play(f2); | |
| play(d2); | |
| play(b1); | |
| play(d2); | |
| play(g1); | |
| play(f2); | |
| play(e2); | |
| play(d2); | |
| mute(); | |
| play(e2); | |
| play(g2); | |
| play(e2); | |
| play(c2); | |
| play(e2); | |
| play(a1); | |
| play(c2); | |
| play(dsharp2); | |
| play(c2); | |
| play(a1); | |
| play(c2); | |
| play(fsharp1); | |
| play(e2); | |
| play(dsharp2); | |
| play(csharp2); | |
| //-- | |
| play(d2); | |
| play(f2); | |
| play(d2); | |
| play(b1); | |
| play(d2); | |
| play(gsharp1); | |
| play(b1); | |
| play(d2); | |
| play(b1); | |
| play(gsharp1); | |
| play(b1); | |
| play(e1); | |
| play(d2); | |
| play(c2); | |
| play(b1); | |
| mute(); | |
| play(e1); | |
| play(a1); | |
| play(c2); | |
| play(b1); | |
| play(e1); | |
| play(b1); | |
| play(d2); | |
| play(c2); play(c2); | |
| play(a1); play(a1); | |
| play(gsharp1); play(gsharp1); | |
| play(e1); play(e1); | |
| // -- | |
| play(a1); | |
| play(c2); | |
| play(e2); | |
| play(c2); | |
| play(a1); | |
| play(c2); | |
| play(fsharp1); | |
| play(a1); | |
| play(c2); | |
| play(a1); | |
| play(fsharp1); | |
| play(a1); | |
| play(dsharp1); | |
| play(c2); | |
| play(b1); | |
| play(a1); | |
| play(gsharp1); | |
| play(b1); | |
| play(d2); | |
| play(b1); | |
| play(gsharp1); | |
| play(b1); | |
| play(d1); | |
| play(f1); | |
| play(gsharp1); | |
| play(f1); | |
| play(d1); | |
| play(f1); | |
| play(b1); | |
| play(f1); | |
| play(e1); | |
| play(d1); | |
| //-- | |
| play(c1); | |
| play(e1); | |
| play(a1); | |
| play(e1); | |
| play(c1); | |
| play(e1); | |
| play(a1); | |
| play(c1); | |
| play(dsharp1); | |
| play(c1); | |
| play(a1); | |
| play(c1); | |
| play(fsharp1); | |
| play(c1); | |
| play(b1); | |
| play(a1); | |
| play(gsharp1);play(gsharp1); | |
| play(b1);play(b1); | |
| play(gsharp1);play(gsharp1); | |
| play(e1);play(e1); | |
| mute(); | |
| play(e1); | |
| play(a1); | |
| play(c2); | |
| play(b1); | |
| play(e1); | |
| play(b1); | |
| play(d2); | |
| play(c2); | |
| play(a1); | |
| play(c2); | |
| play(e2); | |
| play(d2); | |
| play(b1); | |
| play(d2); | |
| play(f2); | |
| play(e2); | |
| play(c2); | |
| play(e2); | |
| play(g2); | |
| play(f2); | |
| play(e2); | |
| play(d2); | |
| play(c2); | |
| play(b1); | |
| play(c2); | |
| play(d2); | |
| play(e2); | |
| play(f2); | |
| play(b1); | |
| play(gsharp2); | |
| play(d2); | |
| play(b2); | |
| play(d2); | |
| play(c2); | |
| play(a2); | |
| play(f2); | |
| play(d2); | |
| play(b1); | |
| play(d2); | |
| //-- | |
| play(gsharp1); | |
| play(b1); | |
| play(c2); | |
| play(a1); | |
| play(e1); | |
| play(a1); | |
| play(b1); | |
| play(gsharp1); | |
| play(a1); | |
| play(e1); | |
| play(c1); | |
| play(e1); | |
| play(a1);play(a1); | |
| play(a1);play(a1); | |
| } | |
| void doSteps(int steps, int stepDelay) { | |
| for(int i=0;i<steps; i++) { | |
| digitalWrite(Step,LOW); delayMicroseconds(stepDelay); | |
| digitalWrite(Step,HIGH); delayMicroseconds(stepDelay); | |
| } | |
| } | |
| void play(int note){ | |
| int steps = 90000 / note; | |
| if(current + steps > 80) { | |
| DD = LOW; | |
| current -= steps; | |
| } else { | |
| DD = HIGH; | |
| current += steps; | |
| } | |
| Serial.println(current); | |
| digitalWrite(Dir, DD); | |
| doSteps(steps, note); | |
| } | |
| void mute(){ | |
| Serial.println("MUTE"); | |
| delay(90); | |
| } | |
| void loop() { | |
| while(true); | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment