Rainbow and JavaScript
Animate a rainbow, then look at the same program as JavaScript. Intermediate · 10 min
Start this tutorial in TinkerPie Studio
Step by step
Rainbow block
From LED matrix, put
rainbow, shifted by 0 °insideforever.Make it move
Create a variable
hue. Drop it into the rainbow slot, then addchange hue by 12andpause (ms) 40.Run
Press Run. The colours flow across all 30 LEDs.
See the code
Switch to JavaScript at the top. This is the exact code the board runs:
led.rainbow(hue).Edit the code
Change
12to30and press Run. Typingled.shows every LED function with a short explanation.
Questions
What does "shifted by" mean in the rainbow block?
It turns the colour wheel by that many degrees (0 to 360). Changing the value a little each time round the loop makes the colours flow across the LEDs.
Do I need the TinkerPie board for this tutorial?
No. It works in the simulator in TinkerPie Studio. On a real TinkerPie V1 the same program lights the 30 RGB LEDs.
What comes after JavaScript?
Try From blocks to Arduino C++ to see the same ideas in Arduino code, or read the block coding guide.