Make It Better

Switching to Loops

Bored of watching the light show? Want to make your own animation, change the animation, or learn about looping functions? Let's make CIRC02 better!

In the void loop() procedure, there are 4 lines. The last three all start with a //. This means the line is a comment (it won't run). We can switch the program to use loops by deleting the comments (If you want to learn more about comments, we have a great writeup!).

First, inside void loop(), add slashes to disable the oneAfterAnotherNoLoop() procedure from running:

    oneAfterAnotherNoLoop(); -> //oneAfterAnotherNoLoop();

Next, we are going to delete comments (slashes) to enable the oneAfterAnotherLoop() procedure to run with loops:

    //oneAfterAnotherLoop();  -> oneAfterAnotherLoop(); 

We should verify that our code compiles correctly now, click the check mark (or, ctrl/command+r). If everything compiles with no errors, go ahead and Upload (ctrl+u) the new program to your metro. 

After running the program, what changed?

There was no change! Both procedures run the same animation.  (click to reveal the answer)

What's the difference between the two procedures: oneAfterAnotherNoLoop() and oneAfterAnotherLoop()?

oneAfterAnotherNoLoop() runs the animation without using a loop which makes for a lot of typing. Using oneAfterAnotherLoop() will require less typing to run the same animation! (click to reveal the answer)

Extra Animations

Tired of this animation? There are more animations for you to play around with!

To enable them, uncomment (just delete the //) row 3 and row 4 so that:

   //oneOnAtATime(); -> oneOnAtATime();

   //inAndOut(); -> inAndOut();

 Then Upload the program (ctrl+u) to your board and enjoy the new light animations. 

Make your own animations

Go ahead and jump into the included code and start changing things around.  

To tell the Metro to turn a LED on,

    digitalWrite(pinNumber, HIGH);

If you want to tell the Metro to turn a LED off,

   digitalWrite(pinNumber, LOW); 

Type away! Regardless of what you change you won't break anything.

This guide was first published on Aug 18, 2017. It was last updated on Aug 18, 2017. This page (Make It Better ) was last updated on Jan 18, 2018.