Skip to content

Instantly share code, notes, and snippets.

@farhangnaderi
Created April 19, 2021 13:21
Show Gist options
  • Save farhangnaderi/76f21f65843da514f1fae38c25eb0e8b to your computer and use it in GitHub Desktop.
Save farhangnaderi/76f21f65843da514f1fae38c25eb0e8b to your computer and use it in GitHub Desktop.
//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