Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added new example Random Rotate #38

Open
wants to merge 7 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
43 changes: 43 additions & 0 deletions examples/PushRotate/PushRotate.ino
Original file line number Diff line number Diff line change
@@ -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.h>

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
}
27 changes: 27 additions & 0 deletions examples/RandomRotate/RandomRotate.ino
Original file line number Diff line number Diff line change
@@ -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.h>

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
}