Light Rocket Boosters

Light the booster LEDs in unison and see how to combine code statements.

Code

The code in the editor below already works Just plug in your Code Rocket and press upload to see what it does! Tinker with it and make changes to see what each line of code controls.

//Turn on the 'booster' LEDs number 9 and 10 void setup(){ pinMode(9,OUTPUT); //Set booster 9 as an 'OUTPUT' pinMode(10,OUTPUT); //Set booster 10 as an 'OUTPUT' } void loop(){ digitalWrite(9,HIGH); //turn on the #9 LED digitalWrite(10,HIGH); //turn on the #10 LED } // (c) 2018 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!

Challenges

Can you complete the challenge? Change the code in the editor above. 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: Functions and Arguments

In this program, you used the pinMode function to set each LED as an OUTPUT, then the digitalWrite function to turn on each LED. You probably noticed that the functions are repeated. Why? It seems easier to be able to type digitalWrite(9,10,HIGH); , right? When a programmer creates a new function, they get to decide what information is required by that function - that information is called the ‘arguments’ for the function.

The digitalWrite function was designed to use just two pieces of information: a pin number and a HIGH or LOW command. If you try to provide more information to that function , like a second number, the function can’t interpret the extra information. Is that extra number a pin number? Is it a number for power level? Is it just an accidental comma that a programmer left in? Because the function wasn’t designed for the extra information, the code won’t run.

It’s important to learn what information your functions can handle and how much information you can provide them. That’s why we include the purple cards with your kit- as a reference for each common function and statement you’ll use.

Real Life Example: ‘Party’ Function

Imagine someone invites you to a party. That sounds great, but you need some important information before you can attend. At a minimum, you need to know what day and where the party will take place. You might also want to know what hour the party will start, and if it’s a party where you should bring a gift. If you designed a function called ‘party’, it might look like this:

party(day, address, hour, gift);

and if you were a computer, a valid invitation to a party might look like:

party(7/4/19,685 Main Street,18:00,FALSE);

With that information, you’d be able to attend! What other arguments would be useful for a party function?

Quiz

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

1. What are the arguments of one of the digitalWrite functions used in the example?