From 0887b98f627500271b5ad8b3c4f6c7b90bc227ee Mon Sep 17 00:00:00 2001 From: Thibaut VIARD Date: Tue, 21 Jun 2011 00:20:43 +0200 Subject: Moving all AVR specific libraries to hardware/avr --- .../SimpleAnalogFirmata/SimpleAnalogFirmata.pde | 35 ++++++++++++++++++++++ 1 file changed, 35 insertions(+) create mode 100644 libraries/Firmata/examples/SimpleAnalogFirmata/SimpleAnalogFirmata.pde (limited to 'libraries/Firmata/examples/SimpleAnalogFirmata/SimpleAnalogFirmata.pde') diff --git a/libraries/Firmata/examples/SimpleAnalogFirmata/SimpleAnalogFirmata.pde b/libraries/Firmata/examples/SimpleAnalogFirmata/SimpleAnalogFirmata.pde new file mode 100644 index 0000000..b505b33 --- /dev/null +++ b/libraries/Firmata/examples/SimpleAnalogFirmata/SimpleAnalogFirmata.pde @@ -0,0 +1,35 @@ +/* Supports as many analog inputs and analog PWM outputs as possible. + * + * This example code is in the public domain. + */ +#include + +byte analogPin = 0; + +void analogWriteCallback(byte pin, int value) +{ + if (IS_PIN_PWM(pin)) { + pinMode(PIN_TO_DIGITAL(pin), OUTPUT); + analogWrite(PIN_TO_PWM(pin), value); + } +} + +void setup() +{ + Firmata.setFirmwareVersion(0, 1); + Firmata.attach(ANALOG_MESSAGE, analogWriteCallback); + Firmata.begin(57600); +} + +void loop() +{ + while(Firmata.available()) { + Firmata.processInput(); + } + // do one analogRead per loop, so if PC is sending a lot of + // analog write messages, we will only delay 1 analogRead + Firmata.sendAnalog(analogPin, analogRead(analogPin)); + analogPin = analogPin + 1; + if (analogPin >= TOTAL_ANALOG_PINS) analogPin = 0; +} + -- cgit v1.2.3-18-g5258