top of page

Follow the lights

Recreating a strange portion of the box - lights that turn off and on. It reminds me of the "lights out" puzzle, where pressing a button introduces a state change.


I haven't quite gotten it to work the way I've envisioned, but you can see a video and the code below.




#include <FastLED.h>
#define NUM_LEDS 10
#define DATA_PIN 31

// Define the array of leds
CRGB leds[NUM_LEDS];
const int lite = 3; 

//buttons
const int center = 7;
const int tl = 6;
const int tr = 5;
const int bl = 4;
const int br = 3;

void setup() { 
  delay( 3000 );
  FastLED.addLeds<WS2811, DATA_PIN, RGB>(leds, NUM_LEDS);
  FastLED.setBrightness( 10 );
  Serial.begin(9600);
  pinMode(center, INPUT_PULLUP);
  pinMode(tl, INPUT_PULLUP);
  pinMode(tr, INPUT_PULLUP);
  pinMode(bl, INPUT_PULLUP);
  pinMode(br, INPUT_PULLUP);
  
  for(int y = 0; y < NUM_LEDS; y++) {
    leds[y] = CRGB::Red;
    FastLED.show();
     }
}


int lightChange (int x, int a, int b, int c){
  if (digitalRead(x) == HIGH){
    if (leds[a] == CRGB::Red){ 
      leds[a] = CRGB::Green;
      FastLED.show();
    }
    else if (leds[a] == CRGB::Green){
      leds[a] = CRGB::Red;
      FastLED.show();
    }
    if (leds[b] == CRGB::Red){
      leds[b] = CRGB::Black;
      FastLED.show();
    }
    else if (leds[b] == CRGB::Green){
      leds[b] = CRGB::Red;
      FastLED.show();
    }
    
    if (leds[c] == CRGB::Red){
      leds[c] = CRGB::Black;
      FastLED.show();
    }
    else if (leds[c] == CRGB::Green){
      leds[c] = CRGB::Red;
      FastLED.show();
      }
  }
}
  
void loop() { 
  int cVal = analogRead(A2);
  delay(1);

  Serial.println(cVal);

  lightChange(7,1,3,4);
  lightChange(6,1,2,3);
  lightChange(5,3,8,7);
  lightChange(4,0,1,5);
  lightChange(3,5,6,7);

}

bottom of page