forked from BanditsTerrificTravelPad/bttp-firmware
-
Notifications
You must be signed in to change notification settings - Fork 0
/
led.h
67 lines (55 loc) · 1.58 KB
/
led.h
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
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
#ifndef BTTP_LED
#define BTTP_LED
#ifdef LEDS
#include <Arduino.h>
#include <FastLED.h>
#include "config.h"
CRGBArray<NUM_LEDS> leds;
uint64_t currentMillis = 0;
// Get the LED offset for a given pad index
uint8_t getLEDStartForPad(uint8_t padIndex) {
for (int i = 0; i < NUM_STEPS; i++) {
if (PAD_LED_ORDER[i] == padIndex) {
return i * NUM_LEDS_PER_STEP;
}
}
}
// defaunt rainbow-y sorta effect
void gamerIdle(uint8_t padIndex, double rate) {
uint32_t colorOffset = currentMillis * rate;
uint8_t ledStartIndex = getLEDStartForPad(padIndex);
for (int i = 0; i < NUM_LEDS_PER_STEP; i++) {
leds[i + ledStartIndex] =
CHSV(((i * 255) / NUM_LEDS_PER_STEP) + colorOffset, 255,
255 * LED_IDLE_BRIGHTNESS);
}
FastLED.show();
}
// handle showing the non-pressed pad lights
void showIdle(uint8_t padIndex) { gamerIdle(padIndex, 0.05); }
// handle showing the pressed pad light
void showActive(uint8_t padIndex) {
CRGB color = CRGB(LED_ACTIVE_COLOR * LED_ACTIVE_BRIGHTNESS);
leds(getLEDStartForPad(padIndex), getLEDStartForPad(padIndex) + NUM_LEDS_PER_STEP - 1).fill_solid(color);
FastLED.show();
}
void setupLights() {
FastLED.addLeds<LED_TYPE, DATA_PIN, LED_COLOR_ORDER>(leds, NUM_LEDS)
.setCorrection(TypicalLEDStrip);
}
void tickLights() {
currentMillis = millis();
for (uint8_t i = 0; i < NUM_STEPS; i++) {
if (padPressed[i]) {
showActive(i);
} else {
showIdle(i);
}
}
}
#else
// LEDs disabled
void setupLights() {}
void tickLights() {}
#endif
#endif