I am again way over my head and totally stuck. Program is in a very early stage and not nearly has all functions in it.
In my project I try to control a bunch of neopixels.
A few of them should be changing color (see code below), but all of them individually. I mean all of them change in the same pattern but how long they take for each step is later randomized.
The part above is the one that causes me trouble.
the rest of them should be display chasing colors (what I exactly want, I haven't though about yet. Like which colors,if random, how random etc, but I think I can do this part on my own)
On top of that at random intervals a random LED should be blink yellow at max brightness. (I also think I can do that on my own)
All pixels (except the occasionally yellow one) should run the breathing brightness animation.
Back to my problem:
I have 6 pixels that I want to run a color change in a randomized speed (by changing the interval in between them, but I am not at that part just yet) but for that each pixel has to know at which part of the animation it is.
I wanted to solve that by ... I actually tried so many ways to get the function to work I forgot.
Basic color cycle: (with int RredColor = 127; int RgreenColor = 127; int RblueColor = 0;)
switch (circ) {
case 0: //green
if (RgreenColor <= 254) {
RredColor--;
RgreenColor++;
if (RredColor<0) {RredColor=0;}
}
else {
circ++;
}
break;
case 1: //blue
if (RblueColor <= 254) {
RgreenColor--;
RblueColor++;
if (RgreenColor<0) {RgreenColor=0;}
}
else {
circ++;
}
break;
case 2: //red
if (RredColor <= 254) {
RblueColor--;
RredColor++;
if (RblueColor<0) {RblueColor=0;}
}
else {
circ=0;
}
break;
default:
circ=0;
break;
}
Problem is ... I think ... (maybe I am choosing the total wrong approach, tho) I can't make the function take and return arrays.
#include <Adafruit_NeoPixel.h>
#define PIN 11 // input pin Neopixel is attached to
#define NUMPIXELS 19 // number of neopixels in strip
Adafruit_NeoPixel pixels = Adafruit_NeoPixel(NUMPIXELS, PIN, NEO_GRB + NEO_KHZ800);
int delayval = 20; // timing delay in milliseconds (temporary for now)
int redColor = 0;
int greenColor = 0;
int blueColor = 0;
//int circ[4]= {127,127,0,0};
int acirc[]= {127,127,0,0};
void setup() {
pixels.begin();
}
void loop() {
delay(delayval);
pixels.setPixelColor(0, pixels.Color(acirc[0],acirc[1],acirc[2]));
pixels.show();
// circ = colorRotation(circ[0],circ[1],circ[2],circ[3]);
acirc = colorRotation(acirc);
}
int * colorRotation(int data[]){
int RredColor=data[0];
int RgreenColor=data[1];
int RblueColor=data[2];
int circ=data[3];
switch (circ) {
case 0: //green
if (RgreenColor <= 254) {
RredColor--;
RgreenColor++;
if (RredColor<0) {RredColor=0;}
}
else {
circ++;
}
break;
case 1: //blue
if (RblueColor <= 254) {
RgreenColor--;
RblueColor++;
if (RgreenColor<0) {RgreenColor=0;}
}
else {
circ++;
}
break;
case 2: //red
if (RredColor <= 254) {
RblueColor--;
RredColor++;
if (RblueColor<0) {RblueColor=0;}
}
else {
circ=0;
}
break;
default:
circ=0;
break;
}
int out[]={RredColor,RgreenColor,RblueColor,circ};
return out;
}
My brain is stuck and needs a nudge.
And I'm sorry for the lack of comments, it is a very bad habit.