forked from RoboticsBrno/SmartLeds
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbasicExample.ino
More file actions
48 lines (40 loc) · 1.16 KB
/
basicExample.ino
File metadata and controls
48 lines (40 loc) · 1.16 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
#include <Arduino.h>
#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_WS2812, 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() {
Serial.begin(9600);
}
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() {
Serial.println("New loop");
if ( millis() % 10000 < 5000 )
showGradient();
else
showRgb();
delay( 50 );
}