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 | * TODO add message to configure minPulse/maxPulse/degrees
|
---|
16 | *
|
---|
17 | * This example code is in the public domain.
|
---|
18 | */
|
---|
19 |
|
---|
20 | #include <Servo.h>
|
---|
21 | #include <Firmata.h>
|
---|
22 |
|
---|
23 | Servo servos[MAX_SERVOS];
|
---|
24 |
|
---|
25 | void analogWriteCallback(byte pin, int value)
|
---|
26 | {
|
---|
27 | if (IS_PIN_SERVO(pin)) {
|
---|
28 | servos[PIN_TO_SERVO(pin)].write(value);
|
---|
29 | }
|
---|
30 | }
|
---|
31 |
|
---|
32 | void setup()
|
---|
33 | {
|
---|
34 | byte pin;
|
---|
35 |
|
---|
36 | Firmata.setFirmwareVersion(0, 2);
|
---|
37 | Firmata.attach(ANALOG_MESSAGE, analogWriteCallback);
|
---|
38 |
|
---|
39 | for (pin = 0; pin < TOTAL_PINS; pin++) {
|
---|
40 | if (IS_PIN_SERVO(pin)) {
|
---|
41 | servos[PIN_TO_SERVO(pin)].attach(PIN_TO_DIGITAL(pin));
|
---|
42 | }
|
---|
43 | }
|
---|
44 |
|
---|
45 | Firmata.begin(57600);
|
---|
46 | }
|
---|
47 |
|
---|
48 | void loop()
|
---|
49 | {
|
---|
50 | while (Firmata.available())
|
---|
51 | Firmata.processInput();
|
---|
52 | }
|
---|
53 |
|
---|
Note:
See
TracBrowser
for help on using the repository browser.