1
0
Fork 0
This repository has been archived on 2019-12-23. You can view files and clone it, but you cannot make any changes to it's state, such as pushing and creating new issues, pull requests or comments.
arduinisten/arduino-0022-linux-x64/libraries/Firmata/examples/ServoFirmata/ServoFirmata.pde

43 lines
818 B
Text
Raw Normal View History

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