4. Music and colour

Music and colour

In this exercise, we will experiment with the LED lights and the music notes of our mBot.

As we already learnt in the exercise first blocks.

 

You will learn

  • To combine different functions of the mBot.
  • The RGB colour system in more detail.
  • How to use variables to programme your mBot.

Open the mBlock programme on your computer, switch on your mBot and connect it.

PREPERATION

Check the steps in "execute". Answer the following questions:

  • Which steps should I follow?
  • Which steps can I take?
  • How much time do I need?
  • What tools do I need?

EXECUTE

Perform the steps one by one. Have you forgotten how to do it? Look at the hints or download the solution.

STEP 1

Theremin

theremin

Do you know what a theremin is? This musical instrument has existed since 1929 and produces different notes depending on the musician's hand position.
Create a theremin playing different notes depending on how far or how close your hand is to the ultrasonic sensor.

uitdaging

Programme your mBot to play the song: “Brother John”.

STEP 2

A colourful keyboard piano

The music

Now we will change your computer keyboard into a piano.

piano

If key ‘A’ is pressed, we want to hear a C4. Can you programme this?

blocks

Make sure you have a complete piano. You can, for example, play "Brother John” with the keyboard!

It is not a lot of extra work to also link the other keys to the right note. To save you some time, you can always right-click on a group of blocks. If you click 'Duplicate’, the group will be copied.

The colours

Now, we want to change your mBot into a colourful piano. Depending on the note, the lights will light up another colour.

Which colour? That's up to you! We have chosen red for the lowest note. A higher tone will gradually become a little more blue.

piano met kleur

Make sure you put the blocks for the colours and the notes in the right order. If not, it will not produce the desired result.

uitdaging

a)    In order to perfect your piano, make sure that the light is off after you have played the tone. Will you give it a try?  

b)    On a real keyboard, you can press a key in order to play a certain tune.  Will you give it a try?

STEP 3

Rainbow

An RGB light can emit a red, green or blue colour, which can shine between 0 (off) and 255 (maximum light).  However, you already knew that!  By mixing these three colours, you can pretty much conjure up any colour. 

RGB wielrgb

In this challenge, we will start off with the colour red and gradually turn it into green or blue.  

toelichting

We must receive feedback from the lamps: after all, we have to know what state they are in at different times.  We can achieve this by creating variables. 

REFLECTING

Look back at the project you just made. Ask yourself the following questions:

  • Does the programme work like I expected?
  • What is working well?
  • What is not working well?
  • How can I do things differently?

Download

Click on the links below to download the solutions: