User Tools

Site Tools


tutorials:products:pixel20mm:index.html

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revision Previous revision
Next revision
Previous revision
tutorials:products:pixel20mm:index.html [2012/01/26 21:12]
pburgess
tutorials:products:pixel20mm:index.html [2016/01/28 18:05] (current)
Line 1: Line 1:
-==== LED full color (RGB) Pixels! ​ ====+==== LED full color (RGB) Pixels! ====
  
-RGB Pixels are digitally-controllable lights you can set to any color, or animate. Each LED module ​and controller chip is molded into a '​dot'​ of silicone. The dots are waterproof and rugged. There are four flanges ​molded in so  that you can '​push'​ them into a drill hole in thin sheet materualThey're typically used to make outdoor signs.+RGB Pixels are digitally-controllable lights you can set to any color, or animate. Each pixel contains an RGB LED and controller chip molded into a '​dot'​ of silicone, with flanges so they can be pushed ​into holes in thin sheet materialThe dots are waterproof and rugged — they're typically used to make outdoor signs.
  
-We have **three** types of RGB pixels, 12mm round, 20mm round and 36mm square. They have the same controller chip and use the same power but the LED type, number and shape differs.+**Basic stats**
  
-**Basic stats!** \\+  ​20mm diameter round waterproof pixels 
 +  ​Approximately 3 inches (75mm) apart on 4-pin strand 
 +  ​5 Volts DC, 60 milliamps max per pixel (all LEDs on, full white) 
 +  ​LPD6803 LED driver chip provides 15-bit color: [[http://​www.adafruit.com/​datasheets/​LPD6803.pdf|Datasheet]] 
 +  * 2-pin SPI-like protocol — easy for Arduino and other microcontrollers
  
-  *20mm or 12mm diameter round or 36mm square waterproof pixels +[[http://​www.adafruit.com/​products/307|You can pick up RGB pixels in strands of 20 from the Adafruit shop]].
-  *Approx 3" apart on 4 pin strand +
-  *20mm pixels are LPD6803 type only. 12mm may be either WS2801/​LPD6803 (we switched to the superior WS2801 pixels mid July 2011). 36mm square are WS2801 type. +
-  *LPD6803 pixels have 15 bit color (5 bits per LED, 3 LEDs per pixel) +
-  *WS2801 pixels have 24 bit color (8 bits per LED, 3 LEDs per pixel) +
-  *Round pixels are **5V** power, 60mA maximum per pixel (all LEDs on, full white) +
-  *Square pixels are **12V** power, 120mA maximum per pixel (all LEDs on, full white) +
-  *2-pin SPI-like protocol +
-  *[[http://​www.adafruit.com/​datasheets/LPD6803.pdf|LPD6803 Datasheet]] and [[http://​www.adafruit.com/​datasheets/​WS2801.pdf|WS2801 Datasheet]]+
  
-[[http://​www.adafruit.com/​index.php?​main_page=index&​cPath=37|You can pick up RGB pixels in either size in strands of 20 or 25 at the Adafruit shop]].  +Here is a video showing ​our similar ​12mm dots running a test pattern:
- +
-Here is a basic video showing ​some 12mm dots running a test pattern.+
  
 {{flickrvid>​5262163094}} {{flickrvid>​5262163094}}
  
-Here is a video showing the 36mm square pixels:+==== Project Ideas ====
  
-{{flickrvid>​6761457165}}+These pixels could be used for stuff like…
  
-==== 20mm Pixels ​ ==== +LED coffee tables (this one is 'hand made' but you could skip the wiring/​drivers part and just use a long strand of our LED pixels now):
-[[http://​www.ladyada.net/​images/​rgbpixels/​20mmledpixel.jpg|{{ ​ http://​www.ladyada.net/​images/​rgbpixels/​20mmledpixel_t.jpg?​nolink&​500x385 ​ |}}]] +
- +
-The larger pixels are about 20mm in diameter (the flanges are a little more) so if you want to drill a hole for these to fit into, make it 20mm in diameter. These pixels use a "​5050"​ clear RGB LED and are brighter than the 12mm pixels. However, the trade off is that they are not diffused which means that the color mixing is not as nice: close up you can see the different colors. +
- +
-They draw a maximum of 60mA per pixel: 3 x 20mA per LED and there are three LEDs in each pixel. +
- +
-==== 12mm Pixels ​ ==== +
-[[http://​www.ladyada.net/​images/​rgbpixels/​12mmledpixel.jpg|{{ ​ http://​www.ladyada.net/​images/​rgbpixels/​12mmledpixel_t.jpg?​nolink&​500x333 ​ |}}]] +
- +
-The 12mm pixels are smaller than the 20mm, needing only a 12mm hole but they are '​longer'​ since the PCB sticks out back. These pixels use an 8mm diffused RGB LED and so are not as bright as the 20mm pixels **but** the diffused pixels color mix nicer. +
- +
-They draw a maximum of 60mA per pixel: 3 x 20mA per LED and there are three LEDs in each pixel. +
- +
-==== 36mm Square Pixels ==== +
-{{ :​tutorials:​products:​rgbledpixel:​id683_lrg.jpg?​500 |}} +
- +
-The 36mm square pixels are the biggest and brightest. They have 4 LEDs total and come in a flat metal square '​plate'​ that is flooded with epoxy. They require 12VDC power and can draw up to 120mA per pixel (there are two sets of two RGB LEDs connected in parallel for two 60mA draw from 12VDC). +
- +
-==== Pixel spacing ​ ==== +
- +
-The LED pixels are spaced out on strands of ribbon cable, the spacing is a little different between the 12mm (3.5" between pixels) and 20mm (2.5"​). If you need them further spaced, you can extend the ribbon by soldering 4 wires to '​extend'​ the pixels. +
- +
-[[http://​www.ladyada.net/​images/​rgbpixels/​12mmledpixelclose.jpg|{{ ​ http://​www.ladyada.net/​images/​rgbpixels/​12mmledpixelclose_t.jpg?​nolink&​500x333 ​ |}}]] +
- +
-[[http://​www.ladyada.net/​images/​rgbpixels/​20mmledpixelside.jpg|{{ ​ http://​www.ladyada.net/​images/​rgbpixels/​20mmledpixelside_t.jpg?​nolink&​500x385 ​ |}}]] +
- +
-Note that the wires are actually '​split'​ the 4 wires coming are not the same as the ones going out (see the next section for more details) +
- +
-==== Ideas  ==== +
- +
-These pixels could be used for stuff like... +
- +
-LED coffee tables (this one is 'hand made' but you could skip the wiring/​drivers part)+
  
 {{youtube>​Tj1j1-dIX6k}} {{youtube>​Tj1j1-dIX6k}}
  
-A 'strand' ​of LEDs like a digital LED strip but easier to control!+trippy ​'light bar':
  
 {{vimeo>​16297109}} {{vimeo>​16297109}}
  
-A '​ball'​ of LEDs: +Signs or displays:
- +
-{{vimeo>​16303734}} +
- +
-A sign or display+
  
 {{youtube>​EkrZbBEqcjo}} {{youtube>​EkrZbBEqcjo}}
  
-A matrix or wall could also be done+==== Overview ====
  
-==== Driver chip  ====+These pixels use a "​5050"​ clear RGB LED and are brighter than our 12mm pixels. The trade off is that they are not diffused, so the color mixing is not as nice; close up, you can see the three separate LEDs. At 5 Volts, they draw a maximum of 60 mA per pixel: 20mA each for red, green and blue.
  
-The pixels have a small microchip inside each silicone dot. In these, the microchip is the WS2801 or LDP6803, chips basically custom designed for this purpose. These chips are very simple - all they does is shift brightness data in from one pin and out the other. The LPD6803 uses 16 bits (15 bits of color data, one start bit) the WS2801 uses 24 bits of color data.+{{ :​tutorials:​products:​pixel20mm:​20mmpixels.jpg?​nolink&​ |}}
  
-So if you want to write data to 10 LEDs in strip, you would shift out 10 * 16 or 24 bits (depending on the chip) and the first data out would be the last LED in the strand.+The LED pixels are spaced along strand of ribbon cablewith about 3 inches or 75mm between pixels. If additional distance is needed ​you can cut the ribbon cable and solder 4 wires to extend ​the gap to the desired length.
  
-There are some differences between the two chips so lets review them+{{ :​tutorials:​products:​pixel20mm:​20mmwires.jpg?​nolink&​ |}}
  
-=== LPD6803 ​===+==== Powering 20mm Pixels ====
  
-This chip can handle PWMing the color brightness, all it needs is a 'pixel PWM clock' which tells it how fast to PWMThe faster the PWM, the smoother the color, but the PWM has to travel all the way down the strand so it can't be too fast or it'll snag the chips.+An important part of running a lot of LEDs is to keep track of power usageIndividual LEDs don't get very hot or use tons of power, but they add up fast!
  
-One strange thing to note, is that the PWM clock is the same as the data clockThis is nice because it saves pin but it means that when we want to send data to the strand ​we have to time it so that its sent as the PWM is '​resetting' ​the counter so that we dont get '​flicker'​ effects ​of updating ​the register while its updating which could cause the register to stay on longer than we want.+Each single 20mm RGB LED pixel can draw up to 60mA from a 5V supplyThat means a strand ​of 20 can use up to 1.2 Amps. Of course this is assuming all the LEDs are on. If you keep most of the LEDs off (by color swirling or patterns) ​the power usage can be 1/3 this or less.
  
-This is OK but little annoying because you always have to be sending it PWM clock dataOn an arduino this takes timer interrupt and bunch of CPU speed+We suggest ​nice switching supply for driving LED pixels: either a [[http://​www.adafruit.com/​products/​276|5 Volt 2 Amp supply]] for strand or two, or our [[http://​www.adafruit.com/​products/​658|5 Volt 10 Amp supply]] for larger installations. For really massive projects, ​[[http://​www.instructables.com/​pages/​search/​search.jsp?​ie=ISO-8859-1&​q=ATX|slightly modified ATX computer power supply]] can provide 30 Amps to power upwards ​of 500 pixels!
  
-=== WS2801 ===+**IMPORTANT:​ Never, //never// connect more than 5 Volts to the pixels! This will permanently damage them!**
  
-In contrast, the WS2801 is more advancedNot only does it have 24 bit color instead of 15 (more colors!but it has **built in PWM clock** so that you can set the LED pixel colors and then 'let go' and leave the chip to run the LEDs on its own. This uses a lot less CPU clock cycles and doesn'​t require an interrupt.+As shown laterconnect ground to both your power supply and microcontroller. Then connect ​the 5V pin to the power supplyA large capacitor ​(1000uF or sobetween 5V and ground is nice addition ​to keep ripple down.
  
-Unfortunately we could not find 20mm pixels with WS2801 chips, but we're still looking!+==== Driver Chip ====
  
-==== Powering 12mm/20mm pixels ​ ====+Each pixel contains a small microchip within the silicone dot. The LPD6803 LED driver chip is custom designed for this purpose. These chips are very simple to communicate with — all they do is shift color data in from one pin and out another. To issue data from a microcontroller such as an Arduino, one "​shifts out" 16 bits of color information. To write data to 10 LEDs, you would issue 160 bits (10 * 16). Following the data, 32 zero bits will "​latch"​ the data and show the new LED colors.
  
-An important part of running a lot of LEDs is to keep track of power usage. LEDs don't get very hot or use tons of power, but they add up fast!+This chip can handle PWM for controlling color brightness, all it needs is 'pixel PWM clock' which sets the PWM speed. The faster the clockthe smoother the color…but this signal has to travel all the way down the strand, so it can't be too fast or it'll snag the chips.
  
-Each single RGB LED pixel (such as the 12mm or 20mm LED rubber pixels) can draw up to 60mA from a 5V supply. That means a strand of 20 can use up to 1.2 Amps, a strand of 25 can use up to 1.5A. Of course this is assuming all the LEDs are on. If you keep most of the LEDs off (by color swirling or patterns) the power usage can be a 1/3 or less. +An interesting point is that the PWM clock is the same as the data clockThis is nice in that it saves pin, but does mean that data must be carefully synchronized ​to the PWM counter in order to avoid unsightly flickerThis is okay but little annoying because ​the PWM clock must be continuously issued, ​and on the Arduino ​this requires ​timer interrupt and costs fair chunk of CPU performance.
- +
-We suggest a nice switching supply for driving LED dots, [[http://​www.adafruit.com/​products/​276| either ​2 Amp 5V supply ]] for a strand or twoor [[http://​www.instructables.com/​pages/​search/​search.jsp?​ie=ISO-8859-1&​q=ATX|a slightly modified ATX power supply (you'​ll need to connect the green power line to ground ​but you do not need the '​loading'​ resistor]]) which can provide 30 Amps to power 500 or more pixels (yow!) +
- +
-As shown below, connect ground to both your supply and logic microcontroller. Then connect ​the 5V pin to the power supplyA large capacitor (1000uF or so) is a nice addition to keep ripple down. +
- +
-==== Powering 36mm pixels ​ ==== +
- +
-The 36mm square pixels are beefier than the 12mm/20mm ones and can draw up to 120mA from a 12V supply. That means a strand of 20 can use up to **2.4** Amps. Of course this is assuming all the LEDs are on. If you keep most of the LEDs off (by color swirling or patterns) the power usage can be a 1/3 or less. +
- +
-We suggest a nice switching supply for driving LED dots, [[https://​www.adafruit.com/​products/​352| such as this 12V 5Amp switching supply ]] for strand or two, or [[http://​www.instructables.com/​pages/​search/​search.jsp?​ie=ISO-8859-1&​q=ATX|slightly modified ATX power supply (you'​ll need to connect the green power line to ground but you do not need the '​loading'​ resistor]]) which can provide 10 Amps or more depending on the make. +
- +
-Since the 36mm pixels are powered by 12V but use 3-5V signalling, you'll want to make sure you don't accidentally connect the 12V to your microcontroller! For that reason, the power lines are separated out. Use something like a [[https://​www.adafruit.com/​products/​368|2.1mm DC terminal block adapter]] so that you can plug a 12VDC adapter directly in. +
- +
-{{ :​tutorials:​products:​rgbledpixel:​36mmpixelterminal.jpg?​500 |}} +
- +
-The wires on the 3-JST SM connector are then connected to your microcontroller:​ black is ground, yellow is data and green is clock.+
  
 ==== Wiring ​ ==== ==== Wiring ​ ====
  
-The nice thing about these pixels is that they are digitally controlled. That is, even though there are only two data lines (clock/data inputs), you can put as many pixels as you'd like in a row and each one is controllable.+The great thing about these pixels is that they'​re ​digitally controlled…that ​is, even though there are only two control ​lines (data and clock inputs), you can put as many pixels as you'd like in a single long strand, yet each one remains independently ​controllable.
  
-It is important to note that even though ​it looks like the 4-conductor ribbon is continuous, it isn't! The ground and 5V lines are shared ​but the two data **input** pins go to a microcontroller ​and the other side has two data **output**s.+Though ​it looks like the 4-conductor ribbon ​cable is continuous, ​//it isn't!// The ground and 5V lines pass through from one pixel to the next, but the two data control lines are different on the input and output sides. The input side goes to the LED driver chip, which then drives its own output ​to the next pixel in the strand.
  
-[[http://​www.ladyada.net/​images/​rgbpixels/​20mmledpixeltop.jpg|{{  http://​www.ladyada.net/​images/​rgbpixels/​20mmledpixeltop_t.jpg?​nolink&​500x199  ​|}}]]+{{ :tutorials:​products:​pixel20mm:​20mminput.jpg?​nolink&​ |}}
  
-When connecting to a microcontroller make sure you are connecting the **input** pins to the microcontroller! Best way to tell is to look at the dots and find the arrow. In the large dots above, the arrow is in the top right corner. The inputs are on the left and the signal passes to the right. If you want to connect ​multiple strands together, make sure input goes to output.+When connecting ​these pixels ​to a microcontrollermake sure you'​re ​connecting ​to the strand'​s ​**input** pins! Best way to distinguish the correct end is to examine ​the dots to find an arrow symbol. In the image above, the arrow is in the top right corner. The inputs are on the left and the signal passes to the right, following the direction of the arrow. If connecting ​multiple strands together, make sure the output of one strand ​goes to the input of the next.
  
-Wiring is pretty easy since there are only 4 wires. The only important thing is that unless you are sure you will be using only a few of the LEDs at a time, you should not try to power the strip from the 5V on the Arduino. The Arduino is only mean to drive about 500mA of current, and as we saw earlier, a strand can take 1000mA or more if on! For that reason, we suggest powering with an external regulated 5V supply.+Wiring is pretty easy since there are only 4 wires. The only important thing is that unless you are sure you will be using only a few of the LEDs at a time, you should not try to power the strip from the 5V on the Arduino. The Arduino is only meant to drive about 500mA of current, and as we saw earlier, a strand can take 1000mA or more if on! For that reason, we suggest powering with an external regulated 5V supply.
  
-For **LPD6803** Pixels, use this diagram with Red going to +5Green going to digital 3, Yellow going to digital 2 and Blue going to Ground**WS2801 wire colors will be different, see below!**+Use this diagram with the red wire going to +5V from the power supplygreen (serial clock) ​to Arduino ​digital ​pin 3, yellow (serial data) to digital ​pin 2and blue to both the ground connection on the power supply and any available GND pin on the Arduino.
  
 {{  http://​www.ladyada.net/​images/​rgbpixels/​arduinowiring.gif?​nolink&​576x467 ​ |}} {{  http://​www.ladyada.net/​images/​rgbpixels/​arduinowiring.gif?​nolink&​576x467 ​ |}}
  
-Just make sure to '​share'​ the ground pin, and triple check that you have the voltage polarity right so that ground is 0V and power is 5V. For the arduino library we wrote, you can use any two pins. +Our code can use any two pins, but the examples are written to use pins 2 and 3 as above.
  
-=== Extra special note for WS2801 pixels ​===+==== Download ====
  
-**PLEASE NOTETHE WIRE COLORS SOMETIMES CHANGE FROM BATCH TO BATCH! Do not assume the wire colors are '​logical' ​or the same for each strandDouble check by looking at the first input pixel!**+The Arduino library is heavily based off of [[http://​www.bliptronics.com|bliptronics']] original code, except we library-ized it and trimmed it down.
  
-If you have 12mm pixels you may have newer WS2801 or older LPD6803 pixelsYou should check the pixel to verify what chip is insideThis is pretty easyfor the WS2801's you'll see it written on the PCBYou can also check your kit packaging.+To download the library, [[https://​github.com/​adafruit/​LPD6803-RGB-Pixels|visit ​the repository on GitHub]]. 
 +Click the DOWNLOAD ZIP button near the upper leftextract ​the archive and then rename the uncompressed folder to ''​LPD6803''​. Confirm that this folder contains ​the files ''​LPD6803.cpp''​ and ''​LPD6803.h''​ and the ''​examples''​ folder.
  
-{{:tutorials:​products:​rgbledpixel:​ws2801pixel.jpg?500|}}+Place the LPD6803 folder inside your Arduino ''​Libraries''​ folder. You may need to create this folder if it does not yet exist. In Windows, this would be ''​(home folder)\My Documents\Arduino\Libraries''​ and for Mac or Linux is ''​(home folder)/​Documents/​Arduino/​Libraries''​ [[http://www.ladyada.net/​library/​arduino/​libraries.html|We also have a tutorial on library installation]].
  
-Here you can see the WS2801 written on the PCB. Another really annoying thing is that like we mentioned, the wire colors for the WS2801 pixels can be '​non-intuitive'​. For example the first batch of WS2801 we got had **Data** wire blue, **Clock** wire red, **Ground** wire white, and **5V** wire black. You can determine ​the wiring for sure by holding up the pixel as shown in that photo and noting that the wire order is Data, Clock, Ground, +5V (this is not the same as LPD6803, see the diagram above for LPD6803 wiring!) Sorry about that!+After installing ​the LPD6803 libraryrestart ​the Arduino IDE. You should now be able to access ​the sample code by navigating through menus in this order: File->​Sketchbook->​Libraries->​LPD6803->​strandtest
  
-==== Code!  ====+==== Code! ====
  
-=== LPD6803 pixels ===+The code to drive these dots is fairly simple, except that the PWM pin and the data clock pin are shared, meaning you can't just stick the PWM pin on a hardware timer output because then it's not possible to use it for the data clocking. Instead, the library uses an interrupt that goes off every few milliseconds. If there is data to be updated on the strip, it sends that data. If not, it just pulses pin to keep the PWM going.
  
-The code to drive these dots is fairly simple, except ​that the PWM pin and the data clock pin is shared which means that you can't just stick the PWM pin on a hardware timer output because then its not possible to use it for the data clocking.+**Note ​that the interrupt uses Timer 1, meaning the pin and 10 PWM outputs will not work for servos at the same timeIf you need this capability, please use a '​software servo' library!**
  
-Instead, ​the library ​uses an interrupt that goes off every few milliseconds. If there is data to be updated on the strip, it sends that dataIf not, it just pulses pin to keep the PWM going.+Let's look through the strandtest example code. To use the library ​in an Arduino sketch, you'll first need to globally declare an LPD6803 object to talk to the strip. ​It is invoked with three variables: ​the number of pixels and the data and clock pins:
  
-**Note that the interrupt uses timer 1 which means the pin 9 and 10 PWMs will not 'work' ​for servos, please use a 'software servo' ​library!**+<code C> 
 +int dataPin = 2;  // 'yellow' ​wire 
 +int clockPin = 3; // 'green' ​wire
  
-This code is heavily based off of [[http://​www.bliptronics.com|bliptronics'​]] original code except we library-ized it and trimmed it down. [[https://​github.com/​adafruit/​LPD6803-RGB-Pixels|You can download the library from github]], [[http://​www.ladyada.net/​library/​arduino/​libraries.html|then follow our library installtion procedure.]] +// Set the first parameter ​to the NUMBER of pixels. 20 = 20 pixels in a row
- +
-Once you've rebooted, load up the **strandtest.pde** example sketch, we'll go through the most important parts. +
- +
-First up, you'll need to make an library object to talk to the strip. It is initialized with three variables, the number of pixels and the data/clock pin. You can change these later. +
- +
-<code C> +
-// Set the first variable ​to the NUMBER of pixels. 20 = 20 pixels in a row+
 LPD6803 strip = LPD6803(20, dataPin, clockPin); LPD6803 strip = LPD6803(20, dataPin, clockPin);
 </​code>​ </​code>​
  
-Next we will set up the strip in the **setup()** procedure.+Nextwe initialize ​the strip in the ''​setup()'' ​procedure:
  
 <code C> <code C>
Line 190: Line 127:
 }</​code>​ }</​code>​
  
-**setCPUmax()** configures the timer 1 interrupt that PWM'​s ​the strand. You can change this from 0 to 100, it runs in the background. The '​max'​ is calculated assuming the longest possible timing (when sending data) so its a big pessimistic. 50% should be plenty, you can mess with this to make the strip more or less '​flickery'​ You can change this 'on the fly' so for example set it to 0% just before doing a bunch of Ethernet stuff, then back to 50% later.+''​setCPUmax()'' ​configures the Timer 1 interrupt that drives ​the strand. You can change this from 0 to 100, and it runs in the background. The '​max'​ is calculated assuming the longest possible timing (when sending data) so its a bit pessimistic. 50% should be plenty, you can mess with this to make the strip more or less '​flickery'​ You can change this 'on the fly' so for example set it to 0% just before doing a bunch of Ethernet stuff, then back to 50% later.
  
-**begin() ​**actually starts the interrupt+''​begin()'' ​actually starts the interrupt.
  
-**show()** is what updates ​the strand display. You'll need to call it after setting ​any colors to see the updates. This way you can change the entire strip at time (it takes the same amount of time to change one pixel as it does for an entire strip because the full strip data must be shifted out at once)+''​show()''​ refreshes the displayed colors of the LEDs. You'll need to call ''​show()'' ​after changing ​any pixel colors to see this reflected in the LEDs. This way you can change the entire strip at one time (it takes the same amount of time to change one pixel as it does for an entire stripbecause the full strip data must be issued regardless).
  
-Last, we'll look at an example function, colorWipe. This creates a '​chase'​ that fills the strip up with a color. It is basically a loop that increments through every pixel (which you can conveniently get by **numPixels()** ) and sets the pixel color of that pixel (incremented with **i**) to the color **c**. In this case the color is stored in a 16 bit variable. The strip output is then updated with **show()**. Finally there is some delay (otherwise this would happen instantly)+Last, we'll look at an example function, ​''​colorWipe()''​. This creates a '​chase' ​sequence ​that fills the strip up with a color. It is basically a loop that increments through every pixel (which you can query with the ''​numPixels()''​ function) and sets the color of each (incremented with ''​i''​) to the value passed (''​c''​ — colors are expressed as a 16-bit variable ​type, though only the bottom 15 bits are used). The strip output is then updated with ''​show()''​. Finally there is some delay (otherwise this would happen instantly).
  
-Below that is a little ​helper that takes 8 bit red green and blue and bit-mashes them into a 15 bit color. This means that the '​max' ​value for each color is 31.+Below that is a helper ​function ​that converts a color from separate 5-bit redgreen and blue values ​into a combined ​15-bit value (suitable ​for passing to ''​colorWipe()''​). The brightness range is from 0 (off) to 31 (max brightness).
  
 <code C> <code C>
Line 221: Line 158:
   return( ((unsigned int)g & 0x1F )<<10 | ((unsigned int)b & 0x1F)<<​5 | (unsigned int)r & 0x1F);   return( ((unsigned int)g & 0x1F )<<10 | ((unsigned int)b & 0x1F)<<​5 | (unsigned int)r & 0x1F);
 } }
- 
 </​code>​ </​code>​
  
-For example, in the **loop()** we call colorWipe(Color(31,​ 0, 0), 50) which will fill the strand with only-full-red light, pausing about 50 milliseconds between pixels.+For example, in the ''​loop()''​ function ​we call colorWipe(Color(31,​ 0, 0), 50) which will fill the strand with full-brightness ​red light, pausing about 50 milliseconds between pixels.
  
 <code C> <code C>
Line 230: Line 166:
   colorWipe(Color(0,​ 31, 0), 50);  // green fill   colorWipe(Color(0,​ 31, 0), 50);  // green fill
   colorWipe(Color(0,​ 0, 31), 50);  // blue fill   colorWipe(Color(0,​ 0, 31), 50);  // blue fill
-</​code> ​ 
- 
-=== WS2801 pixels === 
- 
-This code is very similar to the LPD6803 but simpler because we do not need to use the CPU to update the pixel clock constantly. 
- 
-The code to drive these dots is even simpler, you don't need to worry about any timers, use any two pins you'd like! You can use anything that requires timer 1 like the servo libraries. 
- 
-[[https://​github.com/​adafruit/​WS2801-Library|To download, visit the repository on Github.]] Click the DOWNLOADS button in the top right corner, rename the uncompressed folder WS2801. Check that the WS2801 folder contains WS2801.cpp and WS2801.h 
- 
-Place the WS2801 library folder your <​arduinosketchfolder>/​libraries/​ folder. You may need to create the libraries subfolder if its your first library. Restart the IDE. [[http://​www.ladyada.net/​library/​arduino/​libraries.html|We also have a tutorial on library installation]] 
- 
-Once you've rebooted, load up the **WS2801->​strandtest.pde** example sketch, we'll go through the most important parts. 
- 
-First up, you'll need to make an library object to talk to the strip. It is initialized with three variables, the number of pixels and the data/clock pin. You can change these later. 
- 
-<code C> 
-// Set the first variable to the NUMBER of pixels. 25 = 25 pixels in a row 
-WS2801 strip = WS2801(25, dataPin, clockPin); 
 </​code>​ </​code>​
- 
-Next we will set up the strip in the **setup()** procedure. 
- 
-<code C> 
-void setup() { 
-  // Start up the LED counter 
-  strip.begin();​ 
- 
-  // Update the strip, to start they are all '​off'​ 
-  strip.show();​ 
-}</​code>​ 
- 
-**begin()** initializes the library and sets all the pixel colors to off. 
- 
-**show()** is what updates the strand display. You'll need to call it after setting any colors to see the updates. This way you can change the entire strip at a time (it takes the same amount of time to change one pixel as it does for an entire strip because the full strip data must be shifted out at once) 
- 
-Last, we'll look at an example function, colorWipe. This creates a '​chase'​ that fills the strip up with a color. It is basically a loop that increments through every pixel (which you can conveniently get by **numPixels()** ) and sets the pixel color of that pixel (incremented with **i**) to the color **c**. In this case the color is stored in a 32 bit variable but uses only the bottom 24 bits. The strip output is then updated with **show()**. Finally there is some delay (otherwise this would happen instantly) 
- 
-Below that is a little helper that takes 8 bit red green and blue and bit-mashes them into a 24 bit color. This means that the '​max'​ value for each color is 255. 
- 
-<code C> 
-// fill the dots one after the other with said color 
-// good for testing purposes 
-void colorWipe(uint32_t c, uint8_t wait) { 
-  int i; 
-  ​ 
-  for (i=0; i < strip.numPixels();​ i++) { 
-      strip.setPixelColor(i,​ c); 
-      strip.show();​ 
-      delay(wait);​ 
-  } 
-} 
- 
-/* Helper functions */ 
-// Create a 24 bit color value from R,G,B 
-uint32_t Color(byte r, byte g, byte b) 
-{ 
-  uint32_t c; 
-  c = r; 
-  c <<= 8; 
-  c |= g; 
-  c <<= 8; 
-  c |= b; 
-  return c; 
-} 
- 
-</​code>​ 
- 
-For example, in the **loop()** we call colorWipe(Color(255,​ 0, 0), 50) which will fill the strand with only-full-red light, pausing about 50 milliseconds between pixels. 
- 
-<code C> 
-  colorWipe(Color(255,​ 0, 0), 50);  // red fill 
-  colorWipe(Color(0,​ 255, 0), 50);  // green fill 
-  colorWipe(Color(0,​ 0, 255), 50);  // blue fill 
-</​code> ​ 
-==== Download ​ ==== 
-=== LPD8603 library === 
- 
-We have an Arduino lirbary that can be fairly easily ported to any microcontroller with two digital output pins and a interrupt timer. This code is heavily based off of [[http://​www.bliptronics.com|bliptronics'​]] original code except we library-ized it and trimmed it down. 
- 
-[[https://​github.com/​adafruit/​LPD6803-RGB-Pixels|You can download the library from github]], [[http://​www.ladyada.net/​library/​arduino/​libraries.html|then follow our library installation procedure.]] 
- 
-**Dont forget that this library uses an interrupt on timer 1 which means the pin 9 and 10 PWMs will not '​work'​ for servos, please use a '​software servo' library!** 
- 
-=== WS2801 library === 
- 
-[[https://​github.com/​adafruit/​WS2801-Library|To download, visit the repository on Github.]] Click the DOWNLOADS button in the top right corner, rename the uncompressed folder WS2801. Check that the WS2801 folder contains WS2801.cpp and WS2801.h 
- 
-Place the WS2801 library folder your <​arduinosketchfolder>/​libraries/​ folder. You may need to create the libraries subfolder if its your first library. Restart the IDE. [[http://​www.ladyada.net/​library/​arduino/​libraries.html|We also have a tutorial on library installation]] 
/home/ladyada/public_html/wiki/data/attic/tutorials/products/pixel20mm/index.html.1327612339.txt.gz · Last modified: 2016/01/28 18:05 (external edit)