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 download page in your default browser.
9 * http://firmata.org/wiki/Download
12 /* Supports as many analog inputs and analog PWM outputs as possible.
14 * This example code is in the public domain.
20 void analogWriteCallback(byte pin, int value)
22 if (IS_PIN_PWM(pin)) {
23 pinMode(PIN_TO_DIGITAL(pin), OUTPUT);
24 analogWrite(PIN_TO_PWM(pin), value);
30 Firmata.setFirmwareVersion(FIRMATA_FIRMWARE_MAJOR_VERSION, FIRMATA_FIRMWARE_MINOR_VERSION);
31 Firmata.attach(ANALOG_MESSAGE, analogWriteCallback);
37 while (Firmata.available()) {
38 Firmata.processInput();
40 // do one analogRead per loop, so if PC is sending a lot of
41 // analog write messages, we will only delay 1 analogRead
42 Firmata.sendAnalog(analogPin, analogRead(analogPin));
43 analogPin = analogPin + 1;
44 if (analogPin >= TOTAL_ANALOG_PINS) analogPin = 0;