Last active
August 28, 2015 17:22
-
-
Save mithi/64d58fdcda1e39ebb489 to your computer and use it in GitHub Desktop.
test mearm
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#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