TINKER PiEDESIGN IN INDIA

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

  1. Rainbow block

    From LED matrix, put rainbow, shifted by 0 ° inside forever.

  2. Make it move

    Create a variable hue. Drop it into the rainbow slot, then add change hue by 12 and pause (ms) 40.

  3. Run

    Press Run. The colours flow across all 30 LEDs.

  4. See the code

    Switch to JavaScript at the top. This is the exact code the board runs: led.rainbow(hue).

  5. Edit the code

    Change 12 to 30 and press Run. Typing led. 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.