Neopixel LED Strip + pixel assignment using matrix dim?
Hello.
I am trying to assign colors for each pixels on Neopixel led Strip (144LEDS) .
I have tested codes available on this forum for this purpose, but it appears not working for assigning multiple( or all) pixel colors using jit.iter and serial communication. it allows only using 3 planes.
dim assigns the order of multiple pixel to change the colors, but it's important to change multiple pixels on LED strip at the same time other than the single dim pixel.
maybe a problem with parsing the list of message via serial?
//--arduino code//
#include <Adafruit_NeoPixel.h>
#ifdef __AVR__
#include <avr/power.h>
#endif
#define PIN 6
#define NUM_LEDS 140
#define BRIGHTNESS 50
Adafruit_NeoPixel strip_a = Adafruit_NeoPixel(NUM_LEDS, PIN, NEO_GRBW + NEO_KHZ800);
int pixelA = 0; // pixel number that you're changing
int redA = 255; // red value
int greenA = 0; // green value
int blueA = 0; // blue value
int setBrightness = 50;
/*
Adafruit_NeoPixel strip_b = Adafruit_NeoPixel(4, 3, NEO_GRB + NEO_KHZ800);
int pixelB = 2; // pixel number that you're changing
int redB = 100; // red value
int greenB = 24; // green value
int blueB = 255; // blue value
*/
void setup() {
Serial.begin(115200); // initialize serial communication
Serial.setTimeout(10); // set serial timeout
strip_a.setBrightness(BRIGHTNESS);
strip_a.begin(); // initialize pixel strip
strip_a.show(); // Initialize all pixels to 'off'
//strip_b.begin(); // initialize pixel strip
//strip_b.show(); // Initialize all pixels to 'off'
}
void loop() {
// listen for serial:
if (Serial.available() > 0) {
if (Serial.read() == 'C') { // string should start with C
pixelA = Serial.parseInt(); // then an ASCII number for pixel number
redA = Serial.parseInt(); // then an ASCII number for red
greenA = Serial.parseInt(); // then an ASCII number for green
blueA = Serial.parseInt(); // then an ASCII number for blue
//pixelB = Serial.parseInt(); // then an ASCII number for pixel number
//redB = Serial.parseInt(); // then an ASCII number for red
//greenB = Serial.parseInt(); // then an ASCII number for green
//blueB = Serial.parseInt(); // then an ASCII number for blue
strip_a.setPixelColor(pixelA, redA, greenA, blueA);// set the color for this pixel
strip_a.show(); // refresh the strip
//strip_b.setPixelColor(pixelB, redB, greenB, blueB);// set the color for this pixel
//strip_b.show(); // refresh the strip
}
}
}
I've tried so far and realized it's the matter of using Channel to send a list of all LEDs at once. The arduino should process it every time , which involves its data processing speed and mechanism.
I found this on the Forum. Does it need to use Teensy (not regular Arduinos) to load all addressed LEDs at once? Any suggestion would be very much appreciated...
My goal is to map @dim 144 1 matrix to display colors for each 144 leds on a strip.. is it too much to process?
Here are two arduino codes I've been playing with,
#include <Adafruit_NeoPixel.h>
const int numLeds = 140;
const int numChannels = numLeds * 3;
byte pin = 17;
Adafruit_NeoPixel leds = Adafruit_NeoPixel(numLeds, pin, NEO_GRBW + NEO_KHZ800);
char serial_array[numChannels];
int serial_array_length = 0;
void setup() {
Serial.begin(115200);
leds.begin();
test();
}
void loop()
{
int n = Serial.available();
// first, check if there's anything available to read
if (n > 0)
{
// if it's more than needed, read only enough to fill the array
if (n > numChannels - serial_array_length) n = numChannels - serial_array_length;
// actually read the data, adding to whatever is already in the array
Serial.readBytes(serial_array + serial_array_length, n);
serial_array_length = serial_array_length + n;
// then check if this filled the array and use the data
if (serial_array_length >= numChannels)
{
for (int i = 0; i < numLeds ; i++)
leds.setPixelColor(i, serial_array[i*4], serial_array[i*4+1], serial_array[i*4+2], serial_array[i*4+3]);
leds.show();
serial_array_length = 0;
}
}
}
void test() {
for (int i = 0; i < numLeds ; i++){
leds.setPixelColor(i, random(0,255), random(0,255), random(0,255), random(0,255));
leds.show();
delay(20);
leds.setPixelColor(i, 0, 0, 0, 0);
leds.show();
}
}
///------------------///
#include <Adafruit_NeoPixel.h>
#ifdef __AVR__
#include <avr/power.h>
#endif
#define PIN 6
//#define PIN 7
#define NUM_LEDS 144
#define BRIGHTNESS 10
Adafruit_NeoPixel strip_a = Adafruit_NeoPixel(NUM_LEDS, 6, NEO_GRBW + NEO_KHZ800);
int pixelA; // pixel number that you're changing
int redA; // red value
int greenA; // green value
int blueA; // blue value
int setBrightness = 10;
void setup() {
Serial.begin(115200); // initialize serial communication
Serial.setTimeout(10); // set serial timeout
strip_a.begin(); // initialize pixel strip
strip_a.show(); // Initialize all pixels to 'off' //strip_b.show(); // Initialize all pixels to 'off'
}
void loop() {
// listen for serial:
if (Serial.available()) {
if (Serial.read() == 'C') { // string should start with C
pixelA = Serial.parseInt(); // then an ASCII number for pixel number
redA = Serial.parseInt(); // then an ASCII number for red
greenA = Serial.parseInt(); // then an ASCII number for green
blueA = Serial.parseInt(); // then an ASCII number for blue
}
}
strip_a.setPixelColor(pixelA, redA, greenA, blueA, 10);// set the color for this pixel
strip_a.show(); // refresh the strip
delay(1);
}