Booster LED Power Up Fade

You'll want to warm up your boosters or slow down your speed gradually when taking off and landing the Code Rocket. Learn how to gradually increase the power sent to your booster LEDs.

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.

/* Fade up the booster LED lights*/ void setup(){ pinMode(9,OUTPUT); pinMode(10,OUTPUT); } void loop(){ for(int i=0; i<256; i++){ //set brightness to 0, increasing it by 1 every 'for' loop until it equals 255 analogWrite(9,i); //send the brightness level 'i' to LED9 analogWrite(10,i); //send the brightness level 'i' to LED10 delay(25); //wait 25 milliseconds before increasing brightness } } // (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

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: analogWrite

This project is the first time you’ve seen that you can send signals besides ‘on’ and ‘off’ to an LED. Note that this capability isn’t available on all of Code Rocket’s LEDs, just LEDs 3, 5, 6, 9, and 10. analogWrite has a range from 0 brightness to 255 brightness, and 255 brightness looks the same as digitalWrite(pin,HIGH); would look.

Real Life Example: Plain light switch versus a dimmer switch

A typical light switch has two positions: on or off. When a light is triggered by a switch like this, it turns on 100% power. A dimmer switch, on the other hand, has a range of values it can send to a light. The dimmer switch is like what is happening with the analogWrite command in this program.

New Concept: Limited looping

Up to this point, there have been two ‘loops’ that run in each program. The void setup is a ‘one time loop’. It runs once when the board is powered on. The void loop is continuous, running forever or until you remove power from the board. Now with the ‘for’ loop, you have control over how many times an action occurs.

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 four parts of a 'for' loop, in order of how they're typed? Hint: Use your purple cards!




2. Which pins can you use with analogWrite on Code Rocket? Hint: It's in the New Concepts section!