-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathLightControl.cpp
84 lines (76 loc) · 1.74 KB
/
LightControl.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
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
/*
* LightControl.cpp
*
* Created on: 01.10.2012
* Author: mse
*/
#include <Arduino.h>
#include "LightControl.h"
#include "StaticLightControlStrategy.h"
#include "AudioAnalyser.h"
#include "LightorganStrategy.h"
#include <SerialDebug.h>
LightControl::LightControl() {
//analog read on Pin 1
buttonEvent = new ButtonEvent(1);
buttonEvent->registerCallBackEventHandler(this);
analyser = new AudioAnalyser();
lightorganStrategy = new LightorganStrategy(analyser);
staticStrategy1 = new StaticLightControlStrategy(
ILightControlStrategy::COLOR_BLUE);
staticStrategy2 = new StaticLightControlStrategy(
ILightControlStrategy::COLOR_RED);
staticStrategy3 = new StaticLightControlStrategy(
ILightControlStrategy::COLOR_BLUE_GREEN);
state = LIGHTORGAN;
}
LightControl::~LightControl() {
delete buttonEvent;
delete analyser;
delete lightorganStrategy;
delete staticStrategy1;
delete staticStrategy2;
delete staticStrategy3;
}
void LightControl::testSpotlight() {
for (int aa = 2; aa < 14; aa++) {
pinMode(aa, OUTPUT);
digitalWrite(aa, HIGH);
delay(500);
digitalWrite(aa, LOW);
}
}
void LightControl::onLoop() {
buttonEvent->readAndDispatch();
char buffer[50];
sprintf(buffer, "State: %d", state);
SerialDebugger.debug(STATUSUPDATE, "onLoop", buffer);
switch (state) {
case LIGHTORGAN:
if (lightorganStrategy != 0) {
lightorganStrategy->show();
}
break;
case STATIC_BLUE:
if (staticStrategy1 != 0) {
staticStrategy1->show();
}
break;
case STATIC_RED:
if (staticStrategy2 != 0) {
staticStrategy2->show();
}
break;
case STATIC_GREEN:
if (staticStrategy3 != 0) {
staticStrategy3->show();
}
break;
}
}
void LightControl::handleEvent(int event) {
state++;
if (state == 4) {
state = 0;
}
}