This repository has been archived by the owner on Dec 25, 2018. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathled.cpp
57 lines (43 loc) · 1.49 KB
/
led.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
#include "led.h"
#include "flasher.h"
#include "constants.h"
#include "logger.h"
#include <Arduino.h>
namespace led {
namespace {
const uint8_t VCC_PWM = 105; //Value to adjust for optimal 2V output voltage
//Array keeping track of states
bool states[constants::NUMBER_OF_LEDS];
}
void shiftOut() {
//Latch Low. VCC high
digitalWrite(constants::P_LED_VCC, HIGH);
digitalWrite(constants::P_LED_LATCH, LOW);
//Shift out
for (uint8_t i = constants::NUMBER_OF_LEDS; i <= constants::NUMBER_OF_LEDS; i--) {
digitalWrite(constants::P_LED_DATA, states[i]);
//Clock
digitalWrite(constants::P_LED_CLOCK, HIGH);
digitalWrite(constants::P_LED_CLOCK, LOW);
}
//If data is left on high drop to low, so that the final output voltage is not altered
digitalWrite(constants::P_LED_DATA, LOW);
//Latch high. VCC adjust to two volts
digitalWrite(constants::P_LED_LATCH, HIGH);
analogWrite(constants::P_LED_VCC, VCC_PWM);
}
void turnOn(uint8_t ledNumber) {
logger::log(logger::TYPE_INFO, "led", "Set led number " + String(ledNumber) + " ON");
states[ledNumber] = HIGH;
}
void turnOff(uint8_t ledNumber) {
logger::log(logger::TYPE_INFO, "led", "Set led number " + String(ledNumber) + " OFF");
states[ledNumber] = LOW;
}
void setup() {
pinMode(constants::P_LED_VCC, OUTPUT);
pinMode(constants::P_LED_DATA, OUTPUT);
pinMode(constants::P_LED_CLOCK, OUTPUT);
pinMode(constants::P_LED_LATCH, OUTPUT);
}
}