generated from osamhack2020/Sample_Technology_ProjectName_TeamName
-
Notifications
You must be signed in to change notification settings - Fork 0
/
arduino_circuit.ino
50 lines (42 loc) · 970 Bytes
/
arduino_circuit.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
#include <Servo.h>
Servo sv;
int state;
const int STATE_OPENED = 48;
const int STATE_CLOSED = 49;
const int motorPin = 9;
const int checkPin = 2;
const int ledPin = 4;
void setup() {
Serial.begin(9600);
sv.attach(motorPin);
sv.write(0);
state = STATE_OPENED;
pinMode(checkPin, INPUT);
pinMode(ledPin, OUTPUT);
}
void loop() {
int connected = digitalRead(checkPin);
digitalWrite(ledPin, connected);
if(Serial.available() > 0) {
int read = Serial.read();
if(connected == HIGH) {
if(read != state) {
if(read == STATE_CLOSED) {
Serial.println("Close the Box!");
for(int i = 0; i < 180; i++) {
sv.write(i);
delay(10);
}
}
else if(read == STATE_OPENED) {
Serial.println("Open the Box!");
for(int i = 180; i > 0; i--) {
sv.write(i);
delay(10);
}
}
state = read;
}
}
}
}