Rather Read the Key Concept? Click Here


You may have noticed that this example program runs again and again- that's a code loop in action. Computers don't get tired and they don't get bored, so it's very easy to program a computer to do the same thing over and over. In this lesson, you'll blink an LED light on Code Car with a loop. The code inside the void loop section of the program is run from top to bottom, then starts over and runs again.

When your blinking LED code reaches the closing curly brace of void loop(), it jumps back to the top of the void loop and starts running again, line by line. The loop here doesn't change each time it is run and it never stops. Later, you'll learn about loops that change as they run and that stop once they reach a certain goal.

/* * Blink the tail light on and off once per second */ void setup() { pinMode(7,OUTPUT); //set your tail light LED as an OUTPUT } void loop() { digitalWrite(7,HIGH); //Send power to pin 7 delay(1000); //wait 1000 milliseconds (1 second) with the tail light on digitalWrite(7,LOW); //Turn off the power to pin 7 delay(1000); //wait 1000 milliseconds with the tail light off } // (c) 2017 Let's Start Coding. License: www.letsstartcoding.com/bsdlicense

Walkthrough Videos

Watch the videos for line-by-line explanation of how the example program works. Then you'll be ready to make some changes of your own!


How many can you complete? Change the code according to the challenges below. Upload your code to see the effect when you're finished. Complete a challenge? Check it off the list!

Spread the word! Tell your friends, classmates, and family about your Hour of Code!