// Copyright 2007, Sandeep Gangadharan // For more free scripts go to http://www.sivamdesign.com/scripts/

Flash Both Sirens with Code Car

Blink Hookup: 1 LED in pin 13. Remember shorter leg of LED is ground.

Blink both of the siren lights to learn about combining code commands. Get creative with your light patterns!


The code below already works and is ready to upload! Upload the code to Code Car and see what happens. Then, you'll 'take apart' the code to learn what each piece of the program does.

/* * 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.



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?