Skip to content

Instantly share code, notes, and snippets.

@mithi
Last active Aug 28, 2015
Embed
What would you like to do?
test mearm
#include <Servo.h>
class Sweeper {
Servo servo;
int pos;
int inc;
int interval;
unsigned long lastUpdate;
int maximum;
int minimum;
public:
Sweeper(int updateInterval, int increment, int sMin, int sMax) {
interval = updateInterval;
inc = increment;
minimum = sMin;
maximum = sMax;
pos = minimum;
}
void sync(int pin){
servo.attach(pin);
servo.write(pos);
}
int pose(){
return pos;
}
boolean itsTimeToMove() {
return (millis() - lastUpdate) > interval;
}
void forward() {
if (itsTimeToMove()) {
lastUpdate = millis();
if (pos <= maximum) {
servo.write(pos);
pos += inc;
}
}
}
void reverse() {
if (itsTimeToMove()) {
lastUpdate = millis();
if (pos >= minimum) {
servo.write(pos);
pos -= inc;
}
}
}
};
Sweeper Hip(15, 1, 0, 180);
Sweeper Shoulder(15, 1, 30, 100);
//Sweeper Elbow(10, 1, 0, 180);
//Sweeper Gripper(10, 5, 0, 90);
void setup() {
Hip.sync(9);
Shoulder.sync(10);
}
void loop() {
while (Hip.pose() <= 180){
Hip.forward();
Shoulder.forward();
}
while (Hip.pose() >= 0){
Hip.reverse();
Shoulder.reverse();
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment