// This was written and compiled in Arduino IDE 2.2.1 for a Raspberry Pi Pico
// You will need to install the Adafruit_NeoPixel library
// Swaps among 4 different color options via 2 on/off switches.

#include <Adafruit_NeoPixel.h>

#define PIN_NEO_PIXEL 1  // Arduino pin that connects to NeoPixel
#define NUM_PIXELS 144    // The number of LEDs (pixels) on NeoPixel
#define PIN_SW1 16
#define PIN_SW2 17
#define CRACKLE_DELAY 50  // 50ms crackle flash

// 2 Switches were insterted to switch between 4 color options
int SW1 = 0;
int SW2 = 0;

Adafruit_NeoPixel NeoPixel(NUM_PIXELS, PIN_NEO_PIXEL, NEO_GRB + NEO_KHZ800);

void setup() {
  NeoPixel.begin();  // INITIALIZE NeoPixel strip object (REQUIRED)
  pinMode(PIN_SW1, INPUT_PULLUP);  
  pinMode(PIN_SW2, INPUT_PULLUP);  
}

void loop() {
  NeoPixel.clear();  // set all pixel colors to 'off'. It only takes effect if pixels.show() is called
  int SW1 = digitalRead(PIN_SW1);
  int SW2 = digitalRead(PIN_SW2);

//GREEN
  if (SW1 == 0 && SW2 == 0){
    for (int pixel = 0; pixel < NUM_PIXELS; pixel++) {           // for each pixel
      NeoPixel.setPixelColor(pixel, NeoPixel.Color(0, 255, 0));  // it only takes effect if pixels.show() is called       
    }
    NeoPixel.show();  // send the updated pixel colors to the NeoPixel hardware.
  }

//RED
  else if (SW1 == 1 && SW2 == 0){
    for (int pixel = 0; pixel < NUM_PIXELS; pixel++) {           // for each pixel
      NeoPixel.setPixelColor(pixel, NeoPixel.Color(255, 0, 0));  // it only takes effect if pixels.show() is called       
    }
    NeoPixel.show();  
  }

  //BLUE
  else if (SW1 == 0 && SW2 == 1){
    for (int pixel = 0; pixel < NUM_PIXELS; pixel++) {           
      NeoPixel.setPixelColor(pixel, NeoPixel.Color(0, 0, 255));        
    }
    NeoPixel.show(); 
  }

    //GREEN CRACKLE - Generates a randomized white flash
  else if (SW1 == 1 && SW2 == 1){
    for (int pixel = 0; pixel < NUM_PIXELS; pixel++) {           
      NeoPixel.setPixelColor(pixel, NeoPixel.Color(0, 255, 0));         
    }
    int crack = random(3,140);
    NeoPixel.setPixelColor(crack, NeoPixel.Color(255,255,255));
    NeoPixel.setPixelColor(crack + 1, NeoPixel.Color(255,255,255));
    NeoPixel.show();  
    delay(CRACKLE_DELAY); 
    NeoPixel.setPixelColor(crack, NeoPixel.Color(0, 255, 0));
    NeoPixel.setPixelColor(crack + 1, NeoPixel.Color(0, 255, 0));
    NeoPixel.show();
    delay(random(500,5000));
  }
}

