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

Brake Pedal Light with Code Car

 
 

Code one of the buttons on Code Car to act as a brake pedal, turning on the brake lights when the 'pedal' is pressed!

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: Inputs vs. Outputs

Up to this point, after you hit "Upload" for your code, all you could do is observe what it does. With the addition of buttons to your program, you now have the ability to interact with your code and change what Code Car does after you've uploaded code. This is also the point when you could show your Code Car to someone else and they could interact with it without being involved with the coding process. In computer science terms, the button is an 'interface' to your program, so that a simple action (pressing it) makes something complicated happen in the background, and then an outcome occurs (the light turns on!).

It's useful to think of inputs as things that send information into a program. Then the program can do something with that information. The do something is often a process that leads to an output.

 

New Concept: Decision Making

This program is the first time that your Code Car has 'made a decision' about what to do. To put it a different way, each time the void loop of the program runs, two different things could happen: the brake light could be signaled to turn on or it could be signaled to turn off. Almost any time there is an input to a program, there is a 'decision' being made. Imagine logging off of your computer. You go and find the 'log out' button and click it. Somewhere in the computer code, there must be a 'decision' made by the code so that "if 'log off' is clicked, run the log off process."

Quiz

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

What is the syntax of an 'if' statement?



What are the argument(s)-pieces of information- that the digitalRead() function needs?