The WHILE function.
WHILE something is true, DO something. That’s all.
So in Sonic Pi, we declare a variable called NOTE. Make it worth 20.
Play the note
Add 1 to the value of note.
Check if note < 120. If so, play the new note. Add 1 etc.
Lovely to see in action.
Variables are very powerful. They are used in Scratch and can easily be taught through drama.
VARIABLE Life = 5
VARIABLE Points = 0
VARIABLE Game Over = false
IF you get touched, you lose a life
IF you score, you get 1 point
FOREVER (if GAME OVER NOT TRUE) CHECK LIFE & POINTS
IF LIFE = 0, GAME OVER = TRUE, WIN = FALSE
IF POINTS = 10, GAME OVER = TRUE,WIN = TRUE
IF GAME OVER = TRUE, CHECK WIN.
This demonstrates how variables can be used in music using Sonic Pi.
Sonic Pi is a great way of introducing text coding in the primary classroom. Essentially it allows the children to create a sequence of music using code.
Why teach it?
- Introduces text coding
- It’s creative – and helps teach music
- It’s quick – instant feedback to children
- It teaches a lot of coding concepts
This video introduces the key concepts.
I love Sonic Pi – it’s a great way to teach text coding and to introduce coding concepts.
So I adapted the code from the Arduino to use it on Sonic Pi
The code is here: