Saltar la navegación

Proyectos Neopixel 19

Divide la tira en cuatro tramos y modifica el color de un elemento elegido al azar en cada uno de los tramos

Neopixels. Random led y color_2

#include <Adafruit_NeoPixel.h>
 
#define PIN 2 // input pin Neopixel is attached to
 
#define NUMPIXELS      40 // number of neopixels in strip
 
Adafruit_NeoPixel pixels = Adafruit_NeoPixel(NUMPIXELS, PIN, NEO_GRB + NEO_KHZ800);
 
int delayval = 100; // timing delay in milliseconds
 
int redColor = 0;
int greenColor = 0;
int blueColor = 0;
int np1=0;
int np2=0;
int np3=0;
int np4=0;
void setup() {
  // Initialize the NeoPixel library.
  pixels.begin();
 
   
}
 
void loop() {
   setColor();
 
 // for (int i=0; i < 1000; i++) {
    np1 =random (0,NUMPIXELS/4);
  np2 =random (NUMPIXELS/4,2*NUMPIXELS/4);
  np3 =random (2*NUMPIXELS/4,3*NUMPIXELS/4);
  np4 =random (3*NUMPIXELS/4,NUMPIXELS);
  
  
  // pixels.Color takes RGB values, from 0,0,0 up to 255,255,255
    pixels.setPixelColor(np1, pixels.Color(redColor, greenColor, blueColor));
   pixels.setPixelColor(np2, pixels.Color(redColor, greenColor, blueColor));
   pixels.setPixelColor(np3, pixels.Color(redColor, greenColor, blueColor));
   pixels.setPixelColor(np4, pixels.Color(redColor, greenColor, blueColor));
 
    //setColor();
    //pixels.setPixelColor(10+i, pixels.Color(redColor, greenColor, blueColor));
 
    // This sends the updated pixel color to the hardware.
    pixels.show();
 
    // Delay for a period of time (in milliseconds).
    setColor();
 
 delay(delayval);
  //pixels.setPixelColor(i, pixels.Color(0, 0, 0));
 
 
//}
 
 
}
 
// setColor()
// picks random values to set for RGB
void setColor(){
  redColor = random(0, 255);
  greenColor = random(0,255);
  blueColor = random(0, 255);
}