-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathLedStrip.cpp
More file actions
40 lines (31 loc) · 799 Bytes
/
LedStrip.cpp
File metadata and controls
40 lines (31 loc) · 799 Bytes
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
#include "LedStrip.h"
#include "Arduino.h"
LED_CONTROLLER_NAMESPACE_USING
LedStrip::LedStrip(int dataPin, int clockPin, bool reverse)
: dataPin(dataPin), clockPin(clockPin), reverse(reverse) { }
void LedStrip::setup() {
pinMode(dataPin, OUTPUT);
pinMode(clockPin, OUTPUT);
}
void LedStrip::clear() {
for(int i = 0; i < STRIP_LENGTH; i++) {
colors[i].clear();
}
}
void LedStrip::send() {
if (reverse) {
for(int i = STRIP_LENGTH-1; i >= 0; i--) {
colors[i].send(dataPin, clockPin);
}
} else {
for(int i = 0; i < STRIP_LENGTH; i++) {
colors[i].send(dataPin, clockPin);
}
}
// Pull clock low to put strip into reset/post mode.
digitalWrite(clockPin, LOW);
delayMicroseconds(500); // Wait for 500us to go into reset.
}
Color* LedStrip::getColors() {
return colors;
}