Created
May 5, 2010 06:37
-
-
Save matthewfl/390461 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
// the time between bits about 9600 bauds | |
#define bitDelay 101 | |
void printByte(char out) { | |
digitalWrite(7, HIGH); // start bit | |
delayMicroseconds(bitDelay); | |
for(char mask=0x01; mask; mask <<=1) { | |
digitalWrite(7, out & mask ? HIGH : LOW); // I am not sure which way this should go | |
delayMicroseconds(bitDelay); | |
} | |
digitalWrite(7, LOW); // stop bit | |
delayMicroseconds(bitDelay); // do I need this here | |
} | |
void setup () { | |
Serial.begin(57600); | |
pinMode(7, OUTPUT); | |
pinMode(4, OUTPUT); | |
digitalWrite(4, HIGH); // reset the servo controller | |
delay(1000); | |
digitalWrite(4, LOW); | |
delay(500); | |
printByte(0x80); // send some init commands (is this needed?) | |
printByte(0x01); | |
printByte(0x00); | |
printByte(0x01); | |
printByte(0x7F); | |
} | |
void loop () { | |
//int bitDelay = 1000000/print_rate - clockCyclesToMicroseconds(50); | |
// int bitDelay = 101; | |
/* ///////////////// for when I was testing Mini SSC mode | |
printByte(0xFF); | |
printByte(10); | |
printByte(254); | |
*/ | |
// the pololu mode | |
printByte(0x80); // sync byte | |
printByte(0x01); // device id | |
printByte(0x02); // command | |
printByte(0x02); // servo number | |
printByte(0x76); // data1/location | |
//Serial.println(bitDelay); | |
delay(1000); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment