Arduino - LED

Basic blink sketch

/*

Blink


Turns an LED on for ten seconds, print to Serial Console, then off for one second, repeatedly.


Most Arduinos have an on-board LED you can control. LED_BUILTIN is set to

the correct LED pin independent of which board is used.


This example code is in the public domain.


http://www.arduino.cc/en/Tutorial/Blink

*/


// the setup function runs once when you press reset or power the board

void setup() {

// initialize digital pin LED_BUILTIN as an output.

pinMode(LED_BUILTIN, OUTPUT);

Serial.begin (9600);

}


// the loop function runs over and over again forever

void loop() {

digitalWrite(LED_BUILTIN, HIGH); // turn the LED on (HIGH is the voltage level)

delay(10000); // wait for a second

Serial.println("LED off 10");

digitalWrite(LED_BUILTIN, LOW); // turn the LED off by making the voltage LOW

delay(1000); // wait for a second

}

successful upload example

/home/builder/opt/arduino-builder/arduino-builder -compile -core-api-version 10611 -hardware /home/builder/opt/arduino-builder/hardware -hardware /home/builder/.arduino15/packages -tools /home/builder/opt/arduino-builder/tools -tools /home/builder/.arduino15/packages -built-in-libraries /home/builder/opt/libraries/latest -logger humantags -fqbn arduino:avr:leonardo -build-cache /tmp -build-path /tmp/820459761/build -verbose -prefs runtime.tools.arduinoOTA.path=/home/builder/.arduino15/packages/arduino/tools/arduinoOTA/1.3.0 -prefs runtime.tools.avr-gcc.path=/home/builder/.arduino15/packages/arduino/tools/avr-gcc/7.3.0-atmel3.6.1-arduino5 -prefs runtime.tools.avrdude.path=/home/builder/.arduino15/packages/arduino/tools/avrdude/6.3.0-arduino17 -prefs runtime.tools.i586-poky-linux-uclibc.path=/home/builder/.arduino15/packages/Intel/tools/i586-poky-linux-uclibc/1.6.2+1.0 -prefs runtime.tools.sketchUploader.path=/home/builder/.arduino15/packages/Intel/tools/sketchUploader/1.6.2+1.0 -prefs runtime.tools.arc-elf32.path=/home/builder/.arduino15/packages/Intel/tools/arc-elf32/1.6.9+1.0.1 -prefs runtime.tools.arduino101load.path=/home/builder/.arduino15/packages/Intel/tools/arduino101load/2.0.1 -prefs runtime.tools.dfu-util.path=/home/builder/.arduino15/packages/arduino/tools/dfu-util/0.9.0-arduino2 -prefs runtime.tools.nrf5x-cl-tools.path=/home/builder/.arduino15/packages/arduino/tools/nrf5x-cl-tools/9.3.1 -prefs runtime.tools.flashpack.path=/home/builder/.arduino15/packages/Intel/tools/flashpack/2.0.0 -prefs runtime.tools.x86-linux-gcc.path=/home/builder/.arduino15/packages/arduino/tools/x86-linux-gcc/7.2.0 -prefs runtime.tools.linuxuploader.path=/home/builder/.arduino15/packages/arduino/tools/linuxuploader/1.5.1 -prefs runtime.tools.mkspiffs.path=/home/builder/.arduino15/packages/esp8266/tools/mkspiffs/2.5.0-3-20ed2b9 -prefs runtime.tools.xtensa-lx106-elf-gcc.path=/home/builder/.arduino15/packages/esp8266/tools/xtensa-lx106-elf-gcc/2.5.0-3-20ed2b9 -prefs runtime.tools.bossac.path=/home/builder/.arduino15/packages/arduino/tools/bossac/1.9.1-arduino1 -prefs runtime.tools.CMSIS-Atmel.path=/home/builder/.arduino15/packages/arduino/tools/CMSIS-Atmel/1.2.0 -prefs runtime.tools.CMSIS.path=/home/builder/.arduino15/packages/arduino/tools/CMSIS/4.5.0 -prefs runtime.tools.esptool.path=/home/builder/.arduino15/packages/esp8266/tools/esptool/2.5.0-3-20ed2b9 -prefs runtime.tools.arm-linux-gcc.path=/home/builder/.arduino15/packages/arduino/tools/arm-linux-gcc/4.9.3 -prefs runtime.tools.openocd.path=/home/builder/.arduino15/packages/Intel/tools/openocd/0.9.0+0.1 -prefs runtime.tools.arm-none-eabi-gcc.path=/home/builder/.arduino15/packages/arduino/tools/arm-none-eabi-gcc/7-2017q4 -prefs runtime.tools.core2-32-poky-linux.path=/home/builder/.arduino15/packages/Intel/tools/core2-32-poky-linux/1.6.2+1.0 -libraries /tmp/820459761/custom -libraries /tmp/820459761/pinned /tmp/820459761/Blink_102420

Sketch uses 4014 bytes (13%) of program storage space. Maximum is 28672 bytes.

Global variables use 163 bytes (6%) of dynamic memory, leaving 2397 bytes for local variables. Maximum is 2560 bytes.

Programming with: Serial

Restarting in bootloader mode

Get port list before reset

[COM13]

Touching port COM13 at 1200bps

Set DTR off

Wait for the port to disappear

[COM13] -> []

Wait for the port to reappear

[] -> []

[] -> []

[] -> []

[] -> []

[] -> []

[] -> []

[] -> [COM14]

Found upload port: COM14

Flashing with command:C:/Users/btair/.arduino-create/arduino/avrdude/6.3.0-arduino17/bin/avrdude.exe -CC:/Users/btair/.arduino-create/arduino/avrdude/6.3.0-arduino17/etc/avrdude.conf -v -patmega32u4 -cavr109 -PCOM14 -b57600 -D -Uflash:w:C:/Users/btair/AppData/Local/Temp/arduino-create-agent664132142/Blink_102420.hex:i

avrdude: Version 6.3-20190619

Copyright (c) 2000-2005 Brian Dean, http://www.bdmicro.com/

Copyright (c) 2007-2014 Joerg Wunsch

System wide configuration file is "C:/Users/btair/.arduino-create/arduino/avrdude/6.3.0-arduino17/etc/avrdude.conf"

Using Port : COM14

Using Programmer : avr109

Overriding Baud Rate : 57600

AVR Part : ATmega32U4

Chip Erase delay : 9000 us

PAGEL : PD7

BS2 : PA0

RESET disposition : dedicated

RETRY pulse : SCK

serial program mode : yes

parallel program mode : yes

Timeout : 200

StabDelay : 100

CmdexeDelay : 25

SyncLoops : 32

ByteDelay : 0

PollIndex : 3

PollValue : 0x53

Memory Detail :

Block Poll Page Polled

Memory Type Mode Delay Size Indx Paged Size Size #Pages MinW MaxW ReadBack

----------- ---- ----- ----- ---- ------ ------ ---- ------ ----- ----- ---------

eeprom 65 20 4 0 no 1024 4 0 9000 9000 0x00 0x00

flash 65 6 128 0 yes 32768 128 256 4500 4500 0x00 0x00

lfuse 0 0 0 0 no 1 0 0 9000 9000 0x00 0x00

hfuse 0 0 0 0 no 1 0 0 9000 9000 0x00 0x00

efuse 0 0 0 0 no 1 0 0 9000 9000 0x00 0x00

lock 0 0 0 0 no 1 0 0 9000 9000 0x00 0x00

calibration 0 0 0 0 no 1 0 0 0 0 0x00 0x00

signature 0 0 0 0 no 3 0 0 0 0 0x00 0x00

Programmer Type : butterfly

Description : Atmel AppNote AVR109 Boot Loader

Connecting to programmer: .

Found programmer: Id = "CATERIN"; type = S

Software Version = 1.0; No Hardware Version given.

Programmer supports auto addr increment.

Programmer supports buffered memory access with buffersize=128 bytes.

Programmer supports the following devices:

Device code: 0x44

avrdude: devcode selected: 0x44

avrdude: AVR device initialized and ready to accept instructions

Reading | ################################################## | 100% 0.00s

avrdude: Device signature = 0x1e9587 (probably m32u4)

avrdude: safemode: lfuse reads as FF

avrdude: safemode: hfuse reads as D8

avrdude: safemode: efuse reads as FB

avrdude: reading input file "C:/Users/btair/AppData/Local/Temp/arduino-create-agent664132142/Blink_102420.hex"

avrdude: writing flash (4014 bytes):

Writing | ################################################## | 100% 0.30s

avrdude: 4014 bytes of flash written

avrdude: verifying flash memory against C:/Users/btair/AppData/Local/Temp/arduino-create-agent664132142/Blink_102420.hex:

avrdude: load data flash data from input file C:/Users/btair/AppData/Local/Temp/arduino-create-agent664132142/Blink_102420.hex:

avrdude: input file C:/Users/btair/AppData/Local/Temp/arduino-create-agent664132142/Blink_102420.hex contains 4014 bytes

avrdude: reading on-chip flash data:

Reading | ################################################## | 100% 0.03s

avrdude: verifying ...

avrdude: 4014 bytes of flash verified

avrdude: safemode: lfuse reads as FF

avrdude: safemode: hfuse reads as D8

avrdude: safemode: efuse reads as FB

avrdude: safemode: Fuses OK (E:FB, H:D8, L:FF)

avrdude done. Thank you.



initial blinking led sketch

// A basic everyday NeoPixel strip test program.


// NEOPIXEL BEST PRACTICES for most reliable operation:

// - Add 1000 uF CAPACITOR between NeoPixel strip's + and - connections.

// - MINIMIZE WIRING LENGTH between microcontroller board and first pixel.

// - NeoPixel strip's DATA-IN should pass through a 300-500 OHM RESISTOR.

// - AVOID connecting NeoPixels on a LIVE CIRCUIT. If you must, ALWAYS

// connect GROUND (-) first, then +, then data.

// - When using a 3.3V microcontroller with a 5V-powered NeoPixel strip,

// a LOGIC-LEVEL CONVERTER on the data line is STRONGLY RECOMMENDED.

// (Skipping these may work OK on your workbench but can fail in the field)


#include <Adafruit_NeoPixel.h>

#ifdef __AVR__

#include <avr/power.h> // Required for 16 MHz Adafruit Trinket

#endif


// Which pin on the Arduino is connected to the NeoPixels?

// On a Trinket or Gemma we suggest changing this to 1:

#define LED_PIN 6


// How many NeoPixels are attached to the Arduino?

#define LED_COUNT 60


// Declare our NeoPixel strip object:

Adafruit_NeoPixel strip(LED_COUNT, LED_PIN, NEO_GRB + NEO_KHZ800);

// Argument 1 = Number of pixels in NeoPixel strip

// Argument 2 = Arduino pin number (most are valid)

// Argument 3 = Pixel type flags, add together as needed:

// NEO_KHZ800 800 KHz bitstream (most NeoPixel products w/WS2812 LEDs)

// NEO_KHZ400 400 KHz (classic 'v1' (not v2) FLORA pixels, WS2811 drivers)

// NEO_GRB Pixels are wired for GRB bitstream (most NeoPixel products)

// NEO_RGB Pixels are wired for RGB bitstream (v1 FLORA pixels, not v2)

// NEO_RGBW Pixels are wired for RGBW bitstream (NeoPixel RGBW products)



// setup() function -- runs once at startup --------------------------------


void setup() {

// These lines are specifically to support the Adafruit Trinket 5V 16 MHz.

// Any other board, you can remove this part (but no harm leaving it):

#if defined(__AVR_ATtiny85__) && (F_CPU == 16000000)

clock_prescale_set(clock_div_1);

#endif

// END of Trinket-specific code.


strip.begin(); // INITIALIZE NeoPixel strip object (REQUIRED)

strip.show(); // Turn OFF all pixels ASAP

strip.setBrightness(50); // Set BRIGHTNESS to about 1/5 (max = 255)

Serial.begin (9600);

}



// loop() function -- runs repeatedly as long as board is on ---------------


void loop() {

// Fill along the length of the strip in various colors...

Serial.println("Starting Now");

colorWipe(strip.Color(255, 0, 0), 50); // Red

colorWipe(strip.Color( 0, 255, 0), 50); // Green

colorWipe(strip.Color( 0, 0, 255), 50); // Blue


// Do a theater marquee effect in various colors...

theaterChase(strip.Color(127, 127, 127), 50); // White, half brightness

theaterChase(strip.Color(127, 0, 0), 50); // Red, half brightness

theaterChase(strip.Color( 0, 0, 127), 50); // Blue, half brightness


rainbow(10); // Flowing rainbow cycle along the whole strip

theaterChaseRainbow(50); // Rainbow-enhanced theaterChase variant

}



// Some functions of our own for creating animated effects -----------------


// Fill strip pixels one after another with a color. Strip is NOT cleared

// first; anything there will be covered pixel by pixel. Pass in color

// (as a single 'packed' 32-bit value, which you can get by calling

// strip.Color(red, green, blue) as shown in the loop() function above),

// and a delay time (in milliseconds) between pixels.

void colorWipe(uint32_t color, int wait) {

for(int i=0; i<strip.numPixels(); i++) { // For each pixel in strip...

strip.setPixelColor(i, color); // Set pixel's color (in RAM)

strip.show(); // Update strip to match

delay(wait); // Pause for a moment

}

}


// Theater-marquee-style chasing lights. Pass in a color (32-bit value,

// a la strip.Color(r,g,b) as mentioned above), and a delay time (in ms)

// between frames.

void theaterChase(uint32_t color, int wait) {

for(int a=0; a<10; a++) { // Repeat 10 times...

for(int b=0; b<3; b++) { // 'b' counts from 0 to 2...

strip.clear(); // Set all pixels in RAM to 0 (off)

// 'c' counts up from 'b' to end of strip in steps of 3...

for(int c=b; c<strip.numPixels(); c += 3) {

strip.setPixelColor(c, color); // Set pixel 'c' to value 'color'

}

strip.show(); // Update strip with new contents

delay(wait); // Pause for a moment

}

}

}


// Rainbow cycle along whole strip. Pass delay time (in ms) between frames.

void rainbow(int wait) {

// Hue of first pixel runs 5 complete loops through the color wheel.

// Color wheel has a range of 65536 but it's OK if we roll over, so

// just count from 0 to 5*65536. Adding 256 to firstPixelHue each time

// means we'll make 5*65536/256 = 1280 passes through this outer loop:

for(long firstPixelHue = 0; firstPixelHue < 5*65536; firstPixelHue += 256) {

for(int i=0; i<strip.numPixels(); i++) { // For each pixel in strip...

// Offset pixel hue by an amount to make one full revolution of the

// color wheel (range of 65536) along the length of the strip

// (strip.numPixels() steps):

int pixelHue = firstPixelHue + (i * 65536L / strip.numPixels());

// strip.ColorHSV() can take 1 or 3 arguments: a hue (0 to 65535) or

// optionally add saturation and value (brightness) (each 0 to 255).

// Here we're using just the single-argument hue variant. The result

// is passed through strip.gamma32() to provide 'truer' colors

// before assigning to each pixel:

strip.setPixelColor(i, strip.gamma32(strip.ColorHSV(pixelHue)));

}

strip.show(); // Update strip with new contents

delay(wait); // Pause for a moment

}

}


// Rainbow-enhanced theater marquee. Pass delay time (in ms) between frames.

void theaterChaseRainbow(int wait) {

int firstPixelHue = 0; // First pixel starts at red (hue 0)

for(int a=0; a<30; a++) { // Repeat 30 times...

for(int b=0; b<3; b++) { // 'b' counts from 0 to 2...

strip.clear(); // Set all pixels in RAM to 0 (off)

// 'c' counts up from 'b' to end of strip in increments of 3...

for(int c=b; c<strip.numPixels(); c += 3) {

// hue of pixel 'c' is offset by an amount to make one full

// revolution of the color wheel (range 65536) along the length

// of the strip (strip.numPixels() steps):

int hue = firstPixelHue + c * 65536L / strip.numPixels();

uint32_t color = strip.gamma32(strip.ColorHSV(hue)); // hue -> RGB

strip.setPixelColor(c, color); // Set pixel 'c' to value 'color'

}

strip.show(); // Update strip with new contents

delay(wait); // Pause for a moment

firstPixelHue += 65536 / 90; // One cycle of color wheel over 90 frames

}

}

}

Difference between WS2801, WS2811 and WS2812

Before we start, we should probably identify the differences between the WS2801, WS2811 and WS2812 based strips. The model numbers WS2801, WS2811 and WS2812 actually refer to different “things”.

The WS2801 and WS2811 are LED driver IC’s (Integrated Circuits).

These IC’s can control up to 3 LEDs, typically Red, Green and Blue. Positioned close together, a viewer will see the mixed color result. The LED are combined into 5050 RGB (Red, Green, Blue) package. The 5050 refers to 50mm by 50mm package.

WS2801 strips needed 4 wires (clock, data, Vcc and Ground), the WS2811/WS2812 strips only needs 3 wires (data, Vcc and Ground). The WS2801 uses a separate clock line, which can be seen as an advantage, whereas the WS2811/WS2812 does not. The WS2811/WS2812 depends on sending data matching a very tight timing.

The WS2812 however is a WS2811 placed inside a 5050 LED package.

A WS2812 is the same package as the 5050 RGB LED, but with an additional WS2811 LED driver IC inside the package. The advantage of the WS2812 is that production of these combo’s in strips is easier and therefor cheaper, and each RGB LED takes much less space on strips.

In the illustration to the left you can see the difference:

On the left a 5050 RGB LED, on the right a WS2812 which combines a 5050 RGB LED with a WS2811 controller.

Note how the layout of the “silver” tracks are almost identical in both images, yet the black (IC) block and the tiny wires are different (right).


WS2801.pdf

WS2801 LED Driver

WS2811.pdf

WS2811 LED Driver

LA-5050RGB-A+.pdf

SMD5050 LED

WS2812.pdf