Skip to content

Instantly share code, notes, and snippets.

@LindseyB
Last active January 1, 2018 23:01
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save LindseyB/6097d4514d67abe7fb3d650a90668e21 to your computer and use it in GitHub Desktop.
Save LindseyB/6097d4514d67abe7fb3d650a90668e21 to your computer and use it in GitHub Desktop.
#include <Servo.h>
Servo myservo;
int pos = 0; // variable to store the servo position
int times = 0; // number if times to stab stab
int randomDelay = 0; // Let's be surprising
void setup() {
myservo.attach(9); // attaches the servo on pin 9 to the servo object
randomSeed(analogRead(0)); // nothing attached, should be an okay random number, I'm not a fan
}
void loop() {
for(times = 0; times < 2; times++){
for (pos = 90; pos >= 0; pos -= 1) { // goes from 90 degrees to 0 degrees
myservo.write(pos);
delay(5); // waits 5ms for the servo to reach the position
}
delay(300);
for (pos = 0; pos <= 90; pos += 1) { // goes from 0 degrees to 90 degrees
// in steps of 1 degree
myservo.write(pos);
delay(5); // waits 5ms for the servo to reach the position
}
}
randomDelay = random(1,20);
delay(1000*randomDelay); // wait a bit, be surprising
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment