-
Notifications
You must be signed in to change notification settings - Fork 0
/
final_iot_code_AA.ino
107 lines (106 loc) · 1.86 KB
/
final_iot_code_AA.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
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
#include <Servo.h>
Servo servoMain1;
Servo servoMain2;
Servo servoMain3;
Servo servoMain4;
int led = 13;
long int n = 0;
int a1 = 0;
int a2 = 0;
int a3 = 0;
int a4 = 0;
int d = 0;
int diff = 0;
int diff2 = 0;
int diff3 = 0;
void setup() {
Serial.begin(9600);
pinMode(led, OUTPUT);
servoMain1.attach(3);
servoMain2.attach(5);
servoMain3.attach(6);
servoMain4.attach(9);
}
void loop(){
while (Serial.available() > 0) {
int n = Serial.parseInt();
if(n>10){
a1=n/10;
d=n-(a1*10);
}
if(d>=5){
a2=1;
diff=d-5;
}
switch(diff){
case 4:
a3=2;
break;
case 3:
a3=1;
a4=1;
break;
case 2:
a3=1;
break;
case 1:
a4=1;
}
if(n>=5 && n<10){
a2=1;
diff2=n-5;
switch (diff2){
case 4:
a3=2;
break;
case 3:
a3=1;
a4=1;
break;
case 2:
a3=1;
break;
case 1:
a4=1;
}
}
if(n>=2 && n<5){
a3=1;
diff3=n-2;
}
if(diff3>=1){
a4=diff3;
}
if(n>=1 && n<2){
a4=n;
}
}
Serial.println(a1);
Serial.println(a2);
Serial.println(a3);
Serial.println(a4);
while (a1>0) {
servoMain1.write(40);
delay(300);
servoMain1.write(120);
delay(300);
a1--; }
while (a2>0) {
servoMain2.write(40);
delay(300);
servoMain2.write(120);
delay(300);
a2--; }
while (a3>0) {
servoMain3.write(40);
delay(300);
servoMain3.write(120);
delay(300);
a3--; }
while (a4>0) {
servoMain4.write(40);
delay(300);
servoMain4.write(120);
delay(300);
a4--; }
}