// Copyright 2007, Sandeep Gangadharan // For more free scripts go to http://www.sivamdesign.com/scripts/
/* * Alternate blinking the two siren lights on Code Car */ 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); //Send power to pin 5 digitalWrite(6,LOW); //Turn on pin 6 delay(1000); //wait 1000 milliseconds digitalWrite(5,LOW); //Turn off the power to pin 5 digitalWrite(6,HIGH); //Turn on 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: Imagining and Visualizing

As your code gets more complex, it may be helpful to find ways to visualize what you want to do before putting into coding terms. In the final challenge of this example program, you might want to write down "4 on, wait, 5 on, wait, 6 on, wait....." and so on, before 'translating' your idea into the code terms "digitalWrite()" and "delay". Especially as you're getting used to the syntax of coding, take some time to visualize and imagine how you want your code to work before you start typing.


New Concept: Breaking it Down

You learned in the last project to look for patterns in existing code. In this program, you may have created your own patterns, starting with figuring out how to turn on and off one LED light. Maybe you used the 'copy/paste' commands on your keyboard or maybe you typed out each line of code. In either case, it will help you become a better programmer if you try to think about the repeating actions and patterns you want your code to run. Once you build the first piece, all you have to do it copy it and make small changes, like the pin number of an LED light.


HOC : Step by step

To complete the challenges in this lesson, you'll have to carefully think through the logical sequence of steps the code must take in order to turn on and off the LED lights. It might be helpful to have a pencil and paper to write down the sequence of your steps before translating it into code. Remember to look for patterns that you can repeat!


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

When you have a coding challenge that you're not sure how to complete, a good first step might be to ____________________ . Hint: there is more than one right answer!

The void loop of this program only contains 2 different functions. Which of these is not included in the void loop?