-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdisplay.cpp
More file actions
74 lines (57 loc) · 1.98 KB
/
display.cpp
File metadata and controls
74 lines (57 loc) · 1.98 KB
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
68
69
70
71
72
73
74
#include "display.h"
#include <EEvar.h>
const EEstore<uint8_t> eeBrightness = 96;
CRGB leds[NUM_LEDS];
void initDisplay() {
FastLED.addLeds<WS2812B,LED_PIN,GRB>(leds,NUM_LEDS).setCorrection(TypicalLEDStrip);
uint8_t brightness;
eeBrightness >> brightness;
FastLED.setBrightness(brightness);
}
void clearDisplay() {
memset(leds, CRGB::Black, NUM_LEDS * sizeof(CRGB));
FastLED.show();
}
void setBrightness(uint8_t brightness) {
eeBrightness << brightness;
FastLED.setBrightness(brightness);
}
void drawPixels(fixed cellsA[SIM_DIM][SIM_DIM], fixed cellsB[SIM_DIM][SIM_DIM]) {
for (uint8_t i = 0, idx = 0; i < SIM_DIM; i++) {
for (uint8_t j = 0; j < SIM_DIM; j++, idx++) {
float a = float(cellsA[i][j]);
float b = float(cellsB[i][j]);
float f = a - b;
uint8_t hue = 80.0 + f * 80.0;
leds[idx] = CHSV(hue, uint8_t(constrain((a+b) * 255.0, 0.0, 255.0)), 64);
}
}
FastLED.show();
}
void drawValue(fixed value, fixed min, fixed max, CRGB color, const bool *name, CRGB name_color) {
fixed led_count = (value - min) / (max - min) * fixed(NUM_LEDS);
for (uint8_t idx = 0; idx < led_count.getInteger(); idx++) {
leds[idx] = color;
}
fixed fraction = led_count - led_count.getInteger();
CHSV hsv = rgb2hsv_approximate(color);
hsv.value = uint8_t(fixed(hsv.value) * fraction);
leds[led_count.getInteger()] = hsv;
for (uint8_t idx = led_count.getInteger() + 1; idx < NUM_LEDS; idx++) {
leds[idx] = CRGB::Black;
}
if (name) {
for (uint8_t idx = 0; idx < NUM_LEDS; idx++) {
bool on = pgm_read_byte_near(name + idx);
if (on) leds[idx] = name_color;
}
}
FastLED.show();
}
void drawName(const bool *name, CRGB color, CRGB bg_color) {
for (uint8_t idx = 0; idx < NUM_LEDS; idx++) {
bool on = pgm_read_byte_near(name + idx);
leds[idx] = on ? color : bg_color;
}
FastLED.show();
}