-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathArduino_serial_reader.cpp
65 lines (52 loc) · 1.65 KB
/
Arduino_serial_reader.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
#include <Keyboard.h>
/* Teensy/Arduino Program -GITHUB*/
#define MODE_SERIAL 0
#define MODE_COMMAND 1
// Pin 13 has the LED on Teensy 3.0 -GITHUB
int led = 13;
int serialbaud;
int32_t time=0;
int mode, debug;
int pluscount, buffercount;
char buffer[8];
// the setup routine runs once when you press reset: -GITHUB
void setup() {
// initialize the digital pin as an output.
pinMode(led, OUTPUT);
Serial.begin(115200);
delay(2000);
serialbaud = 115200;
Serial1.begin(serialbaud);
// serialbaud = Serial1.baud();
Serial.print("Teensy USBSerial ");
Serial.print(serialbaud);
mode = MODE_SERIAL;
}
// the loop routine runs over and over again forever: -GITHUB
void loop() {
/* loop through 4 possible serverrequests -GITHUB*/
/* Scan data and commands from USB serial -GITHUB */
while (Serial.available())
{
char c = Serial.read();
Serial1.write(c);
}
/* Scan data and commands from hardware serial, ESP8266 module, using special scanner -GITHUB*/
while (Serial1.available())
{
char inch = Serial1.read();
Keyboard.write(inch);
Serial.write(inch);
}
/* Adapt hardware serrial baud to baudrate given for SUB serial adapter -GITHUB*/
if (serialbaud != Serial.baud())
{
serialbaud = Serial.baud();
//Serial1.begin(serialbaud);
Serial.print("Teensy USBSerial ");
Serial.print(serialbaud);
}
/* Blink some status lights */
if (Serial.dtr()) digitalWrite(led, (millis()/500)&1); // 1 second blinks when USB serial is attaced, dtr is asserted -GITHUB
else digitalWrite(led, (millis()/2000)&1); // 4 second slow blink when not dtr
}