Skip to content

Instantly share code, notes, and snippets.

@borkDoy
Last active June 22, 2019 01:19
Show Gist options
  • Save borkDoy/01db5a3c4818c29f1161a6aa3f352e2c to your computer and use it in GitHub Desktop.
Save borkDoy/01db5a3c4818c29f1161a6aa3f352e2c to your computer and use it in GitHub Desktop.
// Add in the servo library
#include <Servo.h>
// Create the servo object
Servo servo1;
// Store the 2 positions of the disk rotation
int intPos = 0;
int secPos = 180;
// Store the position - 0 is first position and 1 is second position
int onOff = 0;
// Pin# of the Button
int buttonPin = 9;
// Pin# of the LED
int ledPin = 5;
void setup() {
// Set the LED pin output
pinMode(ledPin, OUTPUT);
// Set the Button input
pinMode(buttonPin, INPUT_PULLUP);
// Attach the servo on pin 11 to the servo object
servo1.attach(11);
// Set the starting position
servo1.write(0);
}
void loop() {
// Check if the Button is pressed, when it is,
//change the position of the servo and flash the LED
if (digitalRead(buttonPin) == LOW){
if ( onOff == 0){
digitalWrite(ledPin, HIGH);
servo1.write(secPos);
onOff = 1;
}
else{
digitalWrite(ledPin, HIGH);
servo1.write(intPos);
onOff = 0;
}
}
delay(200);
// Set the button back to LOW
digitalWrite(ledPin, LOW);}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment