1 of 36

LED LIGHTS

Getting Started

2 of 36

0:00 - 1:51

27:33 - 29:19

3 of 36

Run the Arduino IDE Program

Good idea to right click on it and

Pin to Taskbar

4 of 36

Preferences

5 of 36

Plug In

  • Plug the USB cable into the Ardunio and the computer
  • Wait a minute for USB drivers to load

6 of 36

Setup 1

make sure Arduino Uno is selected in Tools -> Board ...

7 of 36

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

8 of 36

Verify Setup

at bottom right it should now indicate that your Arduino Uno is connected to the COM port

9 of 36

Blink

load the Blink program into the arduino editor

File -> Examples -> 01. Basics -> Blink

10 of 36

// 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

11 of 36

Blink

upload the Blink program to the Arduino by clicking on

12 of 36

Blink a LED on the Arduino

one small LED light on the Arduino should now be blinking

13 of 36

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 documentation

14 of 36

FastLED library

Download the FASTLED-3.5.0.zip file (released Jan 2022)

15 of 36

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

16 of 36

FastLED library

verify that the FastLED library is installed

Do NOT click on FastLED, just make sure it is there

17 of 36

Connecting LED Lights

5V

GND

2

connecting the three wires from the lights to the Arduino

18 of 36

Connecting LED Lights

  • connect yellow

wire to pin 2

(2) connect red

wire to 5V pin

(3) connect black

wire to GND pin

19 of 36

File -> New

Replace the default program in the window with the program on the next slide.

50 LED Sample Code

20 of 36

#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.

21 of 36

#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

22 of 36

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

23 of 36

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

24 of 36

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."

25 of 36

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);

26 of 36

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

27 of 36

Initial functions

You can put your code into

your own function

and then

invoke your function

from within the loop() function.

28 of 36

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

}

29 of 36

There are couple of ways in the FastLED library to set an LED's color

30 of 36

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

31 of 36

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;

32 of 36

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.

33 of 36

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);

}

34 of 36

  • Change the color of the first LED (i.e. leds[0])

  • Change the color of other LEDs (the light strand has 50 LEDs, try numbers between 0 to 49)
  • Change the color of all the LEDs
  • Change the color of all the even LEDs to one color and the odd LEDs to another color
  • Change one LED at a time one

after the other (slow or fast) first

one color then another.

A

Arduino reference

(Structure -> Control structure -> for)

C++ for loop

35 of 36

Try out the WOKWi Simulator - instructions

36 of 36

4 stacks of 6 each

2 on bottom

4 on top

store neatly in even/odd order