-
Notifications
You must be signed in to change notification settings - Fork 9
/
pixels.h
85 lines (75 loc) · 2.07 KB
/
pixels.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
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
/*
* pixels.h
*
* WS2812 RGB LED library for ReSpeaker (ATmega32U4)
*
* Copyright (c) 2016 Seeed Technology Limited.
* MIT license
*
*/
#ifndef __PIXELS_H_
#define __PIXELS_H_
#include <avr/interrupt.h>
#include <avr/io.h>
#ifndef F_CPU
#define F_CPU 16000000UL
#endif
#include <util/delay.h>
#include <stdint.h>
#include <Arduino.h>
typedef union {
struct {
uint8_t b;
uint8_t g;
uint8_t r;
uint8_t a;
};
uint32_t c;
} color_t;
class Pixels {
public:
Pixels(uint16_t num_leds);
void begin(uint8_t pin);
void set_color(uint32_t rgb);
void set_color(uint16_t index, uint32_t rgb);
void set_color(uint16_t index, uint8_t r, uint8_t g, uint8_t b);
uint32_t get_color(uint16_t index);
void set_brightness(uint8_t level);
uint8_t get_brightness();
void clear();
void update();
uint16_t number() {
return leds_n;
}
static uint32_t RGB(uint8_t red, uint8_t green, uint8_t blue){
return ((uint32_t)red << 16) | ((uint32_t)green << 8) | blue;
};
static uint32_t wheel(uint8_t position) {
if(position < 85) {
return RGB(position * 3, 255 - position * 3, 0);
} else if(position < 170) {
position -= 85;
return RGB(255 - position * 3, 0, position * 3);
} else {
position -= 170;
return RGB(0, position * 3, 255 - position * 3);
}
}
void rainbow(uint8_t offset);
void scroll(uint32_t px_value, uint8_t time);
void scroll(uint8_t size, uint32_t px_value, uint8_t time);
void pass_by(uint8_t size, uint32_t px_value1, uint32_t px_value2, uint8_t time);
void blink(uint32_t px_value, uint8_t time, uint16_t index);
void blink(uint32_t px_value, uint8_t time);
void color_brush(uint32_t color, uint8_t time);
void theater_chase(uint32_t color, uint8_t time);
void theater_chase_rainbow(uint8_t time);
private:
uint8_t *pixels;
float brightness;
uint16_t leds_n;
uint32_t end_time;
const volatile uint8_t *port;
uint8_t pin_mask;
};
#endif /* __PIXELS_H_ */