Hello new to the forum here. Spent a lot of time trying different things but end up with things not working right. Ive got a robot head project Ive been working on but have been struggling with the code for it. I didnt have nay programming knowledge coming into this project but have been slowly getting some stuff down. Right now I have a LED strip animation that i would like to try and create. Ive gotten close to what I want it to be but have run into a problem. Main one being is that Im currently using a delay for the strips. They are like neo pixel strips so 1 data line per strip. I have 2 different lengths. Some on the head itself and 2 lengths for antennas. Been trying to make a LED chase animation where 5 or so LED's run down the strip. Right now the code I cobbled together is getting caught up in the delay line and not running them all at the same time. I tried to get is on the millis thing to avoid the delay but was unable to make it work. So I was wondering if there was a way to code to just have 5 LEDs run down the strip every second on 3 pins being able to change the number of LEDs per pin. So say 5 LEDs run down pin 3 while 10 LEDs run down pin 10. Havent been able to track down any examples that do what Im trying to accomplish. Here is what I had but this has the issue with the delay. There is also a LED matrix that is going to be running on this arduino as well for the eyes. That has no animation just a fillrect. If I need to I can add another arduino to the mix. The mouth is on a separate arduino as well. That will hopefully be voice reactive at some point. Hopefully some of that made sense. Thanks for any advice or help! Been a fun project so far and I want to learn this stuff.
#include <Adafruit_GFX.h>
#include <Adafruit_NeoMatrix.h>
#include <Adafruit_NeoPixel.h>
#ifndef PSTR
#define PSTR // Make Arduino Due happy
#endif
Adafruit_NeoMatrix left = Adafruit_NeoMatrix(8, 8, 6,
NEO_MATRIX_TOP + NEO_MATRIX_LEFT +
NEO_MATRIX_COLUMNS + NEO_MATRIX_ZIGZAG,
NEO_GRB + NEO_KHZ800); //left eye
Adafruit_NeoMatrix right = Adafruit_NeoMatrix(8, 8, 5,
NEO_MATRIX_TOP + NEO_MATRIX_RIGHT +
NEO_MATRIX_COLUMNS + NEO_MATRIX_ZIGZAG,
NEO_GRB + NEO_KHZ800); //right eye
Adafruit_NeoPixel runs = Adafruit_NeoPixel(73, 3, NEO_GRB + NEO_KHZ800);
Adafruit_NeoPixel SmallAnt = Adafruit_NeoPixel(15, 10, NEO_GRB + NEO_KHZ800);
Adafruit_NeoPixel TallAnt = Adafruit_NeoPixel(23, 11, NEO_GRB + NEO_KHZ800);
//(numled, pin, NEO_GRB + NEO_KHZ800))
void setup() {
// put your setup code here, to run once:
left.begin();
left.setBrightness(40);
right.begin();
right.setBrightness(40);
runs.begin();
TallAnt.begin();
SmallAnt.begin();
TallAnt.setBrightness(40);
SmallAnt.setBrightness(40);
runs.setBrightness(40);
}
int x = left.Color(0, 255,0); // green for eyes left and right
int x2= left.Color(0,0,255); //not needed used for testing
void loop() {
// put your main code here, to run repeatedly:
//matrix.fillRect(1,2,3,3,x); 3x3 // testing smaller eye size
right.fillRect(0,1,4,4,x); //4x4
left.fillRect(0,1,4,4,x);
{
right.show();
left.show();
}
chase(runs.Color(0, 255, 0)); // Green
chase(SmallAnt.Color(0, 255, 0));
chase(TallAnt.Color(0, 255, 0));
}
static void chase(uint32_t c) {
for(uint16_t i=0; i<runs.numPixels()+10; i++) {
runs.setPixelColor(i , c); // Draw new pixel green
runs.setPixelColor(i-10,128,0,128); // Emakes backgroud leds purpleish
runs.show();
delay(50);
for(uint16_t i=0; i<TallAnt.numPixels()+5; i++) {
TallAnt.setPixelColor(i , c); // Draw new pixel green
TallAnt.setPixelColor(i-5,128,0,128); // makes backgroud leds purpleish
TallAnt.show();
delay(50);
for(uint16_t i=0; i<SmallAnt.numPixels()+5; i++) {
SmallAnt.setPixelColor(i , c); // Draw new pixel green
SmallAnt.setPixelColor(i-5,128,0,128); // makes backgroud leds purpleish
SmallAnt.show();
delay(50);
}
}
}
}
Here it is running with everything on a test code just to make sure it was all working.