And a video of it making a circle:
Below also the code for the circle:
#include <Makeblock.h>
#include <Arduino.h>
#include <SoftwareSerial.h>
#include <Wire.h>
MeServo servoDriver1(PORT_1,DEV1);
MeServo servoDriver2(PORT_1,DEV2);
int xco;
int yco;
int servo1co;
int servo2co;
void setup()
{
servoDriver1.begin();
servoDriver2.begin();
}
void loop()
{
for (int xco = 0; xco < 90; xco++) {
yco = sqrt ( 8100 - ( xco * xco ) ) ;
servo1co = xco + 90;
servo2co = 90 - yco;
servoDriver1.write(servo1co);
servoDriver2.write(servo2co);
delay(20);
}
for (int xco = 90; xco > 0 ; xco--) {
yco = sqrt ( 8100 - ( xco * xco ) ) ;
servo1co = xco + 90 ;
servo2co = 90 + yco;
servoDriver1.write(servo1co);
servoDriver2.write(servo2co);
delay(20);
}
for (int xco = 0; xco < 90 ; xco++) {
yco = sqrt ( 8100 - ( xco * xco ) ) ;
servo1co = 90 - xco ;
servo2co = 90 + yco;
servoDriver1.write(servo1co);
servoDriver2.write(servo2co);
delay(20);
}
for (int xco = 90; xco > 0 ; xco--) {
yco = sqrt ( 8100 - ( xco * xco ) ) ;
servo1co = 90 - xco ;
servo2co = 90 - yco;
servoDriver1.write(servo1co);
servoDriver2.write(servo2co);
delay(20);
}
}
I had no internet yesterday so I had to remember the formula for drawing a circle myself, it can probably be done simpler.
cheers,
paul