File tree Expand file tree Collapse file tree 1 file changed +39
-0
lines changed Expand file tree Collapse file tree 1 file changed +39
-0
lines changed Original file line number Diff line number Diff line change
1
+ /*
2
+ Using a servo as a car Wiper, activated by switch.
3
+
4
+ modified on 19 March 2020
5
+ by Durgesh Pachghare
6
+ */
7
+
8
+ #include < Servo.h>
9
+
10
+ Servo myservo; // create servo object to control a servo
11
+
12
+ int button_pin = 2 ; // digital pin used to connect the button input
13
+ int val; // variable to read the value from the analog pin
14
+ int startpos = 10 ; // angle from which the servo wiper starts
15
+ int endpos = 145 ; // angle till the servo wiper rotates
16
+
17
+ void setup ()
18
+ {
19
+ myservo.attach (9 ); // attaches the servo on pin 9 to the servo object
20
+ pinMode (button_pin,INPUT); // declares the pin as digital input
21
+ myservo.write (startpos); // Initialize the servo wiper to start angle
22
+ }
23
+
24
+ void loop ()
25
+ {
26
+ if (digitalRead (button_pin)) // Start the servo if the button is pressed and complete the entire rotation regardless of button state later
27
+ {
28
+ for (int pos = startpos; pos <= endpos; pos += 1 ) // goes from starting angle to end angle in steps of 1 degree
29
+ {
30
+ myservo.write (pos); // tell servo to go to position in variable 'pos'
31
+ delay (15 ); // waits 15ms for the servo to reach the position
32
+ }
33
+ for (int pos = endpos; pos >= startpos; pos -= 1 ) // goes from end angle to start angle again
34
+ {
35
+ myservo.write (pos); // tell servo to go to position in variable 'pos'
36
+ delay (15 ); // waits 15ms for the servo to reach the position
37
+ }
38
+ }
39
+ }
You can’t perform that action at this time.
0 commit comments