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

Alternate Siren Lights with Code Car

 
 

Alternate the sirens like a police car on the road. Play with the speed and build on with your own code. 

Code

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.

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!



Concepts

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.

 

Quiz

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?