-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMain
153 lines (125 loc) · 2.57 KB
/
Main
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
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
#include <Servo.h>
// Relays
int relay1 = 12;
int relay2 = 11;
int relay3 = 10;
int relay4 = 9;
int relay5 = 8;
int relay6 = 7;
// Potar
int potarpin = 0;
int potar = 0;
// Servo
int Nservo = 3;
Servo charger;
int servo_middle = 80;
int servo_press = 20;
int Nbat = 0;
void setup()
{
pinMode(relay1, OUTPUT);
pinMode(relay2, OUTPUT);
pinMode(relay3, OUTPUT);
pinMode(relay4, OUTPUT);
pinMode(relay5, OUTPUT);
pinMode(relay6, OUTPUT);
pinMode(potarpin, INPUT);
charger.attach(Nservo);
Serial.begin(9600);
}
void loop()
{
// TEST RELAY
/*
digitalWrite(relay1, HIGH);
digitalWrite(relay2, HIGH);
digitalWrite(relay3, HIGH);
digitalWrite(relay4, HIGH);
digitalWrite(relay5, HIGH);
digitalWrite(relay6, HIGH);
delay(1000);
digitalWrite(relay1, LOW);
digitalWrite(relay2, LOW);
digitalWrite(relay3, LOW);
digitalWrite(relay4, LOW);
digitalWrite(relay5, LOW);
digitalWrite(relay6, LOW);
delay(1000);
*/
// TEST SERVO
/*
press_right();
delay(1000);
press_left();
delay(1000);
*/
// POTAR SETTING
/*
potar = analogRead(potarpin);
Serial.println(potar);
delay(100);
*/
// MAIN
charger.write(servo_middle);
Nbat = read_potar();
for(int i=1; i<=Nbat; i++)
{
charge(i);
delay(500);
press_right();
// Wait 55min
delay(3300000);
press_left();
delay(1000);
digitalWrite(relay1, LOW);
digitalWrite(relay2, LOW);
digitalWrite(relay3, LOW);
digitalWrite(relay4, LOW);
digitalWrite(relay5, LOW);
digitalWrite(relay6, LOW);
delay(1000);
}
// Wait 24h
delay(86400000);
}
void charge(int x)
{
if(x==1){digitalWrite(relay1, HIGH);}
if(x==2){digitalWrite(relay2, HIGH);}
if(x==3){digitalWrite(relay3, HIGH);}
if(x==4){digitalWrite(relay4, HIGH);}
if(x==5){digitalWrite(relay5, HIGH);}
if(x==6){digitalWrite(relay6, HIGH);}
}
void press_right()
{
// Press right long
charger.write(servo_middle+servo_press);
delay(2000);
// Release
charger.write(servo_middle);
delay(200);
// Press right quick
charger.write(servo_middle+servo_press);
delay(500);
// Release
charger.write(servo_middle);
}
void press_left()
{
charger.write(servo_middle-servo_press);
delay(500);
charger.write(servo_middle);
}
int read_potar()
{
int result;
potar = analogRead(potarpin);
if (potar<=90){result = 6;}
if (potar>90 && potar<=261){result = 5;}
if (potar>265 && potar<=451){result = 4;}
if (potar>455 && potar<=650){result = 3;}
if (potar>6540 && potar<=820){result = 2;}
if (potar>824){result = 1;}
return result;
}