-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathredlight.cpp
More file actions
42 lines (35 loc) · 887 Bytes
/
Copy pathredlight.cpp
File metadata and controls
42 lines (35 loc) · 887 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
#include "SK6812.h"
#define NUM_LEDS 119
#define DATA_PIN 4
#define HEARTBEAT_PIN A0
#define THRESHOLD 550
SK6812 strip(NUM_LEDS);
void setup() {
strip.set_output(DATA_PIN);
// Initialize all LEDs to off
RGBW black = {0, 0, 0, 0};
for (uint16_t i = 0; i < NUM_LEDS; i++) {
strip.set_rgbw(i, black);
}
strip.sync();
Serial.begin(9600);
}
void loop() {
int signal = analogRead(HEARTBEAT_PIN);
if (signal > THRESHOLD) {
// Set all LEDs to red when a heartbeat is detected
RGBW red = {0, 255, 0, 0};
for (uint16_t i = 0; i < NUM_LEDS; i++) {
strip.set_rgbw(i, red);
}
strip.sync();
} else {
// Set LEDs to a dim red when no heartbeat is detected
RGBW dimRed = {0, 50, 0, 0};
for (uint16_t i = 0; i < NUM_LEDS; i++) {
strip.set_rgbw(i, dimRed);
}
strip.sync();
}
delay(50); // Small delay for stability
}