-
Notifications
You must be signed in to change notification settings - Fork 0
/
wio_dmx.ino
128 lines (105 loc) · 2.5 KB
/
wio_dmx.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
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
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
/*
* DMX Monitor
*
* Board: Seeeduino Wio Terminal
*
* Library:
* https://github.com/lovyan03/LovyanGFX
*/
#include "SAMD51_TC.h"
#include "DMX.h"
//#include "TFT_eSPI.h"
//TFT_eSPI tft;
#define LGFX_WIO_TERMINAL
#define LGFX_USE_V1
#include "LovyanGFX.h"
#include "LGFX_AUTODETECT.hpp"
static LGFX tft;
DMX dmx;
volatile int timeout = 0;
int mode = 0, page = 0;
char rdm_uid[] = {0x7f, 0xf7, 0x00, 0x12, 0x34, 0x56};
unsigned char rdm_uid_buf[20][6];
void wait_us (int us) {
delayMicroseconds(us);
}
void draw_dmx (int offset, int refresh) {
int i, d, n, x, y, z;
tft.startWrite();
tft.setTextDatum(textdatum_t::top_left);
if (refresh) {
tft.fillScreen(TFT_BLACK);
tft.setFont(&fonts::Font2);
tft.setTextColor(TFT_GREEN);
tft.setCursor(4, 4);
tft.printf("DMX Monitor");
for (i = 1; i < 10; i ++) {
x = 32 * i;
tft.drawLine(x, 30, x, 239, TFT_DARKGREY);
}
for (i = 0; i < 7; i ++) {
y = 30 + 30 * i;
tft.drawLine(0, y, 319, y, TFT_DARKGREY);
if (i < 10) {
}
}
}
for (i = 0; i < 70; i ++) {
n = offset + i;
x = 32 * (i % 10);
y = 30 + 30 * (i / 10);
if (n < 512) {
d = dmx.get(n);
if (refresh) {
tft.setFont(&fonts::Font0);
tft.setTextColor(TFT_GREENYELLOW);
tft.setCursor(x + 2, y + 2);
tft.printf("%d", n);
} else {
tft.fillRect(x + 1, y + 12, 31, 17, TFT_BLACK);
}
tft.setFont(&fonts::Font2);
tft.setTextColor(TFT_WHITE);
tft.setCursor(x + 5, y + 12);
tft.printf("%3d", d);
z = (d * 31) / 255;
if (d > 0) {
tft.fillRect(x + 1, y + 27, z, 2, TFT_GREEN);
}
}
}
tft.endWrite();
}
void setup() {
Serial.begin(115200);
pinMode(WIO_5S_UP, INPUT_PULLUP);
pinMode(WIO_5S_DOWN, INPUT_PULLUP);
pinMode(PIN_LED, OUTPUT);
digitalWrite(PIN_LED, LOW);
tft.begin();
tft.setRotation(1); // 320 x 240
tft.fillScreen(TFT_BLACK);
tft.drawString("DMX", 10, 10);
dmx.init();
draw_dmx(0, 1);
}
void loop() {
if (dmx.isReceived()) {
digitalWrite(PIN_LED, HIGH);
draw_dmx(page * 10, 0);
digitalWrite(PIN_LED, LOW);
}
if ((digitalRead(WIO_5S_UP) == LOW) && (page > 1)) {
page -= 3;
if (page < 0) page = 0;
draw_dmx(page * 10, 1);
while (digitalRead(WIO_5S_UP) == LOW);
}
if ((digitalRead(WIO_5S_DOWN) == LOW) && (page < 45)) {
page += 3;
if (page > 45) page = 45;
draw_dmx(page * 10, 1);
while (digitalRead(WIO_5S_DOWN) == LOW);
}
delay(10);
}