The status of pins is sent as messages to and from the software on the host
machine. Messages can be addressed to digital and analog pins. To send the
status of an analog pin, use sendAnalog() :
Firmata.sendAnalog(byte pin, int value);
The pin parameter is the analog pin you are requesting information about.
The value parameter is the value read from the pin. This function does not read
the pin value directly; you must explicitly read the value i rst:
analogValue = analogRead(pin);
Digital pins are sent differently. Because serial connections are slow, relative
to the speed of a microprocessor, something had to be done to speed up the
transfer. Digital pins are either on or off, 1 or 0. To send the maximum amount
of information in the minimum packet size, multiple pins are sent in a single
Firmata.sendDigitalPorts(pin, firstPort, secondPort);
Up to eight pins can be sent in the pin parameter, sent as a byte. The pins
must be sent in order; when starting at pin 6, it must be followed by pin 7, pin
8, and so on. To set the i rst pin, use the firstPort parameter sent as a byte. To
set the number of pins sent, use the secondPort parameter. The pin data will
be sent to the computer, specifying that the data received is the data of the pins
from firstPort to secondPort .
This works well when sending a range of pin data but is not efi cient if you
want to send the status of a single pin or if the pins are not linear. You can also
send the data of a single pin using sendDigitalPort() :
This function sends the status of the pin and sends the pin input as value .
To send a string to the host computer, use sendString() :
This sends the String string to the host computer.
Receiving messages on an Arduino is the same as working with other types of
serial information; i rst, you must wait until you have received data and then