-
Notifications
You must be signed in to change notification settings - Fork 0
/
EMG_LEDs.ino
48 lines (36 loc) · 1.13 KB
/
EMG_LEDs.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
/* Code to turn the LEDS on or off depending on received serial commands. Modified from Arduino examples. */
int incomingByte; // variable to read serial data into
int redPin = 8;
int yellowPin = 7;
int bluePin = 12;
void setup() {
// initialize serial communication
Serial.begin(9600);
// set LED pins as outputs
pinMode(redPin, OUTPUT);
pinMode(yellowPin, OUTPUT);
pinMode(bluePin, OUTPUT);
digitalWrite(bluePin, HIGH); // initialize to blue
}
void loop() {
// check if there's incoming data
if (Serial.available() > 0) {
// read the oldest byte in the buffer:
incomingByte = Serial.read();
if (incomingByte == 'Y') {
digitalWrite(yellowPin, HIGH); // yellow
digitalWrite(redPin, LOW);
digitalWrite(bluePin, LOW);
}
if (incomingByte == 'R') {
digitalWrite(redPin, HIGH); // red
digitalWrite(bluePin, LOW);
digitalWrite(yellowPin, LOW);
}
if (incomingByte == 'B') {
digitalWrite(bluePin, HIGH); // blue
digitalWrite(redPin, LOW);
digitalWrite(yellowPin, LOW);
}
}
}