-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathControlling an Arduino from Unity LED
More file actions
47 lines (37 loc) · 1.12 KB
/
Copy pathControlling an Arduino from Unity LED
File metadata and controls
47 lines (37 loc) · 1.12 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
Once the circuit has been created, you’ll need to open the RYG.ino file in Arduino and compile, then upload it.
This is just a simple script that will change the LEDs over every second and make sure that the circuit is correct.
Around this point you should note the COM port the Arduino is on (Tools/Serial Port).
int gLed = 10;
int yLed = 11;
int rLed = 12;
char myCol[20];
void setup() {
// put your setup code here, to run once:
Serial.begin(9600);
pinMode(gLed, OUTPUT);
pinMode(yLed, OUTPUT);
pinMode(rLed, OUTPUT);
digitalWrite(gLed, LOW);
digitalWrite(yLed, LOW);
digitalWrite(rLed, LOW);
}
void loop() {
// put your main code here, to run repeatedly:
int lf = 10;
Serial.readBytesUntil(lf, myCol, 1);
if(strcmp(myCol, "r") == 0){
digitalWrite(gLed, LOW);
digitalWrite(yLed, LOW);
digitalWrite(rLed, HIGH);
}
if(strcmp(myCol, "y") == 0){
digitalWrite(gLed, LOW);
digitalWrite(yLed, HIGH);
digitalWrite(rLed, LOW);
}
if(strcmp(myCol, "g") == 0){
digitalWrite(gLed, HIGH);
digitalWrite(yLed, LOW);
digitalWrite(rLed, LOW);
}
}