2010-08-06 23:55:17 +02:00
|
|
|
/* This firmware supports as many servos as possible using the Servo library
|
|
|
|
* included in Arduino 0017
|
2009-06-01 10:32:11 +02:00
|
|
|
*
|
|
|
|
* TODO add message to configure minPulse/maxPulse/degrees
|
|
|
|
*
|
|
|
|
* This example code is in the public domain.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <Servo.h>
|
2010-08-06 23:55:17 +02:00
|
|
|
#include <Firmata.h>
|
2009-06-01 10:32:11 +02:00
|
|
|
|
2010-08-06 23:55:17 +02:00
|
|
|
Servo servos[MAX_SERVOS];
|
2009-06-01 10:32:11 +02:00
|
|
|
|
|
|
|
void analogWriteCallback(byte pin, int value)
|
|
|
|
{
|
2010-08-06 23:55:17 +02:00
|
|
|
if (IS_PIN_SERVO(pin)) {
|
|
|
|
servos[PIN_TO_SERVO(pin)].write(value);
|
|
|
|
}
|
2009-06-01 10:32:11 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
void setup()
|
|
|
|
{
|
2010-08-06 23:55:17 +02:00
|
|
|
byte pin;
|
|
|
|
|
2009-06-01 10:32:11 +02:00
|
|
|
Firmata.setFirmwareVersion(0, 2);
|
|
|
|
Firmata.attach(ANALOG_MESSAGE, analogWriteCallback);
|
|
|
|
|
2010-08-06 23:55:17 +02:00
|
|
|
for (pin=0; pin < TOTAL_PINS; pin++) {
|
|
|
|
if (IS_PIN_SERVO(pin)) {
|
|
|
|
servos[PIN_TO_SERVO(pin)].attach(PIN_TO_DIGITAL(pin));
|
|
|
|
}
|
|
|
|
}
|
2009-06-01 10:32:11 +02:00
|
|
|
|
2009-07-14 23:32:55 +02:00
|
|
|
Firmata.begin(57600);
|
2009-06-01 10:32:11 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
void loop()
|
|
|
|
{
|
|
|
|
while(Firmata.available())
|
|
|
|
Firmata.processInput();
|
|
|
|
}
|
|
|
|
|