Skip to content

Instantly share code, notes, and snippets.

@JeffersGlass
Created April 5, 2020 03:01
Show Gist options
  • Save JeffersGlass/6a78ebd8bb5141ae5a250a4d08f0ea38 to your computer and use it in GitHub Desktop.
Save JeffersGlass/6a78ebd8bb5141ae5a250a4d08f0ea38 to your computer and use it in GitHub Desktop.
#include <Servo.h>
Servo myservo; // create servo object to control a servo
int potpin = 0; // analog pin used to connect the potentiometer
int val; // variable to read the value from the analog pin
void setup() {
myservo.attach(9); // attaches the servo on pin 9 to the servo object
randomSeed(analogRead(A1));
}
void loop() {
val = random(180); // Creates a random value between 0 and 180 degrees
myservo.write(val); // sets the servo position according to the scaled value
delay(random(1000, 3000); // Wait for between 1 and 3 seconds
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment