Holiday Lights
Light patterns with Arduino!
In this activity, you will create different patterns of colors using the power of Arduino. This Christmas tree has 16 strands of light, each with 8 special LEDs called "NeoPixels." Sounds like fun? Let's get started!
Ask Ms. Koo or Mrs. Marshall for a Chromebook to begin!
Setup!
- Sign into your Chromebook with the following email:
- Username: sdmsstudent01@wethersfield.me
- Password: Student15
- Go to this website: www.codebender.cc/user/gkoo
- Click Log In at the top right corner, then click the red "Sign In with Google" button
- Click on the "HolidayTree" project
- Click on "Clone and Edit" towards the right side of the screen.
- Click the green "Clone Sketch & libraries" button
Coding!
- Underneath the block of code called "setup()" we are going to create your own function. This is where you are going to write all your code!
Make sure your cursor is all the way past the final curly bracket (}) before typing:
void NAME(){
// code below this line
// code above this line
}
Replace NAME with your first name and last initial (same as what we used earlier).
- Before we start coding, we have to tell the Arduino to run your function. Add a call to the function INSIDE the "setup()" block by adding:
- The name of your function
- Two parentheses
- And a semicolon (;)
AFTER tree.init(10); but before the final curly bracket (}).
API
API stands for "Application Program Interface." APIs explain what a piece of code can do and how you can use it to make your own programs.
Class: Holiday Tree
- HolidayTree(numStrands, numLights):
This creates an instance of the HolidayTree, telling the computer how many strands of lights there are, and how many lights are on each strand.
- tree.init(brightness):
Sets initial values and takes care of behind-the-scenes setup for the entire tree.
tree.init(10);
- tree.setLightColor(strandNum, light, color):
Allows the user to set the color of a single light. Give the "X" coordinate (which strand it's on) and the "Y" coordinate (which light on the strand). Use Enum: Color for a list of colors that can be used. HINTS: Always start counting at zero! Also, don't forget show(ms).
- tree.setLightColor(strandNum, light, red, green, blue):
Same as above, but colors are represented by R, G, and B values which can be any number between 0 (off) and 255 (max). Read More...
- tree.setRowColor(rowNum, color):
Sets an entire row (horizontal) to be one color. Give the "Y" coordinate of the row and the color (see Enum: Color). Must call show(ms) for this to have an effect.
- tree.setRowColor(rowNum, red, green, blue):
Same as above, but with R, G, and B values.
- tree.setColumnColor(colNum, Color color):
Sets an entire column (vertical) to be one color. Give the "X" coordinate of the row and the color (see Enum: Color). Must call show(ms) for this to have an effect.
- tree.setColumnColor(colNum, red, green, blue):
Same as above, but with R, G, and B values.
- tree.show(ms):
Sends the values to the lights. Pauses for given amount of time in miliseconds before executing next command.
- tree.reset():
Turns all lights on the tree off. Must call show(ms) for this to have an effect.
- tree.getNumStrands():
Returns the number of strands that are on the tree as an integer.
- tree.getNumLights():
Returns the number of lights per strand that are on the tree as an integer.
Enum: Color
- RED
- ORANGE
- YELLOW
- GREEN
- CYAN
- BLUE
- PURPLE
- MAGENTA
- WHITE