forked from RoboticsBrno/SmartLeds
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.cpp
More file actions
62 lines (53 loc) · 1.42 KB
/
main.cpp
File metadata and controls
62 lines (53 loc) · 1.42 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
#ifdef LX16A_ARDUINO
#include <Arduino.h>
#else
#include <freertos/FreeRTOS.h>
#include <freertos/task.h>
static void delay(int ms) { vTaskDelay(pdMS_TO_TICKS(ms)); }
static uint32_t millis() { return xTaskGetTickCount(); }
#endif
#include <SmartLeds.h>
const int LED_COUNT = 15;
const int DATA_PIN = 22;
const int CHANNEL = 0;
// SmartLed -> RMT driver (WS2812/WS2812B/SK6812/WS2813)
SmartLed leds(LED_WS2812B, LED_COUNT, DATA_PIN, CHANNEL, DoubleBuffer);
const int CLK_PIN = 23;
// APA102 -> SPI driver
//Apa102 leds(LED_COUNT, CLK_PIN, DATA_PIN, DoubleBuffer);
void setup() {}
uint8_t hue;
void showGradient() {
hue++;
// Use HSV to create nice gradient
for (int i = 0; i != LED_COUNT; i++)
leds[i] = Hsv { static_cast<uint8_t>(hue + 30 * i), 255, 255 };
leds.show();
// Show is asynchronous; if we need to wait for the end of transmission,
// we can use leds.wait(); however we use double buffered mode, so we
// can start drawing right after showing.
}
void showRgb() {
leds[0] = Rgb { 255, 0, 0 };
leds[1] = Rgb { 0, 255, 0 };
leds[2] = Rgb { 0, 0, 255 };
leds[3] = Rgb { 0, 0, 0 };
leds[4] = Rgb { 255, 255, 255 };
leds.show();
}
void loop() {
if (millis() % 10000 < 5000)
showGradient();
else
showRgb();
delay(50);
}
#ifndef ARDUINO
extern "C" void app_main() {
setup();
while (true) {
loop();
vTaskDelay(0);
}
}
#endif