Hi there!
This is not really a 'somethings broke, how do I fix it' type question, but I couldn't really find a forum to fit it in.
But I thought maybe it might be the best place to start...
I have an idea involving a trinket and an LED-strip or pixel-strand.
(I have the 25pixel bullet-type WS2801 that I would like to use (if possible), but I have others and can get different ones if needed.)
I want to be able to make a shape with the string/strand, and 'chase' the lights in a specific direction...
A circle for example...I want to control the lights so that they are all off, then, starting at the bottom, they light up in sequence up the sides of the circle.
Another example would be the outline of an 'arrow' made with a single led-strip/strand...
If you want it to light up from the back of the arrow and 'chase' toward the point..you might have to light up the 2 ends first and then proceed lighting the leds next to them in sequence meeting somewhere toward the middle. (or exactly in the middle if your timing is right and your 'arrow' is 'perfect')
1) is this possible with a single Trinket and a single led strip/strand?
It might seem easier to do with 2 strands (1 for each half), but that would require extra power, and they might get 'out of sync' over time.
(you could probably use two Trinkets..one having the additional task to act as a 'trigger' for the other and doing some timing tricks, but I would rather keep this simple)
2) how does one go about 'mapping/addressing' the individual leds on strip ?
The 12mm diffused bullet WS2801 is supposedly individually digitally addressable.. I looked over the datasheet, but I am pretty new to all of this and very little of it makes sense to me yet...gimme software..THAT I at least understand a little. hehe
I do have a few UNOs if those are better suited, but since the WS2801 only needs 2 wires, I figured the trinket would be able to handle it and because of its tiny size,
would rather use it.
Thanks for any input!!!
project idea question
Moderators: adafruit_support_bill, adafruit
Please be positive and constructive with your questions and comments.
- adafruit_support_bill
- Posts: 88096
- Joined: Sat Feb 07, 2009 10:11 am
Re: project idea question
[moved to General Project Help]
The choice between a Trinket or something larger depends mostly on the number of pixels and the amount of SRAM in the processor. Plan on 3 bytes per pixel - plus 25% or more for stack and heap overhead. A Trinket can do up to about 100 pixels or so - depending on your code.
The choice between a Trinket or something larger depends mostly on the number of pixels and the amount of SRAM in the processor. Plan on 3 bytes per pixel - plus 25% or more for stack and heap overhead. A Trinket can do up to about 100 pixels or so - depending on your code.
- copalfreak
- Posts: 33
- Joined: Sun Feb 16, 2014 3:27 pm
Re: project idea question
The WS2801 I purchased from Adafruit only has 25 pixels on it, and since the LEDs on it are supposed to be individually digitally addressable, can I assume then, that the answer to 'is this possible with a single strand and a single trinket' is 'yes'?adafruit_support_bill wrote:[moved to General Project Help]
The choice between a Trinket or something larger depends mostly on the number of pixels and the amount of SRAM in the processor. Plan on 3 bytes per pixel - plus 25% or more for stack and heap overhead. A Trinket can do up to about 100 pixels or so - depending on your code.
If so, where can I find info on how to control the WS2801 (besides the datasheet), so that I can try to light up both ends at once and 'chase' them toward the middle for the effect I am looking for?
Basically, how do I pick a single LED from somewhere on the strand, say third from the end, and light ONLY that one and choose the color (from within a Trinket)?
That is the kind of info I am looking for..Once I have that info, i think I can figure out the rest.
Thanks for the speedy response!
- adafruit_support_bill
- Posts: 88096
- Joined: Sat Feb 07, 2009 10:11 am
Re: project idea question
We have a tutorial and a library for these. Trinket support is still listed as 'experimental' at this point.
https://learn.adafruit.com/12mm-led-pixels/overview
https://github.com/adafruit/Adafruit-WS2801-Library
https://learn.adafruit.com/12mm-led-pixels/overview
https://github.com/adafruit/Adafruit-WS2801-Library
- copalfreak
- Posts: 33
- Joined: Sun Feb 16, 2014 3:27 pm
Re: project idea question
Thank you for the links, but within those pages I could not find how to address a specific pixel.
I saw a loop in the example code as part of a colorWipe function..
..but what if I want to start on a specific pixel?
If I want to light up JUST the 3rd pixel, (assuming they start at 0) could I just do this?
or do I need to
Thanks!
I saw a loop in the example code as part of a colorWipe function..
Code: Select all
...
for (i=0; i < strip.numPixels(); i++) {
strip.setPixelColor(i, c);
...
If I want to light up JUST the 3rd pixel, (assuming they start at 0) could I just do this?
Code: Select all
strip.numPixels(2, 255); # set 3rd pixel to white
strip.show();
Code: Select all
totalPixelCount = strip.numPixels() ;
myPixel = (totalPixelCount - 3);
for (i=0; i < strip.numPixels(); i++) {
if (i == myPixel) {
strip.setPixelColor(i, c);
strip.show();
}
}
- adafruit_support_bill
- Posts: 88096
- Joined: Sat Feb 07, 2009 10:11 am
Re: project idea question
To set a pixel color you call setPixelColor().
The first parameter is the pixel. The second parameter is the color.
To specify the color, use the color() function as described in the tutorial: https://learn.adafruit.com/12mm-led-pixels/code
To set the 3rd pixel to white:
The first parameter is the pixel. The second parameter is the color.
To specify the color, use the color() function as described in the tutorial: https://learn.adafruit.com/12mm-led-pixels/code
To set the 3rd pixel to white:
Code: Select all
strip.setPixelColor(3, color(255,255,255));
- copalfreak
- Posts: 33
- Joined: Sun Feb 16, 2014 3:27 pm
Re: project idea question
Awesome! Thanks!
The code is not perfect, but I hope this is useful for somebody ...It certainly helped me understand a little more about it..
Pro Trinket + Adafruit WS2801 library + single strand of 12mm diffused "bullet" LED Pixels (WS8021)
Pro Trinket:
https://www.adafruit.com/product/2000
LEDs:
https://www.adafruit.com/products/322
IDE:
I used Arduino IDE 1.0.5 (trinket-ized) from "The Fast Way" section here :
https://learn.adafruit.com/introducing- ... rduino-ide
AdaFruit WS2801 LED Pixel Library:
https://learn.adafruit.com/12mm-led-pix ... w=all#code
DOCS:
https://learn.adafruit.com/12mm-led-pixels?view=all
code:
There are a bunch of ways to do this..probably more efficient..I am just learning and this was a good test.
The code is not perfect, but I hope this is useful for somebody ...It certainly helped me understand a little more about it..
Pro Trinket + Adafruit WS2801 library + single strand of 12mm diffused "bullet" LED Pixels (WS8021)
Pro Trinket:
https://www.adafruit.com/product/2000
LEDs:
https://www.adafruit.com/products/322
IDE:
I used Arduino IDE 1.0.5 (trinket-ized) from "The Fast Way" section here :
https://learn.adafruit.com/introducing- ... rduino-ide
AdaFruit WS2801 LED Pixel Library:
https://learn.adafruit.com/12mm-led-pix ... w=all#code
DOCS:
https://learn.adafruit.com/12mm-led-pixels?view=all
code:
Code: Select all
#include "Adafruit_WS2801.h"
//#include "SPI.h" // Comment out this line if using Trinket or Gemma
#ifdef __AVR_ATtiny85__
#include <avr/power.h>
#endif
/*****************************************************************************
Example sketch for driving Adafruit WS2801 pixels!
Designed specifically to work with the Adafruit RGB Pixels!
12mm Bullet shape ----> https://www.adafruit.com/products/322
12mm Flat shape ----> https://www.adafruit.com/products/738
36mm Square shape ----> https://www.adafruit.com/products/683
These pixels use SPI to transmit the color data, and have built in
high speed PWM drivers for 24 bit color per pixel
2 pins are required to interface
Adafruit invests time and resources providing this open source code,
please support Adafruit and open-source hardware by purchasing
products from Adafruit!
Written by Limor Fried/Ladyada for Adafruit Industries.
BSD license, all text above must be included in any redistribution
*****************************************************************************/
/****************************************************************************
PixelControlTest for Trinket - by CopalFreak
This is modification of Limor Fried/Ladyadas' original example
created for the purpose of helping me understand how to control
single pixels so that I could make a shape of the pixel-strand and have an
easy way to 'chase' the lights from the ends to the center.
Many thanks to adafruit_support_bill for his assistance.
*****************************************************************************/
uint32_t red = Color(255, 0, 0);
uint32_t green = Color(0, 255, 0);
uint32_t blue = Color(0, 0, 255);
uint32_t off = Color(0, 0, 0);
uint8_t dataPin = 2; // Yellow wire on Adafruit Pixels
uint8_t clockPin = 3; // Green wire on Adafruit Pixels
Adafruit_WS2801 strip = Adafruit_WS2801(25, dataPin, clockPin);
void setup() {
#if defined(__AVR_ATtiny85__) && (F_CPU == 16000000L)
clock_prescale_set(clock_div_1); // Enable 16 MHz on Trinket
#endif
strip.begin();
strip.show();
}
void loop() {
centerMeet();
}
void centerMeet()
{
// I have a single strand of 25 pixels
int top = 0; // starting at pixel "0" ..closest to controller
int bottom = 24; // starting at pixel "24" ..farthest from controller
int wait = 1000; // 1 second
uint32_t color = blue ; // defined at top
while (top <= bottom)
{
testPixel(top,color,wait);
testPixel(bottom,color,wait);
delay(wait);
testPixel(top,off,wait);
testPixel(bottom,off,wait);
delay(wait);
top = (top + 1);
bottom = (bottom - 1);
}
}
void testPixel(uint8_t pixel, uint32_t c, uint8_t wait) {
int i = pixel;
strip.setPixelColor(i, c);
strip.show(); // write all the pixels out
}
/* 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;
}
Please be positive and constructive with your questions and comments.