This repository has been archived by the owner on Aug 7, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
IrisCore.ino
61 lines (53 loc) · 1.69 KB
/
IrisCore.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
#include <Servo.h>
//int incomingByte = 0; // for incoming serial data
String incomingAction;
int incomingValue;
Servo hzServo, vcServo;
int lazerPin = 13;
void setup() {
Serial.begin(9600);
hzServo.attach(7);
vcServo.attach(9);
pinMode(lazerPin, OUTPUT);
digitalWrite(lazerPin, HIGH);
}
void loop() {
// Listen for transmitted data:
if (Serial.available() > 0) {
//Listen for action:
incomingAction = Serial.readStringUntil(':');
incomingValue = Serial.readString().toInt();
if (incomingAction == "H") {
Serial.println("Moving Horizontaly");
moveHorizontalServos(incomingValue);
}
if (incomingAction == "V") {
Serial.println("Moving Verticaly");
moveVerticalServos(incomingValue);
}
if (incomingAction == "C") {
Serial.println("Calibrating...");
moveHorizontalServos(90);
moveVerticalServos(90);
controlLight(0);
}
if (incomingAction == "L") {
Serial.println("Controlling Light");
controlLight(incomingValue);
}
}
}
void moveHorizontalServos(int degree) {
hzServo.write(degree); // tell servo to go to position in variable 'pos'
}
void moveVerticalServos(int degree) {
vcServo.write(degree); // tell servo to go to position in variable 'pos'
}
void controlLight(int state) {
if (state == 1) {
digitalWrite(lazerPin, LOW);
}
else {
digitalWrite(lazerPin, HIGH);
}
}