Created
April 19, 2021 13:21
-
-
Save farhangnaderi/76f21f65843da514f1fae38c25eb0e8b to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//Adding Libraries | |
#include <Servo.h> | |
//Pin Numbers | |
int led_1pin = 13; | |
int led_2pin = 2; | |
Servo servo1; // create servo object to control a servo | |
int val = 45; | |
int val2 = 170; | |
void setup() { | |
// Assign a pin to this LED | |
pinMode(led_1pin, OUTPUT); // sets the digital pin 13 as output | |
pinMode(led_2pin, OUTPUT); // sets the digital pin 2 as output | |
// Servo Attachment | |
servo1.attach(5); /* attaches the servo on pin 5 to the servo object | |
and resets the servo to init position*/ | |
} | |
void loop() { | |
digitalWrite(led_1pin, HIGH); // sets the digital pin 13 on | |
digitalWrite(led_2pin, HIGH); // sets the digital pin 13 on | |
delay(1000); // waits for a second | |
digitalWrite(led_1pin, LOW); // sets the digital pin 13 off | |
digitalWrite(led_2pin, LOW); // sets the digital pin 13 on | |
delay(1000); | |
//Writing angle value to your servo | |
servo1.write(val); //Val can be between 0 to 180 | |
delay(1000); | |
servo1.write(val2); | |
delay(1000); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment