Ok, more things that don't work like I expect:
when I run
for (int i=0; i <= (sizeof(nextMillis)/sizeof(nextMillis[0])); i++){
[... other parts of the code block ...]
Serial.print(i);
[... other parts of the code block ...]
}
serial shows as i sometime rouge values.
Also at same time one LED which should turns on or updates. (so it is not just the serial)
Quirks of tinkercad?
Side-note: The LED also shows rouge behavior when I use for (int i=0; i <= 7 ; i++)
current full code:
/*
describe your code here
*/
#include <Adafruit_NeoPixel.h>
#define PIN 11 // input pin Neopixel is attached to
#define NUMPIXELS 19 // number of neopixels in strip
#define delayval 20 // timing delay in milliseconds
Adafruit_NeoPixel pixels = Adafruit_NeoPixel(NUMPIXELS, PIN, NEO_GRB + NEO_KHZ800);
/*
int redColor = 127;
int greenColor = 127;
int blueColor = 0;
// contents: red value, green value, blue value, position on the color cycle
int LED1Color[]={127,127,0,0}; // pair 1 = 1 & 13
int LED2Color[]={127,127,0,0}; // pair 2 = 3 & 14
int LED3Color[]={127,127,0,0}; // pair 3 = 5 & 15
int LED4Color[]={127,127,0,0}; // pair 4 = 7 & 16
int LED5Color[]={127,127,0,0}; // pair 5 = 9 & 17
int LED6Color[]={127,127,0,0}; // pair 6 = 11 & 18
int LED7Color[]={127,127,0,0}; //top LED = 19
*/
int LEDColor[7][4]={{127,127,0,0},{127,127,0,0},{127,127,0,0},{127,127,0,0},{127,127,0,0},{127,127,0,0},{127,127,0,0}}; //LED block see above
int LED8Color[]={127,127,0,0}; //LED 2
int LED9Color[]={127,127,0,0}; //LED 4
int LED10Color[]={127,127,0,0}; //LED 6
int LED11Color[]={127,127,0,0}; //LED 8
int LED12Color[]={127,127,0,0}; //LED 10
int LED13Color[]={127,127,0,0}; //LED 12
unsigned long nextMillis[]={0,0,0,0,0,0,0};
int bright =0;
void setup() {
// Initialize the NeoPixel library.
pixels.begin();
pinMode(9, OUTPUT);
Serial.begin(9600);
}
void loop() {
// for (int i=0; i <= (sizeof(nextMillis)/sizeof(nextMillis[0])); i++) //sizeof(nextMillis))
for (int i=0; i <= 7 ; i++)
{
if (millis()>=nextMillis[i]){
nextMillis[i]=millis()+ranPause();
// Serial.print(i);
// Serial.print(" --> ");
// Serial.println(nextMillis[i]);
pixels.setPixelColor(i, pixels.Color(LEDColor[i][0],LEDColor[i][1],LEDColor[i][2]));
colorRotation(i,LEDColor[i][0],LEDColor[i][1],LEDColor[i][2],LEDColor[i][3]);
pixels.show();
}
}
delay(delayval);
}
void setBright() { // placeholder for now
bright = random (0, 127);
}
int ranPause(){
// return random(100, 150); // to slow in simulator more tweaking on actual hardware needed.
return random(5, 10);
}
void colorRotation(int LED,int RredColor,int RgreenColor,int RblueColor,int circ){
switch (circ) {
case 0: //green
if (RgreenColor <= 254) {
// RredColor--; // to slow
// RgreenColor++;
RredColor=RredColor-10;
RgreenColor=RgreenColor+10;
if (RredColor<0) {RredColor=0;}
if (RgreenColor>255) {RgreenColor=255;}
}
else {
circ++;
}
break;
case 1: //blue
if (RblueColor <= 254) {
// RgreenColor--;
// RblueColor++;
RgreenColor=RgreenColor-10;
RblueColor=RblueColor+10;
if (RgreenColor<0) {RgreenColor=0;}
if (RblueColor>255) {RblueColor=255;}
}
else {
circ++;
}
break;
case 2: //red
if (RredColor <= 254) {
// RblueColor--;
// RredColor++;
RblueColor=RblueColor-10;
RredColor=RredColor+10;
if (RblueColor<0) {RblueColor=0;}
if (RredColor>255) {RredColor=255;}
}
else {
circ=0;
}
break;
default:
circ=0;
break;
}
//LEDColor[LED][]= {RredColor,RgreenColor,RblueColor,circ};
//LEDColor[LED]= {RredColor,RgreenColor,RblueColor,circ}; Both do not work. Why?
LEDColor[LED][0]= RredColor;
LEDColor[LED][1]= RgreenColor;
LEDColor[LED][2]= RblueColor;
LEDColor[LED][3]= circ;
}