1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102
|
#include <Adafruit_NeoPixel.h>
#ifdef __AVR__
#include <avr/power.h> // Required for 16 MHz Adafruit Trinket
#endif
// Which pin on the Arduino is connected to the NeoPixels?
#define PIN 4 // On Trinket or Gemma, suggest changing this to 1
#define PIN2 5 // On Trinket or Gemma, suggest changing this to 1
// How many NeoPixels are attached to the Arduino?
#define NUMPIXELS 30 // Popular NeoPixel ring size
Adafruit_NeoPixel pixels(NUMPIXELS, PIN, NEO_GRB + NEO_KHZ800);
Adafruit_NeoPixel pixels2(NUMPIXELS, PIN2, NEO_GRB + NEO_KHZ800);
#define DELAYVAL 3 // Time (in milliseconds) to pause between pixels
const int Push_button_pin = 0;
const int Push_button_2 = 2;
const int led = 14;
int Push_button_state = 0;
int Push_button_state2 = 0;
void setup() {
pinMode(Push_button_pin, INPUT);
pinMode(Push_button_2, INPUT);
pinMode(led, OUTPUT);
#if defined(__AVR_ATtiny85__) && (F_CPU == 16000000)
clock_prescale_set(clock_div_1);
#endif
// END of Trinket-specific code.
pixels.begin(); // INITIALIZE NeoPixel strip object (REQUIRED)
pixels2.begin(); // INITIALIZE NeoPixel strip object (REQUIRED)
}
void loop() {
//generate a random number
int randomNumber = random(1,255);
int randomNumber1 = random(1,255);
int randomNumber2 = random(1,255);
Push_button_state = digitalRead(Push_button_pin);
if (Push_button_state == LOW) {
for(int i=0; i<NUMPIXELS; i++) { // For each pixel...
if(randomNumber2 < 100){
randomNumber2 =0;
}
pixels.setPixelColor(i, pixels.Color(randomNumber, randomNumber2, randomNumber1));
pixels.show(); // Send the updated pixel colors to the hardware.
delay(100); // Pause before next pass through loop
}
}
Push_button_state2 = digitalRead(Push_button_2);
if (Push_button_state2 == LOW) {
for(int i=0; i<NUMPIXELS; i++) { // For each pixel.
if(randomNumber2 < 100){
randomNumber2 =0;
}
pixels2.setPixelColor(i, pixels2.Color(randomNumber2, randomNumber, randomNumber1));
pixels2.show(); // Send the updated pixel colors to the hardware.
delay(100); // Pause before next pass through loop
}
}
if (Push_button_state == HIGH ) {
pixels.clear();
for(int i=NUMPIXELS; i>0; i--) { // For each pixel...
pixels.setPixelColor(i, pixels.Color(255,0, 0));
pixels.show(); // Send the updated pixel colors to the hardware.
delay(DELAYVAL); // Pause before next pass through loop
}
}
if (Push_button_state2 == HIGH ) {
pixels2.clear();
for(int i=NUMPIXELS; i>0; i--) { // For each pixel...
pixels2.setPixelColor(i, pixels2.Color(0, 0, 255));
pixels2.show(); // Send the updated pixel colors to the hardware.
delay(DELAYVAL); // Pause before next pass through loop
}
}
} |
Partager