#include <Adafruit_NeoPixel.h>
#define DIN_PIN_1 11 //pin striscia 1
#define NUM_PIXELS_1 4 // numero LED striscia 1
#define DIN_PIN_2 10 //pin striscia 2
#define NUM_PIXELS_2 4 // numero LED striscia 2
#define DIN_PIN_3 9 //pin striscia 3
#define NUM_PIXELS_3 4 // numero LED striscia 3
#define DIN_PIN_4 3 //pin striscia 4
#define NUM_PIXELS_4 4 // numero LED striscia 4
#define DIN_PIN_5 5 //pin striscia 5
#define NUM_PIXELS_5 4 // numero LED striscia 5
#define DIN_PIN_6 6 //pin striscia 6
#define NUM_PIXELS_6 4 // numero LED striscia 6
//costruttore oggetto Neopixel
Adafruit_NeoPixel pixels_1(NUM_PIXELS_1, DIN_PIN_1);
Adafruit_NeoPixel pixels_2(NUM_PIXELS_2, DIN_PIN_2);
Adafruit_NeoPixel pixels_3(NUM_PIXELS_3, DIN_PIN_3);
Adafruit_NeoPixel pixels_4(NUM_PIXELS_4, DIN_PIN_4);
Adafruit_NeoPixel pixels_5(NUM_PIXELS_5, DIN_PIN_5);
Adafruit_NeoPixel pixels_6(NUM_PIXELS_6, DIN_PIN_6);
//array per gestire le strisce in accensione
Adafruit_NeoPixel* strips[] = {
&pixels_1, &pixels_2, &pixels_3,
&pixels_4, &pixels_5, &pixels_6
};
// array per colore random
int32_t colors[] = {
pixels_1.Color(0, 0, 0),
pixels_1.Color(0, 0, 0),
pixels_1.Color(0, 0, 0),
/*pixels_1.Color(255, 0, 0), // Red
pixels_1.Color(255, 255, 0), // Yellow
pixels_1.Color(0, 255, 0), // Green
pixels_1.Color(0, 0, 255), // blue*/
};
int num_pixels[] = { NUM_PIXELS_1, NUM_PIXELS_2, NUM_PIXELS_3,
NUM_PIXELS_4, NUM_PIXELS_5, NUM_PIXELS_6
};
unsigned long startMillis; // Store start time
unsigned long millisCorrente; // Store current time
const unsigned long periodo_verde = 500; // Green color period (5 second)
const unsigned long periodo_giallo = 1000; // Yellow period (1 second)
const unsigned long periodo_rosso = 5000; // Red period (5 second)
int pausa = 0;
int colore = 0;
int r = 0;
int g = 0;
int b = 0;
void setup() {
Serial.begin(9600); // Start serial communication
pixels_1.begin(); // Initialize NeoPixel strip
pixels_2.begin(); // Initialize NeoPixel strip
pixels_3.begin(); // Initialize NeoPixel strip
pixels_4.begin(); // Initialize NeoPixel strip
pixels_5.begin(); // Initialize NeoPixel strip
pixels_6.begin(); // Initialize NeoPixel strip
startMillis = millis(); // Store the start time
}
void loop() {
millisCorrente = millis(); // Get current time
r = random(0,255);
g = random(0,255);
b = random(0,255);
one_Led_double();
/*one_Led();
all_Color_rov();
all_Color();
all_Color_rov();
all_Color();*/
/*
for (int i =0; i< 3; i++) {
strips[i]->clear(); // equivalente a pixels_i.fill(...)
strips[i]->show(); // equivalente a pixels_i.fill(...)
delay(10);
}
*/
/*
pixels_1.fill(colors[colore]); // Set first pixel to green
pixels_1.show(); // Update the LEDs
colore = 0;
Serial.println("sono qui");
delay(pausa);
pixels_1.clear(); // Clear LED strip
pixels_1.show(); // Update the LEDs
int colore1 = random (0,4);
Serial.println(colore1);
pixels_2.fill(colors[colore1]); // Set first pixel to green
//pixels_1.fill(colors[2]); // Set first pixel to green
pixels_2.show(); // Update the LEDs
// colore = 0;
delay(pausa);
pixels_2.clear(); // Clear LED strip
pixels_2.show(); // Update the LEDs
colore = random (0,4);
Serial.println(colore);
pixels_3.fill(colors[colore]); // Set first pixel to green
//pixels_1.fill(colors[2]); // Set first pixel to green
pixels_3.show(); // Update the LEDs
// colore = 0;
delay(pausa);
pixels_3.clear(); // Clear LED strip
pixels_3.show(); // Update the LEDs
for (int i=0; i<NUM_PIXELS_1;i++){
pixels_1.setPixelColor(i, colors[colore]); // Set first pixel to green
pixels_1.show(); // Update the LEDs
delay(pausa);
pixels_1.show(); // Update the LEDs
}
for (int i=0; i<NUM_PIXELS_2;i++){
pixels_2.setPixelColor(i, colors[colore]); // Set first pixel to green
pixels_2.show(); // Update the LEDs
delay(pausa);
pixels_2.show(); // Update the LEDs
}
for (int i=0; i<NUM_PIXELS_3;i++){
pixels_1.clear();
pixels_1.show();
pixels_3.setPixelColor(i, colors[colore]); // Set first pixel to green
pixels_3.show(); // Update the LEDs
delay(pausa);
pixels_3.show(); // Update the LEDs
}
pixels_1.clear();
pixels_1.show();
pixels_2.clear();
pixels_2.show();
pixels_3.clear();
pixels_3.show();
/*
for (int i=NUM_PIXELS_1; i<0;i--){
for (int a=0;a<3;a++){
pixels_[a].setPixelColor(i, colors[colore]); // Set first pixel to green
pixels_[a].show(); // Update the LEDs
delay(pausa);
pixels_[a].show(); // Update the LEDs
/*
delay(199);
pixels_1.clear(); // Clear LED strip
pixels_1.show(); // Update the LEDs*/
/*
//pixels_1.clear(); // Clear LED strip
//pixels_1.show(); // Update the LEDs
delay(100);
for (int i=0; i<NUM_PIXELS_2;i++){
pixels_2.setPixelColor(i, colors[1]); // Set first pixel to green
pixels_2.show(); // Update the LEDs
delay(100);
pixels_1.fill(colors[5]);
delay(200);
}
pixels_2.clear(); // Clear LED strip
pixels_2.show(); // Update the LEDs
delay(100);*/
/*
// Switch state after the green period
if (millisCorrente - startMillis >= periodo_verde) {
Serial.println(Colori[1].messaggio);
pixels_1.clear(); // Clear LED strip
pixels_1.show(); // Update the LEDs
stato_led = (Colori[1].led_colore); // Change state to yellow
startMillis = millis(); // Reset startMillis for the next timing cycle
}
}
else if (stato_led == (Colori[1].led_colore)) { // Green + Yellow (transition)
pixels_1.fill(colors[1]); // Set second pixel to yellow
pixels_1.show(); // Update the LEDs
// Switch back to green after the yellow period
if (millisCorrente - startMillis >= periodo_giallo) {
Serial.println((Colori[2].messaggio));
pixels_1.clear(); // Clear LED strip
pixels_1.show(); // Update the LEDs
stato_led = 2; // Change state to green
startMillis = millis(); // Reset startMillis for the next cycle
}
}
else if (stato_led == (Colori[2].led_colore)) { // Green + Yellow (transition)
pixels_1.setPixelColor(2, colors[0]); // Set third pixel to red
pixels_1.show(); // Update the LEDs
// Switch back to green after the yellow period
if (millisCorrente - startMillis >= periodo_rosso) {
Serial.println((Colori[0].messaggio));
pixels_1.clear(); // Clear LED strip
pixels_1.show(); // Update the LEDs
stato_led = (Colori[0].led_colore); // Change state to green
startMillis = millis(); // Reset startMillis for the next cycle
}*/
//}
}