-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathLabChartSync.ino
More file actions
executable file
·61 lines (50 loc) · 1.41 KB
/
LabChartSync.ino
File metadata and controls
executable file
·61 lines (50 loc) · 1.41 KB
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
// SIGNAL VARIABLES
const int signalPins[8] = {0,1,2,3,4,5,6,7};
int signalNo = 0;
const long lagTime = 3064; // ms
// SERIAL COMMUNICATION VARIABLES
String pythonSays; // for reading commands from python
const bool echoSerial = true; //send back to python any commands received
const int serialBaudRate = 9600; // should match python
const int serialTimeOut = 10; // ms
void setup() {
for (int i=0; i<8; i++) {
pinMode(signalPins[i],OUTPUT);
digitalWrite(signalPins[i],LOW);
}
Serial.begin(serialBaudRate);
Serial.setTimeout(serialTimeOut);
}
void loop() {
while (Serial.available() <= 0) {
// wait for serial input
}
// get instructions from python over serial connection
pythonSays = Serial.readString();
// CHECK SERIAL CONNECTION
if (pythonSays == "ping") {
Serial.println("ack");
// SIGNALS
} else if (pythonSays == "signal") {
signalNo = serial_get_int(echoSerial);
delay(lagTime);
digitalWrite(signalPins[signalNo],HIGH);
delay(1000);
digitalWrite(signalPins[signalNo],LOW);
// UNRECOGNISED INSTRUCTIONS
} else {
Serial.print("I don't understand: ");
Serial.println(pythonSays);
}
}
// FUNCTIONS
int serial_get_int(boolean echo){
if (echo) Serial.println(pythonSays);
int serialInt;
while (Serial.available() <= 0){
// wait
}
serialInt = Serial.parseInt();
if (echo) Serial.println(serialInt);
return serialInt;
}