forked from aetios50/PincabLedStrip
-
Notifications
You must be signed in to change notification settings - Fork 2
/
LedStrip.h
125 lines (97 loc) · 2.94 KB
/
LedStrip.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
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
#ifndef LedStrip_h
#define LedStrip_h
#include <Arduino.h>
#ifndef DEBUG_ON_WIFI
#define FASTLED_ALLOW_INTERRUPTS 0
#endif
#include <FastLED.h>
FASTLED_USING_NAMESPACE
//#define LED_TYPE WS2811
//#define LED_TYPE WS2812
#define LED_TYPE WS2812B
//#define LED_TYPE WS2813
//#define COLOR_ORDER RGB
#define COLOR_ORDER GRB
/************* VALUE TO CHANGE *******************/
//Defines the number of ledstrip
#define NUMBER_LEDSTRIP 8
#define TEENSY (defined(__MK20DX128__) || defined(__MK20DX256__) || defined(__MK64FX512__) || defined(__MK66FX1M0__) || defined(__MKL26Z64__) || defined (__IMXRT1062__))
#if defined(ESP8266)
//Defines the max number of ledstrip which is allowed per ledstrip.
#define MaxLedsPerStrip 1200
//Ports in configtool vs ports in wemos
//Configtool ===== Wemos
//1 ===== D5
//4 ===== D6
//7 ===== D7
//10 ===== D8
//13 ===== D1
//16 ===== D4
//19 ===== D2
//22 ===== D3
#define DATA_PIN1 D5
#define DATA_PIN2 D6
#define DATA_PIN3 D7
#define DATA_PIN4 D8
#define DATA_PIN5 D1
#define DATA_PIN6 D4
#define DATA_PIN7 D2
#define DATA_PIN8 D3
#elif defined(ESP32)
//Defines the max number of ledstrip which is allowed per ledstrip.
#define MaxLedsPerStrip 1200
#define DATA_PIN1 7
#define DATA_PIN2 9
#define DATA_PIN3 11
#define DATA_PIN4 12
#define DATA_PIN5 35
#define DATA_PIN6 16
#define DATA_PIN7 33
#define DATA_PIN8 18
#elif TEENSY
//Defines the max number of ledstrip which is allowed per ledstrip.
#define MaxLedsPerStrip 1200
#define DATA_PIN1 2
#define DATA_PIN2 14
#define DATA_PIN3 7
#define DATA_PIN4 8
#define DATA_PIN5 6
#define DATA_PIN6 20
#define DATA_PIN7 21
#define DATA_PIN8 5
#else
#error "Unsupported Card Model"
#endif
#define HALF_BRIGHTNESS 128 // Defines Brightness in RGB boot sequence - 16 its the minimum (1-15 strip don't iluminate at all)
#define FULL_BRIGHTNESS 255 // Defines Brightness in pin 1 (0 to 255)
/************* END VALUE TO CHANGE *******************/
class LedStrip {
public:
LedStrip(uint32_t numPerStrip);
void begin(void);
void reset();
void addNewStrip(uint8_t index, uint16_t length);
void setStripLength(uint16_t length);
void setStripBrightness(uint8_t index, uint8_t brightness);
void clearAll();
void setPixels(uint32_t start_num, uint16_t len, int color);
void setPixel(uint32_t num, int color);
void setPixel(uint32_t num, uint8_t red, uint8_t green, uint8_t blue) {
setPixel(num, color(red, green, blue));
}
CRGB& getPixel(uint32_t num);
void show(void);
int busy(void);
int numPixels(void) {
return stripTotalLen * 8;
}
int color(uint8_t red, uint8_t green, uint8_t blue) {
return (red << 16) | (green << 8) | blue;
}
private:
static uint16_t stripTotalLen;
static uint16_t stripLen[NUMBER_LEDSTRIP];
static uint16_t stripStartOffset[NUMBER_LEDSTRIP];
static uint8_t stripIndex[NUMBER_LEDSTRIP * MaxLedsPerStrip];
};
#endif