5 Maestro::Maestro(Stream &stream,
11 _deviceNumber = deviceNumber;
13 _CRCEnabled = CRCEnabled;
20 digitalWrite(_resetPin, LOW);
21 pinMode(_resetPin, OUTPUT);
23 pinMode(_resetPin, INPUT);
31 _stream->write(miniSscCommand);
32 _stream->write(channelNumber);
33 _stream->write(target);
38 writeCommand(goHomeCommand);
44 writeCommand(stopScriptCommand);
50 writeCommand(restartScriptAtSubroutineCommand);
51 write7BitData(subroutineNumber);
58 writeCommand(restartScriptAtSubroutineWithParameterCommand);
59 write7BitData(subroutineNumber);
60 write14BitData(parameter);
66 writeCommand(setTargetCommand);
67 write7BitData(channelNumber);
68 write14BitData(target);
74 writeCommand(setSpeedCommand);
75 write7BitData(channelNumber);
76 write14BitData(speed);
82 writeCommand(setAccelerationCommand);
83 write7BitData(channelNumber);
84 write14BitData(acceleration);
90 writeCommand(getPositionCommand);
91 write7BitData(channelNumber);
94 while (_stream->available() < 2);
95 uint8_t lowerByte = _stream->read();
96 uint8_t upperByte = _stream->read();
97 return (upperByte << 8) | (lowerByte & 0xFF);
102 writeCommand(getMovingStateCommand);
105 while (_stream->available() < 1);
106 return _stream->read();
111 writeCommand(getErrorsCommand);
114 while (_stream->available() < 2);
115 uint8_t lowerByte = _stream->read();
116 uint8_t upperByte = _stream->read();
117 return (upperByte << 8) | (lowerByte & 0xFF);
122 writeCommand(getScriptStatusCommand);
125 while (_stream->available() < 1);
126 return _stream->read();
129 void Maestro::writeByte(uint8_t dataByte)
131 _stream->write(dataByte);
135 _CRCByte ^= dataByte;
136 for (uint8_t j = 0; j < 8; j++)
140 _CRCByte ^= CRC7Polynomial;
147 void Maestro::writeCRC()
151 _stream->write(_CRCByte);
156 void Maestro::writeCommand(uint8_t commandByte)
160 writeByte(baudRateIndication);
161 write7BitData(_deviceNumber);
162 write7BitData(commandByte);
166 writeByte(commandByte);
170 void Maestro::write7BitData(uint8_t data)
172 writeByte(data & 0x7F);
175 void Maestro::write14BitData(uint16_t data)
177 writeByte(data & 0x7F);
178 writeByte((data >> 7) & 0x7F);
183 uint8_t deviceNumber,
184 bool CRCEnabled) :
Maestro(stream,
193 uint8_t deviceNumber,
194 bool CRCEnabled) :
Maestro(stream,
203 writeCommand(setPwmCommand);
204 write14BitData(onTime);
205 write14BitData(period);
210 uint8_t firstChannel,
211 uint16_t *targetList)
213 writeCommand(setMultipleTargetsCommand);
214 write7BitData(numberOfTargets);
215 write7BitData(firstChannel);
217 for (
int i = 0; i < numberOfTargets; i++)
219 write14BitData(targetList[i]);
uint16_t getErrors()
Gets the error register.
uint8_t getScriptStatus()
Gets if the script is running or stopped.
void setMultiTarget(uint8_t numberOfTargets, uint8_t firstChannel, uint16_t *targetList)
Sets multiple targets starting with the channel specified by firstChannel to a list of values listed ...
void stopScript()
Stops the script.
void goHome()
Sends the servos and outputs to home position.
MiniMaestro(Stream &stream, uint8_t resetPin=noResetPin, uint8_t deviceNumber=deviceNumberDefault, bool CRCEnabled=false)
Create a MiniMaestro object.
static const uint8_t deviceNumberDefault
The default device number, used to construct a MicroMaestro or MiniMaestro object that will use the c...
void reset()
Resets the Maestro by toggling the resetPin, if a resetPin was given.
static const uint8_t noResetPin
The default reset pin is no reset pin, used to construct a MicroMaestro or MiniMaestro object that wi...
void restartScript(uint8_t subroutineNumber)
Starts loaded script at specified subroutineNumber location.
MicroMaestro(Stream &stream, uint8_t resetPin=noResetPin, uint8_t deviceNumber=deviceNumberDefault, bool CRCEnabled=false)
Create a MicroMaestro object.
void setAcceleration(uint8_t channelNumber, uint16_t acceleration)
Sets the acceleration limit of channelNumber.
uint8_t getMovingState()
Gets the moving state for all configured servo channels.
void restartScriptWithParameter(uint8_t subroutineNumber, uint16_t parameter)
Starts loaded script at specified subroutineNumber location after loading parameter on to the stack...
void setSpeed(uint8_t channelNumber, uint16_t speed)
Sets the speed limit of channelNumber.
uint16_t getPosition(uint8_t channelNumber)
Gets the position of channelNumber.
Main Maestro class that handles common functions between the Micro Maestro and Mini Maestro...
void setTarget(uint8_t channelNumber, uint16_t target)
Sets the target of the servo on channelNumber.
void setTargetMiniSSC(uint8_t channelNumber, uint8_t target)
Sets the target of the servo on channelNumber using the Mini SSC protocol.
void setPWM(uint16_t onTime, uint16_t period)
Sets the PWM specified by onTime and period in units of 1/48 microseconds.