Light the booster LEDs in unison and see how to combine code statements.
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?