Skip to content

Instantly share code, notes, and snippets.

@panakuma
Created October 3, 2017 11:11
Show Gist options
  • Save panakuma/18e1010c8d79616bcfed8cc116d0b43d to your computer and use it in GitHub Desktop.
Save panakuma/18e1010c8d79616bcfed8cc116d0b43d to your computer and use it in GitHub Desktop.
int RED = 11;
int GREEN = 12;
int BLUE = 13;
int SPEAKER = 8;
int japa[] = {698,659,698,784,698,784,880,932,988,1046,880,794,698,698,1175,1046,698,587,932,880,784,698};
int japa_notes_time[] = {1,1,1,2,1,1,2,1,1,3,1,1,1,2,2,2,2,2,2,2,2,4};
int koi[] = {1109, 1318, 1109, 1318, 1480, 1318, 1109, 880, 988, 1109, 1109, 1318, 1109, 1760, 1661, 1480, 1318, 1480, 1318, 880, 988};
int koi_notes_time[] = {1, 1, 1, 1, 2, 1, 1, 2, 2, 4, 1, 1, 1, 1, 2, 1, 1, 2, 2, 2, 2};
int cinderella[]={1661, 1396, 1568, 1661, 1865, 1568, 1568, 1661, 1864, 1661, 1244, 1661, 1865, 1661, 1567, 1661, 1864, 1567, 1661, 1244, 1397, 1568, 1661, 1865, 1661, 1568, 1661, 1661, 2217, 2093, 1661, 1661, 1245, 1865, 1661};
int cin_notes_time[]={2, 1, 1, 2, 2, 1, 1, 1, 4, 1, 1, 1, 2, 1, 1, 2, 1, 2, 3, 1, 1, 1, 1, 2, 1, 1, 3, 1, 1, 1, 1, 1, 2, 1, 4};
int town[]={
784,
0, 587, 659, 0, 784, 659, 784,
880, 988, 784,
880, 988, 784,
1175,
0, 1046, 988, 0, 1175, 1046, 988,
788, 0,
1568, 0, 1568, 0, 1568, 0, 2093,
0, 2093, 0, 2093, 2093, 0,
1568, 0, 1568, 0, 1568, 0, 2093,
0, 2093, 0, 2093, 2093, 0,
1760, 0, 1760, 0, 1760, 0, 2349,
0, 2349, 0, 2349, 2349, 0,
1760, 0, 1760, 0, 1760, 0, 2349,
0, 2349, 0, 2349, 2349,
1568
};
int town_notes_time[]={
8,
1, 1, 1, 1, 2, 1, 1,
2, 3, 2,
2, 3, 2,
8,
1, 1, 1, 1, 2, 1, 1,
14, 2,
1, 1, 1, 1, 2, 1, 1,
1, 1, 1, 1, 2, 2, 1,
1, 1, 1, 1, 2, 1, 1,
1, 1, 1, 1, 2, 2,
1, 1, 1, 1, 2, 1, 1,
1, 1, 1, 1, 4,
1, 1, 1, 1, 2, 1, 1,
1, 1, 1, 1, 4,
4
};
void setup(){
pinMode(SPEAKER, OUTPUT);
pinMode(GREEN, OUTPUT);
pinMode(BLUE, OUTPUT);
pinMode(RED, OUTPUT);
Serial.begin(9600);
}
void loop(){
int value = Serial.read();
value = value - 0x30;
switch (value){
case 1:
//Serial.write("ようこそじゃぱりぱーくへ!\n");
for(int i=0;i<22;i++){
tone(8,japa[i],300*japa_notes_time[i]);
delay(175*japa_notes_time[i]);
noTone(8);
delay(10);
if(i%2==0){
digitalWrite(BLUE, HIGH);
}
else {
digitalWrite(RED, LOW);
digitalWrite(GREEN, LOW);
digitalWrite(BLUE, LOW);
}
}
digitalWrite(RED, LOW);
digitalWrite(GREEN, LOW);
digitalWrite(BLUE, LOW);
break;
case 2:
//Serial.write("恋\n");
for(int i=0;i<21;i++){
tone(8,koi[i],300*koi_notes_time[i]);
delay(175*koi_notes_time[i]);
noTone(8);
delay(10);
if(i%2==0) digitalWrite(RED, HIGH);
else {
digitalWrite(RED, LOW);
digitalWrite(GREEN, LOW);
digitalWrite(BLUE, LOW);
}
}
digitalWrite(RED, LOW);
digitalWrite(GREEN, LOW);
digitalWrite(BLUE, LOW);
break;
case 3:
//Serial.write("お願い!シンデレラ\n");
for(int i=0;i<35;i++){
tone(8,cinderella[i],300*cin_notes_time[i]);
delay(200*cin_notes_time[i]);
noTone(8);
delay(10);
if(i%4==0){
digitalWrite(RED, HIGH);
digitalWrite(GREEN, HIGH);
digitalWrite(BLUE, HIGH);
}
if(i%4==1){
digitalWrite(RED, HIGH);
digitalWrite(GREEN, HIGH);
digitalWrite(BLUE, LOW);
}
if(i%4==2){
digitalWrite(RED, HIGH);
digitalWrite(GREEN, LOW);
digitalWrite(BLUE, HIGH);
}
if(i%4==3){
digitalWrite(RED, LOW);
digitalWrite(GREEN, HIGH);
digitalWrite(BLUE, HIGH);
}
}
digitalWrite(RED, LOW);
digitalWrite(GREEN, LOW);
digitalWrite(BLUE, LOW);
break;
case 4:
//Serial.write("Town(てってってー)\n");
for(int i=0;i<76;i++){
tone(8,town[i],200*town_notes_time[i]);
delay(150*town_notes_time[i]);
noTone(8);
delay(10);
if(i%4==0){
digitalWrite(RED, HIGH);
digitalWrite(GREEN, HIGH);
digitalWrite(BLUE, HIGH);
}
if(i%4==1){
digitalWrite(RED, HIGH);
digitalWrite(GREEN, HIGH);
digitalWrite(BLUE, LOW);
}
if(i%4==2){
digitalWrite(RED, HIGH);
digitalWrite(GREEN, LOW);
digitalWrite(BLUE, HIGH);
}
if(i%4==3){
digitalWrite(RED, LOW);
digitalWrite(GREEN, HIGH);
digitalWrite(BLUE, HIGH);
}
}
digitalWrite(RED, LOW);
digitalWrite(GREEN, LOW);
digitalWrite(BLUE, LOW);
break;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment