Created
September 16, 2014 02:27
-
-
Save arduinoboard/f2a1e7c260c732c7c353 to your computer and use it in GitHub Desktop.
The file that is currently on an ArbotiX with a serial number of AH01DRQ6
This file contains hidden or 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 <ax12.h> | |
#include <BioloidController.h> | |
int linearPin = 16; // the pin number of the actuator. | |
int servoPin = 1; // the pin number of the servo. | |
long delayTime = 1; // servo movement delay time in millis. | |
int extend=1950; | |
int retract=1050; | |
int startPos= 200; | |
int currentPos; | |
int zero= 200; | |
int fortyFive=510; | |
int movement = 0; // length of the actuator | |
int pulseWidth = 0; // angle to microseconds. | |
int standard = 5000; | |
int brief = 1000; | |
void setup(){ | |
Serial.begin(9600); | |
pinMode(linearPin, OUTPUT); | |
// extend sequence. | |
for (movement = retract; movement <= extend; movement++) { | |
linearMove(linearPin, movement); | |
} | |
delay (standard); | |
//servo 0 degree | |
SetPosition(1,startPos); | |
currentPos = startPos; | |
delay(brief); | |
// retract sequence. | |
for (movement = extend; movement >= retract; movement--) { | |
linearMove(linearPin, movement); | |
} | |
delay (standard); | |
} | |
void loop() | |
{ | |
Serial.println(currentPos); | |
// extend sequence. | |
for (movement = retract; movement <= extend; movement++) { | |
linearMove(linearPin, movement); | |
} | |
delay (standard); | |
//servo 45 degree | |
currentPos=servoMoveCCW(servoPin,currentPos,fortyFive); | |
delay(standard); | |
// retract sequence. | |
for (movement = extend; movement >= retract; movement--) { | |
linearMove(linearPin, movement); | |
} | |
delay (standard); | |
// extend sequence. | |
for (movement = retract; movement <= extend; movement++) { | |
linearMove(linearPin, movement); | |
} | |
delay (standard); | |
//servo 0 degree | |
currentPos=servoMoveCW(servoPin,currentPos,zero); | |
delay(standard); | |
// retract sequence. | |
for (movement = extend; movement >= retract; movement--) { | |
linearMove(linearPin, movement); | |
} | |
delay (standard); | |
} | |
This file contains hidden or 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 linearMove(int servoPin, int movement) { | |
digitalWrite(servoPin, HIGH); // set servo high. | |
delayMicroseconds(movement); // wait a very small amount. | |
digitalWrite(servoPin, LOW); // set servo low. | |
delay(delayTime); // refresh cycle of typical servos. | |
} | |
void downToUp(){ | |
} |
This file contains hidden or 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
int servoMoveCCW(int servoPin, int tempCurrentPos, int movement){ | |
for(int i=tempCurrentPos;i<movement;i++) | |
{ | |
SetPosition(servoPin,i); //set the position of servo #1 to the current value of 'i' | |
delay(20); //slow servo movement | |
} | |
return movement; | |
} |
This file contains hidden or 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
int servoMoveCW(int servoPin, int tempCurrentPos, int movement){ | |
for(int i=tempCurrentPos;i>movement;i--) | |
{ | |
SetPosition(servoPin,i); //set the position of servo #1 to the current value of 'i' | |
delay(20); //slow servo movement | |
} | |
return movement; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment