Skip to content

Instantly share code, notes, and snippets.

@radavis
Created September 27, 2014 21:09
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 radavis/9fb71c670c3f4b276e84 to your computer and use it in GitHub Desktop.
Save radavis/9fb71c670c3f4b276e84 to your computer and use it in GitHub Desktop.
Arduino code to control a servo
// GongHitter
// by Vikram and Richard
#include <Servo.h>
int STEP = 5;
int DELAY = 500;
unsigned long TIME_BETWEEN_HITS = 3600000; // one hour
//1000 * 60 * 60 * 24;
Servo myservo; // create servo object to control a servo
// a maximum of eight servo objects can be created
void moveMallet() {
// move home
myservo.write(90);
delay(DELAY);
myservo.write(0);
delay(250);
// strike
myservo.write(90);
delay(DELAY);
}
void setup() {
myservo.attach(9); // attaches the servo on pin 9 to the servo object
}
void loop() {
moveMallet();
delay(TIME_BETWEEN_HITS);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment