Created
February 29, 2016 02:29
-
-
Save jameshih/efa8b443d40071ebca50 to your computer and use it in GitHub Desktop.
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
void debug() { | |
Serial.print("Servo Degree(9,10)= \t"); | |
Serial.print(pos); | |
Serial.print("\tServo Degree(11,6)= \t"); | |
Serial.print(pos2); | |
Serial.println(); | |
} |
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> | |
Servo myservo1; | |
Servo myservo2; | |
Servo myservo3; | |
Servo myservo4; | |
int interval = 100; | |
int pos; | |
int pos2; | |
float counter; | |
void setup() { | |
myservo1.attach(9); | |
myservo2.attach(10); | |
myservo3.attach(11); | |
myservo4.attach(6); | |
Serial.begin(9600); | |
} | |
void loop() { | |
long start = millis(); | |
counter = 128 + 127 * cos (0.25 * PI / interval * (interval - start)); | |
pos = map(counter, 0, 255, 40, 135); | |
pos2 = map(counter, 0, 255, 135, 40); | |
myservo1.write(pos); | |
myservo3.write(pos2); | |
myservo2.write(pos); | |
myservo4.write(pos2); | |
debug(); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment