diff --git a/examples/PushRotate/PushRotate.ino b/examples/PushRotate/PushRotate.ino new file mode 100644 index 0000000..230aa3d --- /dev/null +++ b/examples/PushRotate/PushRotate.ino @@ -0,0 +1,43 @@ +/* PushRotate + by K.Abhijeet + This example code rotates the servo motor clockwise or anti-clockwise as per button pressed. + + Circuit:- + Arduino Uno + Micro Servo Motor connected at pin 9 + push button1 between pin 6 and VCC with 220 Ohm pull-down resistor(rotate anti-clockwise) + push button2 between pin 7 and VCC with 220 Ohm pull-down resistor(rotate clockwise) + +*/ + +#include + +Servo Smotor; // Servo motor object +int pos = 0; +int angle = 5; //angle to rotate +void setup() { + Serial.begin(9600); + pinMode(6, INPUT); //Input button1 + pinMode(7, INPUT); //Input button2 + Smotor.attach(9); //Servo Motor connected at pin 9 + Smotor.write(90); +} + +void loop() { + + if (digitalRead(6) == HIGH) + { + pos = pos + angle; + Smotor.write(pos); // rotates servo motor anti-clockwise + } + + if (digitalRead(7) == HIGH) + { + pos = pos - angle; + Smotor.write(pos); //rotates servo motor clockwise + } + delay(100); + + Serial.print("Current Motor position is:"); + Serial.println(pos); //prints motor angle +} diff --git a/examples/RandomRotate/RandomRotate.ino b/examples/RandomRotate/RandomRotate.ino new file mode 100644 index 0000000..8ed1196 --- /dev/null +++ b/examples/RandomRotate/RandomRotate.ino @@ -0,0 +1,27 @@ +/* RandomRotate + by K.Abhijeet + This example code rotates the servo motor at random angle. + + Circuit:- + Arduino Uno + Micro Servo Motor connected at pin no 9 +*/ + +#include + +Servo Smotor; // Servo motor object +int pos = 0; + +void setup() { + Serial.begin(9600); + Smotor.attach(9); //Servo Motor connected at pin no 9 + Smotor.write(0); +} + +void loop() { + pos = random(0, 180); //calculates random angle + Smotor.write(pos); + Serial.print("Current Motor position is:"); + Serial.println(pos); //prints motor angle + delay(1000); //Wait for 1 second +}