source: rtos_arduino/trunk/arduino_lib/libraries/Firmata/examples/SimpleAnalogFirmata/SimpleAnalogFirmata.ino@ 136

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

ライブラリとOS及びベーシックなサンプルの追加.

File size: 1.1 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/* Supports as many analog inputs and analog PWM outputs as possible.
13 *
14 * This example code is in the public domain.
15 */
16#include <Firmata.h>
17
18byte analogPin = 0;
19
20void analogWriteCallback(byte pin, int value)
21{
22 if (IS_PIN_PWM(pin)) {
23 pinMode(PIN_TO_DIGITAL(pin), OUTPUT);
24 analogWrite(PIN_TO_PWM(pin), value);
25 }
26}
27
28void setup()
29{
30 Firmata.setFirmwareVersion(0, 1);
31 Firmata.attach(ANALOG_MESSAGE, analogWriteCallback);
32 Firmata.begin(57600);
33}
34
35void loop()
36{
37 while (Firmata.available()) {
38 Firmata.processInput();
39 }
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;
45}
46
Note: See TracBrowser for help on using the repository browser.