LED LIGHTS
Getting Started
0:00 - 1:51
27:33 - 29:19
Run the Arduino IDE Program
Good idea to right click on it and
Pin to Taskbar
Preferences
Plug In
Setup 1
make sure Arduino Uno is selected in Tools -> Board ...
Setup 2
select the COM port1 that's been assigned to the Arduino in Tools -> Port
make sure to click to get the checkmark
You may have to do this EVERY time you plug in an arduino
COM1 will NOT work
1usually the highest numbered COM
Verify Setup
at bottom right it should now indicate that your Arduino Uno is connected to the COM port
Blink
load the Blink program into the arduino editor
File -> Examples -> 01. Basics -> Blink
// the setup function runs once when you press reset or power the board
void setup() {
// initialize digital pin 13 as an output.
pinMode(LED_BUILTIN, OUTPUT);
}
// the loop function runs over and over again forever
void loop() {
digitalWrite(LED_BUILTIN, HIGH); // turn the LED on (i.e. voltage HIGH)
delay(1000); // wait for a second
digitalWrite(LED_BUILTIN, LOW); // turn the LED off (i.e. voltage LOW)
delay(1000); // wait for a second
}
setup() function runs once at startup
loop() function runs continually
Blink
upload the Blink program to the Arduino by clicking on
Blink a LED on the Arduino
one small LED light on the Arduino should now be blinking
FastLED library
FastLED is a fast, efficient, easy-to-use Arduino library for programming addressable LED strips and pixels such as WS2810, WS2811, LPD8806, Neopixel and more. FastLED is used by thousands of developers, in countless art and hobby projects, and in numerous commercial products.
FastLED library
FastLED library
install the FastLED library
Sketch -> Include Library-> Add .Zip Libraries...
and select your downloaded zip file
Contributed libraries like FastLED are installed in Documents\Arduino\libraries\FastLED-3.5.0
FastLED library
verify that the FastLED library is installed
Do NOT click on FastLED, just make sure it is there
Connecting LED Lights
5V
GND
2
connecting the three wires from the lights to the Arduino
Connecting LED Lights
wire to pin 2
(2) connect red
wire to 5V pin
(3) connect black
wire to GND pin
File -> New
Replace the default program in the window with the program on the next slide.
50 LED Sample Code
#include <FastLED.h> // include the FastLED library code
#define DATA_PIN 2
#define NUM_LEDS 50
#define MAX_BRIGHTNESS 255
#define BRIGHTNESS 100 // MAX is 255
CRGB leds[NUM_LEDS]; // array of leds[]
// runs once when program starts (see setup code)
void setup() {
Serial.begin(9600); //enables serial output for debugging
FastLED.addLeds<WS2811, DATA_PIN, RGB>(leds, NUM_LEDS).setCorrection(TypicalLEDStrip);
FastLED.setBrightness(BRIGHTNESS);
}
// loops continuously (see loop code)
void loop() {
leds[0]=CRGB::White; // sets leds array element 0 to a color name (e.g. White)
FastLED.show(); // show the values of 50 element leds[] array on 50 LEDs
delay(1000); // pauses for the specified number of milliseconds
leds[0].setRGB(0,0,0); // sets leds array element 0 to a RGB color (e.g. black)
FastLED.show(); // show the values of 50 element leds[] array on 50 LEDs
delay(1000); // pauses for the specified number of milliseconds
}
50 LED Sample Code
Each arduino program MUST have a setup() and a loop() function.
#include <FastLED.h> // include the FastLED library code
#define DATA_PIN 2
#define NUM_LEDS 50
#define MAX_BRIGHTNESS 255
#define BRIGHTNESS 100 // MAX is 255
CRGB leds[NUM_LEDS]; // array of leds[]
// runs once when program starts (see setup code)
void setup() {
Serial.begin(9600); //enables serial output for debugging
FastLED.addLeds<WS2811, DATA_PIN, RGB>(leds, NUM_LEDS).setCorrection(TypicalLEDStrip);
FastLED.setBrightness(BRIGHTNESS);
}
50 LED Sample Code Part 1 of 2
leds[0] | leds[1] | leds[2] | leds[3] | leds[4] | ⋯ | leds[48] | leds[49] |
arduino
memory
Initial functions
// loops continuously (see loop code)
void loop() {
leds[0]=CRGB::White; // sets leds array element 0 to a color name (e.g. White)
FastLED.show(); // show the values of 50 element leds[] array on 50 LEDs
delay(1000); // pauses for the specified number of milliseconds
leds[0].setRGB(0,0,0); // sets leds array element 0 to a RGB color (e.g. black)
FastLED.show(); // show the values of 50 element leds[] array on 50 LEDs
delay(1000); // pauses for the specified number of milliseconds
}
Upload the program and you should see 1 of the 50 LEDs blinking white.
50 LED Sample Code Part 2 of 2
Initial functions
The 50 element leds[ ] array exists only in the C++ program on your Arduino.
Changing a value in the leds[ ] array does NOT change the actual LEDs without calling FastLED.show()
just changing a value in leds[ ]
the leds[ ] array the actual LEDs
From FastLED Basic Usage
the leds[ ] array the actual LEDs
"Making your LEDs actually show colors is a two part process with this library. First, you set the values of the entries in the leds[ ] array to whatever colors you want. Then you tell the library to show your data. Your animation/code/patterns will pretty much consist of this cycle.
You can change the value that you set to an LED between calls to show (i.e. leds[ ] = ), and the next time you call show the new value will get written out."
Initial functions
To get the 50 values currently in the leds[] array to show up on the 50 actual LEDs use FastLED.show();
You will likely need a delay(); before doing the next FastLED.show(); to give some time for the LEDs values to persist.
leds[ ] and FastLED.show(); / FastLED.delay();
// The FastLED library delay() method
FastLED.delay(1000);
// is like doing both a FastLED.show() and an arduino delay()
FastLED.show();
delay(1000);
Initial functions
All your code must be inside a function.
Thus your code must be in the loop() function.
// the setup function runs once when you press reset or power the board
void setup() {
// initialize digital pin 13 as an output.
pinMode(13, OUTPUT);
}
// the loop function runs over and over again forever
void loop() {
leds[0]=CRGB::White; // Sets leds array element 0 to a color name (e.g. White)
FastLED.delay(1000); // shows LEDs & pauses for the specified number of milliseconds
leds[0].setRGB(0,0,0); // Sets leds array element 0 to a RGB color (e.g. black)
FastLED.delay(1000); // shows LEDs & pauses for the specified number of milliseconds
}
runs once at startup
runs in a loop continuously
Initial functions
You can put your code into
your own function
and then
invoke your function
from within the loop() function.
Initial functions
// runs once when program starts (see setup code)
void setup() {
Serial.begin(9600); //enables serial output for debugging
FastLED.addLeds<WS2811, DATA_PIN, RGB>(leds, NUM_LEDS).setCorrection(TypicalLEDStrip);
FastLED.setBrightness(BRIGHTNESS);
}
// loops continuously (see loop code)
void loop()
{
blink_light_0_example(); // example that blinks LED 0
}
//blink the light closest to the controller
void blink_light_0_example() {
leds[0]=CRGB::White; // Sets leds array element 0 to a color name (e.g. White)
FastLED.delay(1000); // shows LEDs & pauses for the specified number of milliseconds
leds[0].setRGB(0,0,0); // Sets leds array element 0 to a RGB color (e.g. black)
FastLED.delay(1000); // shows LEDs & pauses for the specified number of milliseconds
}
There are couple of ways in the FastLED library to set an LED's color
Named color leds[#] = CRGB::Aqua;
AliceBlue=F0F8FF Amethyst=9966CC AntiqueWhite=FAEBD7 Aqua=00FFFF Aquamarine=7FFFD4 Azure=F0FFFF Beige=F5F5DC Bisque=FFE4C4 Black=000000 BlanchedAlmond=FFEBCD Blue=0000FF BlueViolet=8A2BE2 Brown=A52A2A BurlyWood=DEB887 CadetBlue=5F9EA0 Chartreuse=7FFF00 Chocolate=D2691E Coral=FF7F50 CornflowerBlue=6495ED Cornsilk=FFF8DC Crimson=DC143C Cyan=00FFFF DarkBlue=00008B DarkCyan=008B8B DarkGoldenrod=B8860B DarkGray=A9A9A9 DarkGrey=A9A9A9 DarkGreen=006400 DarkKhaki=BDB76B DarkMagenta=8B008B | DarkOliveGreen=556B2F DarkOrange=FF8C00 DarkOrchid=9932CC DarkRed=8B0000 DarkSalmon=E9967A DarkSeaGreen=8FBC8F DarkSlateBlue=483D8B DarkSlateGray=2F4F4F DarkSlateGrey=2F4F4F DarkTurquoise=00CED1 DarkViolet=9400D3 DeepPink=FF1493 DeepSkyBlue=00BFFF DimGray=696969 DimGrey=696969 DodgerBlue=1E90FF FireBrick=B22222 FloralWhite=FFFAF0 ForestGreen=228B22 Fuchsia=FF00FF Gainsboro=DCDCDC GhostWhite=F8F8FF Gold=FFD700 Goldenrod=DAA520 Gray=808080 Grey=808080 Green=008000 GreenYellow=ADFF2F Honeydew=F0FFF0 HotPink=FF69B4 | IndianRed=CD5C5C Indigo=4B0082 Ivory=FFFFF0 Khaki=F0E68C Lavender=E6E6FA LavenderBlush=FFF0F5 LawnGreen=7CFC00 LemonChiffon=FFFACD LightBlue=ADD8E6 LightCoral=F08080 LightCyan=E0FFFF LightGoldenrodYellow=FAFAD2 LightGreen=90EE90 LightGrey=D3D3D3 LightPink=FFB6C1 LightSalmon=FFA07A LightSeaGreen=20B2AA LightSkyBlue=87CEFA LightSlateGray=778899 LightSlateGrey=778899 LightSteelBlue=B0C4DE LightYellow=FFFFE0 Lime=00FF00 LimeGreen=32CD32 Linen=FAF0E6 Magenta=FF00FF Maroon=800000 MediumAquamarine=66CDAA MediumBlue=0000CD MediumOrchid=BA55D3 | MediumPurple=9370DB MediumSeaGreen=3CB371 MediumSlateBlue=7B68EE MediumSpringGreen=00FA9A MediumTurquoise=48D1CC MediumVioletRed=C71585 MidnightBlue=191970 MintCream=F5FFFA MistyRose=FFE4E1 Moccasin=FFE4B5 NavajoWhite=FFDEAD Navy=000080 OldLace=FDF5E6 Olive=808000 OliveDrab=6B8E23 Orange=FFA500 OrangeRed=FF4500 Orchid=DA70D6 PaleGoldenrod=EEE8AA PaleGreen=98FB98 PaleTurquoise=AFEEEE PaleVioletRed=DB7093 PapayaWhip=FFEFD5 PeachPuff=FFDAB9 Peru=CD853F Pink=FFC0CB Plaid=CC5533 Plum=DDA0DD PowderBlue=B0E0E6 Purple=800080 | Red=FF0000 RosyBrown=BC8F8F RoyalBlue=4169E1 SaddleBrown=8B4513 Salmon=FA8072 SandyBrown=F4A460 SeaGreen=2E8B57 Seashell=FFF5EE Sienna=A0522D Silver=C0C0C0 SkyBlue=87CEEB SlateBlue=6A5ACD SlateGray=708090 SlateGrey=708090 Snow=FFFAFA SpringGreen=00FF7F SteelBlue=4682B4 Tan=D2B48C Teal=008080 Thistle=D8BFD8 Tomato=FF6347 Turquoise=40E0D0 Violet=EE82EE Wheat=F5DEB3 White=FFFFFF WhiteSmoke=F5F5F5 Yellow=FFFF00 YellowGreen=9ACD32 |
RGB
color value
leds[i].r = 255; �leds[i].g = 68; �leds[i].b = 221;
leds[i].setRGB( 255, 68, 221);
or in hexadecimal
leds[i] = 0xFF44DD;
CHSV(Hue,Saturation,Value) color
leds[i] = CHSV(224, 187, 255);
HUE = 0-255 to specifies the color (see picture below)
Saturation = 0-255
Value (aka brightness) = 0-255 (0=dark, 255=full)
The leds[] array stores CRGB objects.
The CHSV() function converts HSV values to a CRGB object.
CHSV(Hue,Saturation,Value) color
void loop() {
int hue = 50;
for (int i=0; i<50; i=i+1) {
leds[i] = CHSV( hue, 255, 255);
}
FastLED.delay(100);
}
after the other (slow or fast) first
one color then another.
Try out the WOKWi Simulator - instructions
4 stacks of 6 each
2 on bottom
4 on top
store neatly in even/odd order