Rather Read the Key Concept? Click Here

KEY CONCEPT: FINDING PATTERNS

In this lesson, you'll start to see some repetition of code commands. It's a good idea to look for patterns in programs, so that you can start to make broad connections about how code is working without getting too caught up in the details.

In this case, you'll use the exact same commands to control two different LED lights on Code Car, turning them on, then turning them off. Once you recognize the pattern that you need for each LED, it's simple to add more LEDs for a light show!

 
/* * Flash the siren lights of Code Car on and off together */ void setup() { pinMode(5,OUTPUT); //set your blue siren light as an OUTPUT pinMode(6,OUTPUT); //set your red siren light as an OUTPUT } void loop() { digitalWrite(5,HIGH); //Turn on pin 5 digitalWrite(6,HIGH); //Turn on pin 6 delay(1000); //wait 1000 milliseconds digitalWrite(5,LOW); //Turn off power to pin 5 digitalWrite(6,LOW); //Turn off pin 6 delay(1000); } // (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!


Challenges

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!