@@ -960,7 +960,7 @@ The following example was created by Samantha Lagestee in 2017. Inspired by the
960
960
961
961
```
962
962
963
- /\ * Rick Roll Code
963
+ /* Rick Roll Code
964
964
AUTHOR: Samantha Lagestee
965
965
Copyright 2017 samilagestee at gmail dot com
966
966
@@ -973,7 +973,7 @@ Copyright 2017 samilagestee at gmail dot com
973
973
is not the creative property of the author. This code simply
974
974
plays a Piezo buzzer rendition of the song.
975
975
976
- \ */
976
+ */
977
977
978
978
#define a3f 208 // 208 Hz
979
979
#define b3f 233 // 233 Hz
@@ -1068,7 +1068,7 @@ int song1_chorus_rhythmn[] =
1068
1068
3, 3, 3, 1, 2, 2, 2, 4, 8, 4
1069
1069
};
1070
1070
1071
- char\ * lyrics_chorus[] =
1071
+ char* lyrics_chorus[] =
1072
1072
{ "Never ", "", "gonna ", "", "give ", "you ", "up\r\n",
1073
1073
"Never ", "", "gonna ", "", "let ", "you ", "down", "", "\r\n",
1074
1074
"Never ", "", "gonna ", "", "run ", "around ", "", "", "", "and ", "desert ", "", "you\r\n",
@@ -1079,90 +1079,91 @@ char\* lyrics_chorus[] =
1079
1079
1080
1080
void setup()
1081
1081
{
1082
- pinMode(piezo, OUTPUT);
1083
- pinMode(led, OUTPUT);
1084
- digitalWrite(led, LOW);
1085
- Serial.begin(9600);
1086
- flag = true;
1087
- a = 4;
1088
- b = 0;
1089
- c = 0;
1082
+ pinMode(piezo, OUTPUT);
1083
+ pinMode(led, OUTPUT);
1084
+ digitalWrite(led, LOW);
1085
+ Serial.begin(9600);
1086
+ flag = true;
1087
+ a = 4;
1088
+ b = 0;
1089
+ c = 0;
1090
1090
}
1091
1091
1092
1092
void loop()
1093
1093
{
1094
- // edit code here to define play conditions
1095
- /_
1096
- if (CONDITION 1) { // play
1097
- flag = true;
1098
- }
1099
- else if (CONDITION2) { // pause
1100
- flag = false;
1101
- }
1102
- _ /
1103
-
1104
- // play next step in song
1105
- if (flag == true) {
1106
- play();
1107
- }
1094
+ // edit code here to define play conditions
1095
+ /*
1096
+ if (CONDITION 1) { // play
1097
+ flag = true;
1098
+ }
1099
+ else if (CONDITION2) { // pause
1100
+ flag = false;
1101
+ }
1102
+ * /
1103
+
1104
+ // play next step in song
1105
+ if (flag == true) {
1106
+ play();
1107
+ }
1108
1108
}
1109
1109
1110
1110
void play() {
1111
- int notelength;
1112
- if (a == 1 || a == 2) { // Intro
1113
- // intro
1114
- notelength = beatlength _ song1_intro_rhythmn[b];
1115
- if (song1_intro_melody[b] > 0) { // if not a rest, play note
1116
- digitalWrite(led, HIGH);
1117
- tone(piezo, song1_intro_melody[b], notelength);
1118
- }
1119
- b++;
1120
- if (b >= sizeof(song1_intro_melody) / sizeof(int)) {
1121
- a++;
1122
- b = 0;
1123
- c = 0;
1124
- }
1125
- }
1126
- else if (a == 3 || a == 5) { // Verse 1
1127
- // verse
1128
- notelength = beatlength _ 2 _ song1_verse1_rhythmn[b];
1129
- if (song1_verse1_melody[b] > 0) {
1130
- digitalWrite(led, HIGH);
1131
- Serial.print(lyrics_verse1[c]);
1132
- tone(piezo, song1_verse1_melody[b], notelength);
1133
- c++;
1134
- }
1135
- b++;
1136
- if (b >= sizeof(song1_verse1_melody) / sizeof(int)) {
1137
- a++;
1138
- b = 0;
1139
- c = 0;
1140
- }
1141
- }
1142
- else if (a == 4 || a == 6) { //chorus
1143
- // chorus
1144
- notelength = beatlength _ song1_chorus_rhythmn[b];
1145
- if (song1_chorus_melody[b] > 0) {
1146
- digitalWrite(led, HIGH);
1147
- Serial.print(lyrics_chorus[c]);
1148
- tone(piezo, song1_chorus_melody[b], notelength);
1149
- c++;
1150
- }
1151
- b++;
1152
- if (b >= sizeof(song1_chorus_melody) / sizeof(int)) {
1153
- Serial.println("");
1154
- a++;
1155
- b = 0;
1156
- c = 0;
1157
- }
1158
- }
1159
- delay(notelength); // necessary because piezo is on independent timer
1160
- noTone(piezo);
1161
- digitalWrite(led, LOW);
1162
- delay(notelength \* beatseparationconstant); // create separation between notes
1163
- if (a == 7) { // loop back around to beginning of song
1164
- a = 1;
1165
- }
1111
+ int notelength;
1112
+ if (a == 1 || a == 2) { // Intro
1113
+ // intro
1114
+ notelength = beatlength * song1_intro_rhythmn[b];
1115
+ if (song1_intro_melody[b] > 0) { // if not a rest, play note
1116
+ digitalWrite(led, HIGH);
1117
+ tone(piezo, song1_intro_melody[b], notelength);
1118
+ }
1119
+
1120
+ b++;
1121
+ if (b >= sizeof(song1_intro_melody) / sizeof(int)) {
1122
+ a++;
1123
+ b = 0;
1124
+ c = 0;
1125
+ }
1126
+ } else if (a == 3 || a == 5) { // Verse 1
1127
+ // verse
1128
+ notelength = beatlength * 2 * song1_verse1_rhythmn[b];
1129
+ if (song1_verse1_melody[b] > 0) {
1130
+ digitalWrite(led, HIGH);
1131
+ Serial.print(lyrics_verse1[c]);
1132
+ tone(piezo, song1_verse1_melody[b], notelength);
1133
+ c++;
1134
+ }
1135
+ b++;
1136
+ if (b >= sizeof(song1_verse1_melody) / sizeof(int)) {
1137
+ a++;
1138
+ b = 0;
1139
+ c = 0;
1140
+ }
1141
+ } else if (a == 4 || a == 6) { //chorus
1142
+ // chorus
1143
+ notelength = beatlength * song1_chorus_rhythmn[b];
1144
+ if (song1_chorus_melody[b] > 0) {
1145
+ digitalWrite(led, HIGH);
1146
+ Serial.print(lyrics_chorus[c]);
1147
+ tone(piezo, song1_chorus_melody[b], notelength);
1148
+ c++;
1149
+ }
1150
+
1151
+ b++;
1152
+ if (b >= sizeof(song1_chorus_melody) / sizeof(int)) {
1153
+ Serial.println("");
1154
+ a++;
1155
+ b = 0;
1156
+ c = 0;
1157
+ }
1158
+ }
1159
+
1160
+ delay(notelength); // necessary because piezo is on independent timer
1161
+ noTone(piezo);
1162
+ digitalWrite(led, LOW);
1163
+ delay(notelength * beatseparationconstant); // create separation between notes
1164
+ if (a == 7) { // loop back around to beginning of song
1165
+ a = 1;
1166
+ }
1166
1167
}
1167
1168
```
1168
1169
0 commit comments