You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
> This article was revised on 2022/09/28 by Hannes Siebeneicher.
9
16
10
-
This article highlights different approaches to making sounds and even entire songs with an Arduino. In 2013 Brett Hagman created the [tone()](https://www.arduino.cc/reference/en/language/functions/advanced-io/tone/) library which is a good starting point for creating different types of sounds using an Arduino. As the examples in this article are gathered from the Arduino playground and were mostly created before 2013 the differences in the code should be noted. The examples are nevertheless still relevant as they explain some basic concepts of generating tone frequencies, interpolation and even provide you with some songs to try out. If you want to see an example for a simple melody using the [tone()](https://www.arduino.cc/reference/en/language/functions/advanced-io/tone/) library and familiarize yourself with the concept of external sound data files, you can check out [this example](https://docs.arduino.cc/built-in-examples/digital/toneMelody).
17
+
This article highlights different approaches to making sounds and even entire songs with an Arduino. In 2013 Brett Hagman created the [tone()](https://www.arduino.cc/reference/en/language/functions/advanced-io/tone/) library which is a good starting point for creating different types of sounds using an Arduino. As the examples in this article are gathered from the Arduino playground and were mostly created before 2013 a lot of steps are still done manually, which can be skipped when using the [tone()](https://www.arduino.cc/reference/en/language/functions/advanced-io/tone/) library.
18
+
19
+
The examples are nevertheless still relevant as they explain some basic concepts of generating tone frequencies, interpolation and even provide you with some songs to try out. If you want to see an example for a simple melody using the [tone()](https://www.arduino.cc/reference/en/language/functions/advanced-io/tone/) library and familiarize yourself with the concept of external sound data files, you can check out [this example](https://docs.arduino.cc/built-in-examples/digital/toneMelody).
11
20
12
21
Most sketches in this article use pin 8 as output for the piezo buzzer or speaker which means you only need to connect your components a shown below and try out the different examples by uploading them to your Arduino. Only the **PCMAudio** example uses pin 11 as it is making us of [PWM](https://www.arduino.cc/en/Tutorial/Foundations/PWM).
13
22
@@ -154,7 +163,7 @@ pinMode(outpin, INPUT); // shut off pin to avoid noise from other
154
163
155
164
### Duration extension
156
165
157
-
Here's some minor tweaks to the above to extend it just a bit. The above untouched is left out because its simplicity is great. Basically, the array has been changed to have durations and a sentinel was added to mark the end.
166
+
In the example below some minor tweaks have been made, mostly changing the array to have durations and a sentinel was added to mark the end. The example shown above remains as it shows a great simplistic structure.
158
167
159
168
```
160
169
float EIGHTH = 1;
@@ -275,7 +284,6 @@ Takes over Timer 1 (16-bit) for the 8000 Hz timer. This breaks PWM (analogWrite(
The following example was created by Samantha Lagestee in 2017. Inspired by the popular meme, this code rickrolls people by playing the song "Never Gonna Give You Up" by Rick Astley on a piezo buzzer. Open the serial port to see the lyrics and sing along.
959
966
960
967
### Code
968
+
961
969
```
962
970
963
971
/\* Rick Roll Code
@@ -980,14 +988,14 @@ Copyright 2017 samilagestee at gmail dot com
980
988
#define b3 247 // 247 Hz
981
989
#define c4 261 // 261 Hz MIDDLE C
982
990
#define c4s 277 // 277 Hz
983
-
#define e4f 311 // 311 Hz
991
+
#define e4f 311 // 311 Hz
984
992
#define f4 349 // 349 Hz
985
-
#define a4f 415 // 415 Hz
993
+
#define a4f 415 // 415 Hz
986
994
#define b4f 466 // 466 Hz
987
995
#define b4 493 // 493 Hz
988
996
#define c5 523 // 523 Hz
989
997
#define c5s 554 // 554 Hz
990
-
#define e5f 622 // 622 Hz
998
+
#define e5f 622 // 622 Hz
991
999
#define f5 698 // 698 Hz
992
1000
#define f5s 740 // 740 Hz
993
1001
#define a5f 831 // 831 Hz
@@ -1164,13 +1172,14 @@ if (a == 7) { // loop back around to beginning of song
1164
1172
a = 1;
1165
1173
}
1166
1174
}
1167
-
1168
1175
```
1169
1176
1170
1177
## MusicalAlgoFun
1178
+
1171
1179
This is a simple song with the Arduino created by Alexandre Quessy in 2006.
0 commit comments