-
Notifications
You must be signed in to change notification settings - Fork 0
/
LedFlow.ino
69 lines (54 loc) · 1.96 KB
/
LedFlow.ino
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
#include <LinkedList.h>
#include <StaticThreadController.h>
#include <Thread.h>
#include <ThreadController.h>
#include "EventReceiver.h"
#include "StatusConverter.h"
#include "LEDArranger.h"
#include "LightController.h"
#include "ShiftRegisterController.h"
#include "PitchToKeyboardConverter.h"
#include "Debug.h"
EventReceiver eventReceiver;
StatusConverter statusConverter = StatusConverter(11, 10, 7, 6); // whiteLength, whiteDestination, blackLength, blackDestination
LEDArranger lEDArranger = LEDArranger(&statusConverter);
LinkedList<Pair> lightStatus;
ShiftRegisterController shiftRegisterController = ShiftRegisterController(8, 12, 11, 32, 11); // latch, clock, data, keyAmount, ledLength
PitchToKeyboardConverter pitchToKeyboardConverter = PitchToKeyboardConverter(52, 83); // minPitch, maxPitch
LightController lightController = LightController(&shiftRegisterController, &pitchToKeyboardConverter);
ThreadController threadController;
Thread updateThread;
Thread runThread;
//int debugb = 0;
void updateCallback(){
//thread1
eventReceiver.Receive();
lEDArranger.AddEvents(eventReceiver.Pop());
lEDArranger.Update();
lEDArranger.Arrange(&lightStatus);
lightController.Update(&lightStatus);
#ifdef _DEBUG_MODE
if(lightStatus.size() > 0) DEBUG_PRINTLN(lightStatus.size());
for(int i = 0; i < lightStatus.size(); i++){
String debugLine = String("") + lightStatus.get(i).first + " " + lightStatus.get(i).second + ",";
DEBUG_PRINT(debugLine);
}
if(lightStatus.size() > 0) DEBUG_PRINTLN("");
#endif
}
void runCallback(){
//thread2
lightController.Run();
}
void setup() {
Serial.begin(9600);
updateThread.onRun(updateCallback);
updateThread.setInterval(100);
runThread.onRun(runCallback);
runThread.setInterval(1);
threadController.add(&updateThread);
threadController.add(&runThread);
}
void loop() {
threadController.run();
}