if (x
<= 255)
{}
else
{}
“If/else” statements are used to make choices in your programs. The
statement within the parentheses ( ) is evaluated; if it’s true, the code within
the first brackets { } will run. If it’s not true, the code within the second
brackets { } will run.
What You Should See
You should see your LED turn on, but this time in new, crazy colors! If it
doesn’t, make sure you have assembled the circuit correctly and verified
and uploaded the code to your board, or see the Troubleshooting section.
Troubleshooting
LED Remains Dark or Shows Incorrect Color
With the four pins of the LED so close together, it’s sometimes easy to
misplace one. Double check that each pin is where it should be.
Seeing Red
The red diode within the RGB LED may be a bit brighter than the other two.
To make your colors more balanced, use a higher ohm resistor.
Experiment 4: Driving Multiple LEDs
Introduction
Now that you’ve gotten your LED to blink on and off, it’s time to up the
stakes a little bit – by connecting
six LEDs at once
. We’ll also give your
RedBoard a little test by creating various lighting sequences. This
experiment is a great setup to start practicing writing your own programs
and getting a feel for the way your RedBoard works.
Along with controlling the LEDs, you’ll learn a few programming tricks that
keep your code neat and tidy!
You will need the following parts:
•
1x
Breadboard
•
1x
SparkFun RedBoard
•
6x
LEDs
•
6x
330
Ω
Resistors
•
7x
Jumper Wires
Didn’t Get the Tinker Kit?
If you are conducting this experiment and didn’t get the Tinker Kit, we
suggest using these parts:
Page 20 of 63