// Copyright 2007, Sandeep Gangadharan // For more free scripts go to http://www.sivamdesign.com/scripts/
/* * 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!


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!


These are the new code concepts covered in this example program. To become a great coder, read through these concepts to learn new vocabulary.

New Concept: Using Speed as a Tool

You already know that computers can run code really quickly. So quickly that your eyes can't even see it! If you want to make two things appear to happen at the exact same time, that's pretty easy to do on Code Car- just type the code commands one line after another with no delay in between. 


New Concept: Finding Patterns

If you were successful in both challenges on this program, you probably figured out that there is a pattern that you can follow to complete a task. In this program, for example, the pattern for adding a new LED light is: 

1. Add a pinMode command for that light.

2. Add a digitalWrite(  , HIGH); command next to the other digitalWrite(  ,HIGH); commands.

3. Add a digitalwrite(  ,LOW); command next to the other digitalWrite(  ,LOW); commands. 

Once you know the pattern, you can imagine how you'd add any number of LED lights to the program! Don't be spooked as programs get larger- there are almost always patterns repeating throughout.


HOC: 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!



If you're having trouble, try to run an experimental program or look at the example code to help you find the answer.

To make two things appear to happen at the same time, you need to ___________.

If you don't type everything perfectly in a code comment or you forget to type one, what will happen?