#include <Adafruit_NeoPixel.h>

#define DIN_PIN 6
#define NUM_PIXELS 3

Adafruit_NeoPixel pixels(NUM_PIXELS, DIN_PIN);

int32_t colors[] = {
  pixels.Color(255, 0, 0),    // Red
  pixels.Color(255, 255, 0),  // Yellow
  pixels.Color(0, 255, 0),    // Green
};

unsigned long startMillis;         // Store start time
unsigned long millisCorrente;      // Store current time
const unsigned long periodo_verde = 5000;  // 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 stato_led = 0;  // State to control which color to display

void setup() {
  Serial.begin(9600);  // Start serial communication
  pixels.begin();      // Initialize NeoPixel strip
  startMillis = millis();  // Store the start time
}

void loop() {
  millisCorrente = millis();  // Get current time

  // Handle the logic for the different LED states
  if (stato_led == 0) {  // Green
    pixels.setPixelColor(0, colors[2]);  // Set first pixel to green
    pixels.show();  // Update the LEDs
    
    // Switch state after the green period
    if (millisCorrente - startMillis >= periodo_verde) {
      Serial.println("Switching to Yellow");
      pixels.clear();  // Clear LED strip
      pixels.show();   // Update the LEDs
      stato_led = 1;   // Change state to yellow
      startMillis = millis();  // Reset startMillis for the next timing cycle
    }
  }
  else if (stato_led == 1) {  // Green + Yellow (transition)
       pixels.setPixelColor(1, colors[1]);  // Set second pixel to yellow
    pixels.show();  // Update the LEDs
    
    // Switch back to green after the yellow period
    if (millisCorrente - startMillis >= periodo_giallo) {
      Serial.println("Switching to Red");
      pixels.clear();  // Clear LED strip
      pixels.show();   // Update the LEDs
      stato_led = 2;   // Change state to green
      startMillis = millis();  // Reset startMillis for the next cycle
    }
  }
  else if (stato_led == 2) {  // Green + Yellow (transition)
       pixels.setPixelColor(2, colors[0]);  // Set third pixel to red
    pixels.show();  // Update the LEDs
    
    // Switch back to green after the yellow period
    if (millisCorrente - startMillis >= periodo_rosso) {
      Serial.println("Switching back to Green");
      pixels.clear();  // Clear LED strip
      pixels.show();   // Update the LEDs
      stato_led = 0;   // Change state to green
      startMillis = millis();  // Reset startMillis for the next cycle
    }
  }
}
uno:A5.2
uno:A4.2
uno:AREF
uno:GND.1
uno:13
uno:12
uno:11
uno:10
uno:9
uno:8
uno:7
uno:6
uno:5
uno:4
uno:3
uno:2
uno:1
uno:0
uno:IOREF
uno:RESET
uno:3.3V
uno:5V
uno:GND.2
uno:GND.3
uno:VIN
uno:A0
uno:A1
uno:A2
uno:A3
uno:A4
uno:A5
rgb1:VDD
rgb1:DOUT
rgb1:VSS
rgb1:DIN
rgb2:VDD
rgb2:DOUT
rgb2:VSS
rgb2:DIN
rgb3:VDD
rgb3:DOUT
rgb3:VSS
rgb3:DIN