53 lines
1.1 KiB
C

#include <FastLED.h>
#define NUM_LEDS 16
#define DATA_PIN 8 // Change to your actual data pin
CRGB leds[NUM_LEDS];
void fastled_color(int start, int end, byte r, byte g, byte b, byte brightness) {
if (start < 0) start = 0;
if (end >= NUM_LEDS) end = NUM_LEDS - 1;
CHSV hsv = rgb2hsv_approximate(CRGB(r, g, b));
hsv.value = brightness;
for (int i = start; i <= end; i++) {
leds[i] = hsv;
}
}
void fastled_begin() {
FastLED.addLeds<WS2812B, DATA_PIN, GRB>(leds, NUM_LEDS);
FastLED.clear();
FastLED.show();
}
void fastled_show() {
FastLED.show();
}
// Example health bar functions
void red_health(uint8_t value, uint8_t brightness) {
fastled_color(0, value-1, 255, 0, 0, brightness);
}
void blue_health(uint8_t value, uint8_t brightness) {
fastled_color(8, 8+value-1, 0, 0, 255, brightness); // Adjust if you want a different range
}
void crossfade_red() {
for(int i=10; i<=60; i++){
red_health(4, i);
fastled_show();
delay(20);
}
for(int i=60; i>=10; i--) {
red_health(4, i);
fastled_show();
delay(20);
}
}