source: rtos_arduino/trunk/arduino_lib/libraries/Firmata/examples/ServoFirmata/ServoFirmata.ino@ 224

Last change on this file since 224 was 224, checked in by ertl-honda, 8 years ago

1.7.10のファイルに更新

File size: 1.5 KB
Line 
1/*
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.
5 *
6 * To download a host software package, please clink on the following link
7 * to open the download page in your default browser.
8 *
9 * http://firmata.org/wiki/Download
10 */
11
12/* This firmware supports as many servos as possible using the Servo library
13 * included in Arduino 0017
14 *
15 * This example code is in the public domain.
16 */
17
18#include <Servo.h>
19#include <Firmata.h>
20
21Servo servos[MAX_SERVOS];
22byte servoPinMap[TOTAL_PINS];
23byte servoCount = 0;
24
25void analogWriteCallback(byte pin, int value)
26{
27 if (IS_PIN_DIGITAL(pin)) {
28 servos[servoPinMap[pin]].write(value);
29 }
30}
31
32void systemResetCallback()
33{
34 servoCount = 0;
35}
36
37void setup()
38{
39 byte pin;
40
41 Firmata.setFirmwareVersion(FIRMATA_FIRMWARE_MAJOR_VERSION, FIRMATA_FIRMWARE_MINOR_VERSION);
42 Firmata.attach(ANALOG_MESSAGE, analogWriteCallback);
43 Firmata.attach(SYSTEM_RESET, systemResetCallback);
44
45 Firmata.begin(57600);
46 systemResetCallback();
47
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));
55 servoCount++;
56 }
57 }
58 }
59}
60
61void loop()
62{
63 while (Firmata.available())
64 Firmata.processInput();
65}
Note: See TracBrowser for help on using the repository browser.