This repository has been archived by the owner on Apr 11, 2019. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1 from allgood38/master
Working Pololu Library
- Loading branch information
Showing
3 changed files
with
131 additions
and
2 deletions.
There are no files selected for viewing
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
Original file line number | Original file line | Diff line number | Diff line change |
---|---|---|---|
@@ -0,0 +1,24 @@ | |||
To use the Pololu Micro Servo Controller library. | |||
|
|||
```c | |||
#include <pololu_servo.h> | |||
|
|||
static const int pololu_reset_pin = 3; | |||
static const int MOTOR_ONE = 7; | |||
|
|||
PololuMSC* pololu; | |||
|
|||
void setup() { | |||
Serial1.begin(9600); | |||
pinMode(pololu_reset_pin, OUTPUT); | |||
pololu = new PololuMSC(&Serial1, pololu_reset_pin); | |||
pololu->restart(); | |||
} | |||
|
|||
void loop() { | |||
pololu->setPosition(MOTOR_ONE, 250); | |||
delay(500); | |||
pololu->setPosition(MOTOR_ONE, 0); | |||
delay(500); | |||
} | |||
``` |
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
Original file line number | Original file line | Diff line number | Diff line change |
---|---|---|---|
@@ -0,0 +1,59 @@ | |||
#include "pololu_servo.h" | |||
|
|||
PololuMSC::PololuMSC(Stream* serialIn, int reset_pin) { | |||
for( int i = 0; i < this->SERVO_SLOTS; i++ ) { | |||
this->available_servos[i].current_value = SERVO_DEFAULT; | |||
this->available_servos[i].is_attached = false; | |||
} | |||
|
|||
this->DEBUG = false; | |||
|
|||
this->serialCom = serialIn; | |||
this->reset_pin = reset_pin; | |||
} | |||
|
|||
int PololuMSC::restart() { | |||
// reset the pololu | |||
digitalWrite(this->reset_pin, HIGH); | |||
delay(this->RESET_HIGH_WAIT); | |||
digitalWrite(this->reset_pin, LOW); | |||
delay(this->RESET_LOW_WAIT); | |||
|
|||
// send initialization byte | |||
this->serialCom->write(0xFF); | |||
|
|||
return 0; | |||
} | |||
int PololuMSC::setPosition(int motorID, int newValue) { | |||
if ( newValue > 254 || newValue < 0 | |||
|| motorID < 0 || motorID > this->SERVO_SLOTS - 1 ) { | |||
if ( this->DEBUG ) { | |||
this->serialDebug->println("Invalid setPosition Values"); | |||
} | |||
return -1; | |||
} | |||
this->available_servos[motorID].current_value = newValue; | |||
this->available_servos[motorID].is_attached = true; | |||
|
|||
this->serialCom->write(0xFF); | |||
this->serialCom->write(motorID); | |||
this->serialCom->write(newValue); | |||
|
|||
return 0; | |||
} | |||
|
|||
int PololuMSC::debugSet(Stream* newSerial) { | |||
if ( newSerial == NULL ) { | |||
return -1; | |||
} | |||
this->serialDebug = newSerial; | |||
this->DEBUG = true; | |||
|
|||
return 0; | |||
} | |||
|
|||
int PololuMSC::debugOff() { | |||
this->DEBUG = false; | |||
this->serialDebug = NULL; | |||
return 0; | |||
} |
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