1#include <Servo.h>
2
3Servo myservo;
4
5const int pinBottone = 2;
6const int pinFine = 3;
7const int pinLed = 4;
8const int pin20 = 13;
9const int pin40 = 12;
10const int pin60 = 11;
11const int pin80 = 10;
12const int pin100 = 8;
13
14
15int presBottone = 0;
16int fineOn = 0;
17int pos = 0;
18
19
20int dCoarse = 5000;
21int dFine = 1000;
22
23
24void setup() {
25 pinMode(pinLed, OUTPUT);
26 pinMode(pin20, OUTPUT);
27 pinMode(pin40, OUTPUT);
28 pinMode(pin60, OUTPUT);
29 pinMode(pin80, OUTPUT);
30 pinMode(pin100, OUTPUT);
31 pinMode(pinBottone, INPUT_PULLUP);
32 pinMode(pinFine, INPUT_PULLUP);
33 myservo.attach(9);
34 digitalWrite(presBottone, HIGH);
35 digitalWrite(fineOn, HIGH);
36 delay(200);
37 digitalWrite(pin20, HIGH);
38 delay(200);
39 digitalWrite(pin40, HIGH);
40 delay(200);
41 digitalWrite(pin60, HIGH);
42 delay(200);
43 digitalWrite(pin80, HIGH);
44 delay(200);
45 digitalWrite(pin100, HIGH);
46 delay(200);
47 digitalWrite(pin20, LOW);
48 delay(200);
49 digitalWrite(pin40, LOW);
50 delay(200);
51 digitalWrite(pin60, LOW);
52 delay(200);
53 digitalWrite(pin80, LOW);
54 delay(200);
55 digitalWrite(pin100, LOW);
56}
57
58void loop() {
59 presBottone = digitalRead(pinBottone);
60 fineOn = digitalRead(pinFine);
61 if (presBottone == LOW) {
62 digitalWrite(pinLed, HIGH);
63 if (fineOn == LOW) {
64 for (pos = 0; pos <= 60; pos += 1) {
65 presBottone = digitalRead(pinBottone);
66 while (presBottone == LOW) {
67 presBottone = digitalRead(pinBottone);
68 }
69 digitalWrite(pin20, LOW);
70 digitalWrite(pin40, LOW);
71 digitalWrite(pin60, LOW);
72 digitalWrite(pin80, LOW);
73 digitalWrite(pin100, LOW);
74 if (((pos<=12)&&(pos>0))){}
75 if (((pos<=24)&&(pos>12))){digitalWrite(pin20,HIGH);}
76 if (((pos<=36)&&(pos>24))){digitalWrite(pin20,HIGH);digitalWrite(pin40,HIGH);;}
77 if (((pos<=48)&&(pos>36))){digitalWrite(pin20,HIGH);digitalWrite(pin40,HIGH);digitalWrite(pin60,HIGH);}
78 if (((pos<=59)&&(pos>48))){digitalWrite(pin20,HIGH);digitalWrite(pin40,HIGH);digitalWrite(pin60,HIGH);digitalWrite(pin80,HIGH);}
79 if (pos==60){digitalWrite(pin20,HIGH);digitalWrite(pin40,HIGH);digitalWrite(pin60,HIGH);digitalWrite(pin80,HIGH);digitalWrite(pin100,HIGH);}
80 myservo.writeMicroseconds(1760);
81 delay(20);
82 myservo.writeMicroseconds(1500);
83 delay(dFine);
84 presBottone = LOW;
85 }
86 } else {
87 for (pos = 0; pos <= 24; pos += 1) {
88 presBottone = digitalRead(pinBottone);
89 while (presBottone == LOW) {
90 presBottone = digitalRead(pinBottone);
91 }
92 digitalWrite(pin20, LOW);
93 digitalWrite(pin40, LOW);
94 digitalWrite(pin60, LOW);
95 digitalWrite(pin80, LOW);
96 digitalWrite(pin100, LOW);
97 if (((pos<=3)&&(pos>0))){}
98 if (((pos<=7)&&(pos>3))){digitalWrite(pin20,HIGH);}
99 if (((pos<=12)&&(pos>7))){digitalWrite(pin20,HIGH);digitalWrite(pin40,HIGH);;}
100 if (((pos<=17)&&(pos>12))){digitalWrite(pin20,HIGH);digitalWrite(pin40,HIGH);digitalWrite(pin60,HIGH);}
101 if (((pos<=23)&&(pos>17))){digitalWrite(pin20,HIGH);digitalWrite(pin40,HIGH);digitalWrite(pin60,HIGH);digitalWrite(pin80,HIGH);}
102 if (pos==24){digitalWrite(pin20,HIGH);digitalWrite(pin40,HIGH);digitalWrite(pin60,HIGH);digitalWrite(pin80,HIGH);digitalWrite(pin100,HIGH);}
103 myservo.writeMicroseconds(2060);
104 delay(60);
105 myservo.writeMicroseconds(1500);
106 delay(dCoarse);
107 presBottone = LOW;
108 }
109 }
110
111 }
112 else {
113 digitalWrite(pinLed, HIGH);
114 delay (500);
115 digitalWrite(pinLed, LOW);
116 delay (500);
117 }
118}
119
120
121