Hello
I`m try to random my leds only cover this colors
(255, 0, 0)); // Red
(0, 255, 0)); // Green
(0, 0, 255)); // Blue
(255, 255, 255)); //White
Could You advice how to change this code :
#include <Adafruit_NeoPixel.h>
#define PIN 3 // On Trinket or Gemma, suggest changing this to 1
// How many NeoPixels are attached to the Arduino?
#define NUMPIXELS 24 // Popular NeoPixel ring size
Adafruit_NeoPixel pixels(NUMPIXELS, PIN, NEO_GRB + NEO_KHZ800);
#define DELAYVAL 200 // Time (in milliseconds) to pause between pixels
unsigned char x[2]={0, 255};
unsigned char y = x[random(0,2)]; //pick one
void setup() {
pixels.begin(); // INITIALIZE NeoPixel strip object (REQUIRED)
pixels.show();
pixels.setBrightness(25);
}
void loop() {
pixels.clear();
for(int i=0; i<NUMPIXELS; i++) { // For each pixel...
pixels.setPixelColor(i, pixels.Color(random(y),random(y),random(y)));
pixels.show(); // Send the updated pixel colors to the hardware.
delay(DELAYVAL); // Pause before next pass through loop
}
}
Right now the color is pick up randomly but it`s to much other colors.
See file - Video .
I want to define the 4 color only to pick up them randomly.
Hi I put it in to code finally work but white is missing
Could You advice what to wrote in code to see serialprint "case" which was drawn .
#include <Adafruit_NeoPixel.h>
#define PIN 3 // On Trinket or Gemma, suggest changing this to 1
// How many NeoPixels are attached to the Arduino?
#define NUMPIXELS 24 // Popular NeoPixel ring size
Adafruit_NeoPixel pixels(NUMPIXELS, PIN, NEO_GRB + NEO_KHZ800);
#define DELAYVAL 200 // Time (in milliseconds) to pause between pixels
//unsigned char x[2]={0, 255};
//unsigned char y = x[random(0,2)]; //pick one
void setup() {
Serial.begin(9600);
pixels.begin(); // INITIALIZE NeoPixel strip object (REQUIRED)
pixels.show();
pixels.setBrightness(225);
}
void loop() {
pixels.clear();
for(int i=0; i<NUMPIXELS; i++) { // For each pixel...
{
switch (random(0, 3)) {
case 0:
pixels.setPixelColor(i, pixels.Color(255, 0, 0));
break;
case 1:
pixels.setPixelColor(i, pixels.Color(0, 255, 0));
break;
case 2:
pixels.setPixelColor(i, pixels.Color(0, 0, 255));
break;
case 3:
pixels.setPixelColor(i, pixels.Color(255, 255, 255));
break;
}
}
//pixels.setPixelColor(i, pixels.Color(random(y),random(y),random(y)));
pixels.show(); // Send the updated pixel colors to the hardware.
delay(DELAYVAL); // Pause before next pass through loop
Serial.println(i);
}
}