Following on from my adventures with the PS2 keyboard, I modified the code to play tones.
What I like about this is the opportunity to work with arrays. The “FOR” section is key. It scans an array to see if there is a match with the pressed key. If there’s a match, it then uses the position of the array to get the frequency and play it.
A noisy lesson – take a couple of speakers and get them to play a frequency. The frequency range is about 30 hertz to 20,000 hertz. As you get older, the top level you can hear goes down. I like this lesson as it teaches some key words such as frequency, tone, pitch and vibration. It also builds up into teaching the idea of variables as well as functions. Plus it teaches music.
The basic code for Arduino:
tone (10,500); // 10 is the speaker pin, 500 is the frequency.
Easy to pick up. Here’s an example.
It’s just tones at the moment. We can use this to make music as well.
Make basic circuit so LEDs flash up. (they can code LEDs to flash already in Arduino)
Learn how to create a tune using the TONE function.
Link the tune to flashing lights.
Create the circuit on a piece of card
Put the circuit on to a small chip so it works independently. (my job)
Take home, add power and watch it light up.
It’s going to be a fun, creative project. They can even paint the card as well so it looks all pretty and artistic.
The only real cost is the chip – and that’s £2!! The speakers will be hacked from broken headphones – something that’s very common in primary schools. I like this because it shows that broken does not mean broken.
The project will also teach the physics of sound – looking at frequency and pitch. Plus coding of course.
A great lesson. Covers the concepts of pitch, frequency and how speakers work. Next step is to introduce the notes and get them to create their own music. Hopefully then they will be able to put them into a card.
Delivering the computing curriculum to primary schools