Skip to content

Commit 3cb56dc

Browse files
authored
Merge pull request #1321 from goshlanguage/patch-1
Update audio.md to resolve syntax errors
2 parents 5a698ad + 8f3b330 commit 3cb56dc

File tree

1 file changed

+81
-80
lines changed
  • content/learn/03.programming/10.audio

1 file changed

+81
-80
lines changed

content/learn/03.programming/10.audio/audio.md

Lines changed: 81 additions & 80 deletions
Original file line numberDiff line numberDiff line change
@@ -960,7 +960,7 @@ The following example was created by Samantha Lagestee in 2017. Inspired by the
960960

961961
```
962962
963-
/\* Rick Roll Code
963+
/* Rick Roll Code
964964
AUTHOR: Samantha Lagestee
965965
Copyright 2017 samilagestee at gmail dot com
966966
@@ -973,7 +973,7 @@ Copyright 2017 samilagestee at gmail dot com
973973
is not the creative property of the author. This code simply
974974
plays a Piezo buzzer rendition of the song.
975975
976-
\*/
976+
*/
977977
978978
#define a3f 208 // 208 Hz
979979
#define b3f 233 // 233 Hz
@@ -1068,7 +1068,7 @@ int song1_chorus_rhythmn[] =
10681068
3, 3, 3, 1, 2, 2, 2, 4, 8, 4
10691069
};
10701070
1071-
char\* lyrics_chorus[] =
1071+
char* lyrics_chorus[] =
10721072
{ "Never ", "", "gonna ", "", "give ", "you ", "up\r\n",
10731073
"Never ", "", "gonna ", "", "let ", "you ", "down", "", "\r\n",
10741074
"Never ", "", "gonna ", "", "run ", "around ", "", "", "", "and ", "desert ", "", "you\r\n",
@@ -1079,90 +1079,91 @@ char\* lyrics_chorus[] =
10791079
10801080
void setup()
10811081
{
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;
10901090
}
10911091
10921092
void loop()
10931093
{
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+
}
11081108
}
11091109
11101110
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+
}
11661167
}
11671168
```
11681169

0 commit comments

Comments
 (0)