Saltar la navegación

Proyectos Neopixel 21 (modificación 20)

Modificación del NeoPíxels. Random led y color_3. Antes de aplicar un color a un píxel modifica el color por random

Neopixels. Random led y color_4

#include <Adafruit_NeoPixel.h>
 
#define PIN 2 // input pin Neopixel is attached to
 
#define NUMPIXELS      80 // 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;
int np5=0;
int np6=0;
int np7=0;
int np8=0;
void setup() {
  // Initialize the NeoPixel library.
  pixels.begin();
 
   
}
 
void loop() {
   setColor();
  np();
 
  
  
  // pixels.Color takes RGB values, from 0,0,0 up to 255,255,255
    pixels.setPixelColor(np1, pixels.Color(redColor, greenColor, blueColor));
  setColor();
  pixels.setPixelColor(np2, pixels.Color(redColor, greenColor, blueColor));
  setColor();
  pixels.setPixelColor(np3, pixels.Color(redColor, greenColor, blueColor));
  setColor();
  pixels.setPixelColor(np4, pixels.Color(redColor, greenColor, blueColor));
  setColor();
  pixels.setPixelColor(np5, pixels.Color(redColor, greenColor, blueColor));
  setColor(); 
  pixels.setPixelColor(np6, pixels.Color(redColor, greenColor, blueColor));
  setColor();
  pixels.setPixelColor(np7, pixels.Color(redColor, greenColor, blueColor));
  setColor();
  pixels.setPixelColor(np8, 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));
 
 
//}
 
 
}
void np(){
  np1 =random (0,NUMPIXELS/8);
  np2 =random (NUMPIXELS/8,2*NUMPIXELS/8);
  np3 =random (2*NUMPIXELS/8,3*NUMPIXELS/8);
  np4 =random (3*NUMPIXELS/8,4*NUMPIXELS/8);
  np5 =random (4*NUMPIXELS/8,5*NUMPIXELS/8);
  np6 =random (5*NUMPIXELS/8,6*NUMPIXELS/8);
  np7 =random (6*NUMPIXELS/8,7*NUMPIXELS/8);
  np8 =random (7*NUMPIXELS/8,NUMPIXELS);
  
}
// setColor()
// picks random values to set for RGB
void setColor(){
  redColor = random(0, 255);
  greenColor = random(0,255);
  blueColor = random(0, 255);
}