-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathLeds.h
97 lines (81 loc) · 2.52 KB
/
Leds.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
//#include <wprogram.h>
//#include <wiring_private.h>
//#include <pins_arduino.h>
class Leds{
private:
int* objectLedsPins;
int objectLedsState[NUM_LEDS];
int numLedsEnabled;
/*int digitalReadOutputPin(uint8_t pin)
{
uint8_t bit = digitalPinToBitMask(pin);
uint8_t port = digitalPinToPort(pin);
if (port == NOT_A_PIN)
return LOW;
return (*portOutputRegister(port) & bit) ? HIGH : LOW;
}*/
public:
Leds(int* _objectLedsPins) {
//Leds(int _numRoutes, int _numRouteSteps) {
objectLedsPins = _objectLedsPins;
numLedsEnabled = 0; //starting at 1 for start object selection led
for(int i=0;i<NUM_LEDS;i++) {
int ledPin = objectLedsPins[i];
pinMode(ledPin, OUTPUT);
digitalWrite(ledPin,LOW);
objectLedsState[i] = 0;
}
//Serial.println(numLedsEnabled);
}
void enableObject(int object) {
//Serial.println(numLedsEnabled);
int ledPin = objectLedsPins[object];
if(objectLedsState[object] == 1 || numLedsEnabled > MAX_ENABLED_LEDS) return;
#ifndef DISABLE_LEDS
digitalWrite(ledPin, HIGH);
#endif
objectLedsState[object] = 1;
numLedsEnabled++;
#ifdef DEBUG_LEDS
Serial.print(" led: ");
Serial.println(ledPin);
//Serial.print(' ');
//Serial.println(numLedsEnabled);
#endif
}
void disableObject(int object) {
//Serial.println(numLedsEnabled);
int ledPin = objectLedsPins[object];
if(objectLedsState[object] == 0) return;
digitalWrite(ledPin, LOW);
objectLedsState[object] = 0;
numLedsEnabled--;
#ifdef DEBUG_LEDS
Serial.print(" led disable : ");
Serial.println(ledPin);
//Serial.print(' ');
//Serial.println(numLedsEnabled);
#endif
}
void disableAllObjects() {
for(int i=0;i<NUM_LEDS;i++) {
int ledPin = objectLedsPins[i];
if(objectLedsState[i] == 0) continue;
digitalWrite(ledPin, LOW);
objectLedsState[i] = 0;
numLedsEnabled--;
}
#ifdef DEBUG_LEDS
Serial.println(" led disable all ");
//Serial.println(numLedsEnabled);
#endif
}
/*void lightStartObjectSelection(int selectedStartObject) {
for(int i=0;i<NUM_START_OBJECTS;i++) {
//int startObject = objectLedsPins[]
digitalWrite(startObjectLedsPins[i],(i == selectedStartObject)? HIGH : LOW);
}
}*/
void update() {
}
};