2 * Firmata is a generic protocol for communicating with microcontrollers
3 * from software on a host computer. It is intended to work with
4 * any host computer software package.
6 * To download a host software package, please click on the following link
7 * to open the list of Firmata client libraries in your default browser.
9 * https://github.com/firmata/arduino#firmata-client-libraries
12 /* This firmware supports as many servos as possible using the Servo library
13 * included in Arduino 0017
15 * This example code is in the public domain.
21 Servo servos[MAX_SERVOS];
22 byte servoPinMap[TOTAL_PINS];
25 void analogWriteCallback(byte pin, int value)
27 if (IS_PIN_DIGITAL(pin)) {
28 servos[servoPinMap[pin]].write(value);
32 void systemResetCallback()
41 Firmata.setFirmwareVersion(FIRMATA_FIRMWARE_MAJOR_VERSION, FIRMATA_FIRMWARE_MINOR_VERSION);
42 Firmata.attach(ANALOG_MESSAGE, analogWriteCallback);
43 Firmata.attach(SYSTEM_RESET, systemResetCallback);
46 systemResetCallback();
48 // attach servos from first digital pin up to max number of
49 // servos supported for the board
50 for (pin = 0; pin < TOTAL_PINS; pin++) {
51 if (IS_PIN_DIGITAL(pin)) {
52 if (servoCount < MAX_SERVOS) {
53 servoPinMap[pin] = servoCount;
54 servos[servoPinMap[pin]].attach(PIN_TO_DIGITAL(pin));
63 while (Firmata.available())
64 Firmata.processInput();