Activity: Colourful Sounds

Create a program that allows our robot to translate data from the colour sensors to display on the LEDs and play sounds. When you move your rover over new colours the LEDs will match that surface colour and create sound unique to that colour.

Relevant Coding Skills

Iteration
Maths

Relevant Rover Concepts

Colour
LEDs
Buzzer
Activity Demonstration

Activity Demonstration

Setup

This exercise requires access to many different coloured surfaces or cards. Lay them out in different orders on the floor and have the rover drive across them to play different tunes. To make this music sound good you will have to do some more complex calculations from the hue value to frequency. Try looking up the frequencies of musical notes.

 

Here’s Our Approach

Stage 1

We want to set all our LEDs to the colour our sensor is detecting. The Set LED blocks use an RGB value. The blocks we use to get colour sensor values do not return values in RGB. This means we need a way to translate the value from our colour sensor to an RGB value. One of the values we can get from our colour sensor block is hue, we can use a hue to colour block from the colour category and place that in our Set all LEDs block.

Stage 2

The hue colour sensor block returns a single number. We can program our rover’s buzzer to play sound at a specific frequency (in Hz), which is just a number of vibrations per second. We can place the hue value we get from our colour sensor directly inside our Play Sound block. We multiply this with a math block to make the sound more pronounced. See if you can add to this calculation to make better music.

Stage 3

We want to repeat this behaviour indefinitely so once it’s running we can pickup and move move our robot over new colours around us and it will play sound.

Example Code

Example Code

 

Related Posts

Previous
Previous

Activity: Conversation Bot

Next
Next

Activity: Prison Escape