-
-
Save crazymonkyyy/e1a98d5118a89c96f2d8256fba0d5775 to your computer and use it in GitHub Desktop.
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
#define NOTE_A2 110 | |
#define NOTE_B2 123 | |
#define NOTE_C3 131 | |
#define NOTE_D3 147 | |
#define NOTE_E3 165 | |
#define NOTE_F3 175 | |
#define NOTE_G3 196 | |
#define speaker 2 | |
#define keys 30 | |
#define play 6 | |
#define maxnotes 100 | |
int tones[7]={NOTE_A2,NOTE_B2,NOTE_C3,NOTE_D3,NOTE_E3,NOTE_F3,NOTE_G3}; | |
void setup() { | |
Serial.begin(9600); | |
Serial.println("hi"); | |
//pinMode(keys,INPUT); | |
} | |
int waitcount(int i){ | |
int j=0; | |
while(digitalRead(keys+i)){ | |
j++; | |
tone(speaker,tones[i]); | |
} | |
return j; | |
} | |
int notes[maxnotes]; | |
int times[maxnotes]; | |
int j; | |
void loop() { | |
startup: | |
j=0; | |
tone(speaker,NOTE_A2,100); | |
delay(100); | |
tone(speaker,NOTE_G3,100); | |
delay(100); | |
//delay(1000); | |
writeloop: | |
for(int i=0;i<8;i++){ | |
if(digitalRead(keys+i)){ | |
notes[j]=i; | |
times[j]=waitcount(i)/5; | |
if(times[j]<25){ | |
times[j]=25; | |
} | |
j++; | |
noTone(speaker); | |
} | |
} | |
if(digitalRead(play)){ | |
while(digitalRead(play)){delay(10);} | |
goto playloop; | |
} | |
goto writeloop; | |
playloop: | |
for(int i=0;i<j;i++){ | |
tone(speaker,tones[notes[i]]); | |
delay(times[i]); | |
if(times[i]<50){ | |
noTone(speaker); | |
delay(50-times[i]); | |
} | |
noTone(speaker); | |
if(digitalRead(play)){ | |
goto startup; | |
} | |
} | |
goto writeloop; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment