Our workshop kit has a small speaker and amplifier connected to pin 2.
(See Kit)
Using the Arduino "tone" function, we can make some noise.
Here's the Arduino language reference for the tone() function:
https://www.arduino.cc/reference/en/language/functions/advanced-io/tone/
Generates a square wave of the specified frequency (and 50% duty cycle) on a pin. A duration can be specified, otherwise the wave continues until a call to noTone(). The pin can be connected to a piezo buzzer or other speaker to play tones.
...
tone(pin, frequency)
tone(pin, frequency, duration)
pin: the Arduino pin on which to generate the tone.
frequency: the frequency of the tone in hertz. Allowed data types: unsigned int.
duration: the duration of the tone in milliseconds (optional). Allowed data types: unsigned long.
In the Arduino IDE:
File > Examples > 0.2 Digital > toneMelody
Change the tone() and noTone() statements in the sketch to use the correct pin for the speaker.
If you'd like, you can use model from the Button exercise to improve this example:
const int speakerPin = 2; // the number of the speaker pin
Then, change
tone(8, melody[thisNote], noteDuration);
to
tone(speakerPin, melody[thisNote], noteDuration);
Do the same thing for the statement that uses noTone().
Tools > Processor: ATMega32U5 (5V, 16Mhz)
Important! Be sure to select the 5V Processor!
(We are using 5 volt Pro Micros, not the 3.3 volt version.)
Otherwise, when you upload a sketch, you will "brick" the Pro Micro.
Compile and Upload your sketch.
Does it work?
Change it to do something else:
Write your own melody
Use the buttons to play the tones
Blink the LEDs while the melody is playing
your ideas?