Skip to content

Commit f2256cf

Browse files
committed
Added an example 'wiper'
1 parent 2e973f6 commit f2256cf

File tree

1 file changed

+39
-0
lines changed

1 file changed

+39
-0
lines changed

examples/Wiper/Wiper.ino

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
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+
}

0 commit comments

Comments
 (0)