-
Notifications
You must be signed in to change notification settings - Fork 1
/
sketch_oct14a.ino
57 lines (44 loc) · 1.48 KB
/
sketch_oct14a.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
// Arduino Nano clone windowsdriver=«USB-SERIAL CH340» Processor=328P(Old) Board=«Arduino Duomilanove» Programmer=«Arduino As ISP»
/* DmxSimple is compatible with the Tinker.it! DMX shield and all known DIY Arduino DMX control circuits.
** DmxSimple is available from: http://code.google.com/p/tinkerit/
** Help and support: http://groups.google.com/group/dmxsimple */
// Due to the small amount of RAM on 168 and Mega8 Arduinos, only the first 128 channels are supported.
// Arduinos with processor sockets can easily be upgraded to a 328 to control all 512 channels.
// Timer 2 is used.
#include <DmxSimple.h>
#define MAXCH 50
unsigned long waiting=0;
void setup() {
// put your setup code here, to run once:
DmxSimple.maxChannel(MAXCH);
DmxSimple.usePin(3);
Serial.begin(9600);
}
void loop() {
// put your main code here, to run repeatedly:
if (Serial.available() >= 2) {
byte channel = Serial.read();
if (channel>MAXCH) {
Serial.print("INVALID");
Serial.println(channel);
}
else {
byte value = Serial.read();
DmxSimple.write(channel, value);
// Serial.print("OK");
// Serial.print(channel);
// Serial.print("=");
// Serial.println(value);
waiting = 0;
}
}
else if (Serial.available() == 1) {
waiting += 1;
}
if (waiting>50000) {
byte discarded = Serial.read();
Serial.print("DISCARDED");
Serial.println(discarded);
waiting = 0;
}
} // ...loop