Quartz Components
Published © GPL3+

DIY Real-Time Ambient Lighting Sync System Using Arduino

Build a real-time ambient lighting system with Arduino Nano & WS2812B LEDs that sync instantly with your monitor.

BeginnerFull instructions provided1 hour57
DIY Real-Time Ambient Lighting Sync System Using Arduino

Things used in this project

Hardware components

Arduino Nano R3
Arduino Nano R3
×1
WS2812 Addressable LED Strip
Digilent WS2812 Addressable LED Strip
×1

Software apps and online services

prismatik
Arduino IDE
Arduino IDE

Story

Read more

Schematics

Schemetic Diagram

Code

Real-Time Ambient Lighting System

C/C++
#define NUM_LEDS 65
#define DATA_PIN 6
#define serialRate 115200

uint8_t prefix[] = {'A', 'd', 'a'}, hi, lo, chk, i;

CRGB leds[NUM_LEDS];

void setup() {
FastLED.addLeds(leds, NUM_LEDS);

FastLED.showColor(CRGB(255, 0, 0)); delay(500);
FastLED.showColor(CRGB(0, 255, 0)); delay(500);
FastLED.showColor(CRGB(0, 0, 255)); delay(500);
FastLED.showColor(CRGB(0, 0, 0));

Serial.begin(serialRate);
Serial.print("Ada\n");
}

void loop() {
for(i = 0; i < sizeof prefix; ++i) {
waitLoop: while (!Serial.available());
if(prefix[i] == Serial.read()) continue;
i = 0;
goto waitLoop;
}

while (!Serial.available());
hi = Serial.read();
while (!Serial.available());
lo = Serial.read();
while (!Serial.available());
chk = Serial.read();

if (chk != (hi ^ lo ^ 0x55)) {
i = 0;
goto waitLoop;
}

memset(leds, 0, NUM_LEDS * sizeof(struct CRGB));

for (uint8_t i = 0; i < NUM_LEDS; i++) {
byte r, g, b;
while(!Serial.available()); r = Serial.read();
while(!Serial.available()); g = Serial.read();
while(!Serial.available()); b = Serial.read();
leds[i].r = r;
leds[i].g = g;
leds[i].b = b;
}

FastLED.show();
} 

Credits

Quartz Components
6 projects • 5 followers
Quartz Components builds robotics, IoT, AI hardware, Arduino, ESP32, automation, sensors, and innovative DIY electronics projects.

Comments