-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathneoPixel.cpp
More file actions
128 lines (109 loc) · 2.85 KB
/
neoPixel.cpp
File metadata and controls
128 lines (109 loc) · 2.85 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
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
126
127
128
#include "neoPixel.h"
//////////////////////////////////////////////////////////////////////
// Global variables
//////////////////////////////////////////////////////////////////////
Adafruit_NeoPixel pixels(1, PIN_NEOPIXEL, NEO_GRB + NEO_KHZ800);
neoPixelBlinker _neoPixelBlinker;
neoPixelBlinker::neoPixelBlinker() {
}
void neoPixelBlinker::blink(int hexIn) {
// Serial.print(F("-----");
// Serial.print(F("NeoPixel on..."));
// Serial.println(_hex);
if (_hex == 0x000000)
_hex = hexIn;
else
_hex = 0x000000;
_pixels.fill(_hex);
_pixels.show();
};
void neoPixelBlinker::blink(int timestamp, int delayMs) {
bool blink = false;
unsigned int delta = timestamp - _timestamp;
if (delta > delayMs) {
blink = true;
_timestamp = timestamp;
}
if (blink) {
// Serial.print(F("-----"));
// Serial.println(_count);
if (_count % 1 == 0) {
// Serial.print(F("NeoPixel on..."));
// Serial.println(_hex);
_hex = cycle(_hex);
}
if (_count % 2 == 0) {
_count = 0;
off();
// Serial.println(F("NeoPixel off..."));
}
_count++;
}
};
int neoPixelBlinker::cycle(int hexIn) {
// Serial.println(hexIn);
if (hexIn != 0xFF000 && hexIn != 0x00FF00 && hexIn != 0x0000FF)
hexIn = 0xFF0000;
// Serial.println(hexIn);
int hex = hexIn;
if (hexIn == 0xFF0000)
hex = 0x00FF00;
else if (hexIn == 0x00FF00)
hex = 0x0000FF;
else if (hexIn == 0x0000FF)
hex = 0xFF0000;
// Serial.println(hex);
_pixels.fill(hex);
_pixels.show();
return hex;
};
void neoPixelBlinker::init(Adafruit_NeoPixel pixels) {
_pixels = pixels;
_pixels.begin(); // INITIALIZE NeoPixel strip object (REQUIRED)
_pixels.setBrightness(5);
off();
// _delayMs = delayMs;
}
void neoPixelBlinker::init(Adafruit_NeoPixel pixels, int brightness) {
_pixels = pixels;
_pixels.begin(); // INITIALIZE NeoPixel strip object (REQUIRED)
_pixels.setBrightness(brightness);
off();
// _delayMs = delayMs;
}
void neoPixelBlinker::off() {
_pixels.fill(0x000000);
_pixels.show();
};
void neoPixelBlinker::setup() {
_neoPixelBlinker.init(pixels);
}
void neoPixelBlinker::setupDeinit() {
_neoPixelBlinker.off();
}
neoPixel::neoPixel() {
}
void neoPixel::off(Adafruit_NeoPixel pixels) {
pixels.fill(0x000000);
pixels.show();
}
void neoPixel::on(Adafruit_NeoPixel pixels, int hex) {
pixels.fill(hex);
pixels.show();
}
void neoPixel::sleep() {
pinMode(NEOPIXEL_POWER, OUTPUT);
}
void neoPixel::sleepHold() {
gpio_hold_en((gpio_num_t)NEOPIXEL_POWER);
}
void neoPixel::setup(Adafruit_NeoPixel pixels) {
pixels.begin(); // INITIALIZE NeoPixel strip object (REQUIRED)
pixels.setBrightness(25);
pixels.fill(0x000000);
pixels.show();
}
void neoPixel::setup(Adafruit_NeoPixel pixels, int brightness) {
pixels.begin(); // INITIALIZE NeoPixel strip object (REQUIRED)
pixels.setBrightness(brightness);
}