-
Notifications
You must be signed in to change notification settings - Fork 0
/
RobotLights.cpp
65 lines (52 loc) · 1.67 KB
/
RobotLights.cpp
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
/*
* RobotLights.cpp
*
* Created on: 12 æîâò. 2016 ð.
* Author: snm
*/
#include "RobotLights.h"
RobotLights::RobotLights(uint8_t in_frontPin, uint8_t in_rearPin, uint8_t in_leftPin, uint8_t in_rightPin) {
frontPin = in_frontPin;
rearPin = in_rearPin;
pinMode(frontPin, OUTPUT);
pinMode(rearPin, OUTPUT);
// Initialize the NeoPixel objects
leftPix = new Adafruit_NeoPixel(3, in_leftPin, NEO_RGB + NEO_KHZ800);
rightPix = new Adafruit_NeoPixel(3, in_rightPin, NEO_RGB + NEO_KHZ800);
leftPix->begin();
rightPix->begin();
scheduleTimedTask(2000);
}
RobotLights::~RobotLights() {
}
void RobotLights::turnFrontLED(bool turnOn) {
digitalWrite(frontPin, turnOn);
}
void RobotLights::turnRearLED(bool turnOn) {
digitalWrite(rearPin, turnOn);
}
void RobotLights::turnSideLED(bool turnOn) {
sideLedsActive = turnOn;
}
void RobotLights::processTask() {
if(reachedDeadline()) {
// if the side lights turned on - light the LED's in random colors
if(sideLedsActive) {
leftPix->setPixelColor(0, random(0,255), random(0,255), random(0,255));
leftPix->setPixelColor(1, random(0,255), random(0,255), random(0,255));
leftPix->setPixelColor(2, random(0,255), random(0,255), random(0,255));
leftPix->show();
rightPix->setPixelColor(0, random(0,255), random(0,255), random(0,255));
rightPix->setPixelColor(1, random(0,255), random(0,255), random(0,255));
rightPix->setPixelColor(2, random(0,255), random(0,255), random(0,255));
rightPix->show();
} else {
// turn off the LEDS
leftPix->clear();
leftPix->show();
rightPix->clear();
rightPix->show();
}
scheduleTimedTask(LED_DELAY);
}
}