Rather Read the Key Concept? Click Here


In this program, your code will 'make a decision' about whether or not to turn on the LED brake light. The decision is based on whether or not a button is pressed. In code, you express decisions with 'if' statements, a piece of code that runs only under certain conditions. You surely make hundreds of decisions each day, and each of those could be simplified down into an 'if' statement!

The rest of the lessons in this hour will be based on the different ways you can use 'if' statements to make multiple things happen, or how you can combine 'if' statements to work under many different conditions.

/* * Press button 11 for the brakes and brakelight of Code Car */ void setup(){ pinMode(7, OUTPUT); // Tail light pinMode(11, INPUT_PULLUP); //"Brakes" button } void loop(){ //if the pushbutton is pressed, hold the LED on if (digitalRead(11) == LOW) { //if the button is pressed digitalWrite(7, HIGH); //the code between the braces is the 'action' } else { // an else statement runs when the 'if' condition isn't true digitalWrite(7,LOW); //otherwise, turn LED off } } // (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!

Spread the word! Tell your friends, classmates, and family about your Hour of Code!