Serial Communication Using Various Languages - Arduino Uno Quick Start Manual

Hide thumbs Also See for Arduino Uno:
Table of Contents

Advertisement

Serial Communication Using Various Languages

When working with the Arduino, you often have to talk to it using a serial
port. In this section, you ll learn how to do that in various programming lan-
guages. For demonstration purposes, we ll use the same Arduino sketch for
all of them:
SerialProgramming/AnalogReader/AnalogReader.ino
const unsigned int
BAUD_RATE = 9600;
const unsigned int
NUM_PINS = 6;
String
pin_name = "";
boolean input_available = false;
void
setup() {
Serial.begin(BAUD_RATE);
}
void
loop() {
if
(input_available) {
if
(pin_name.length() > 1 &&
(pin_name[0] ==
{
const unsigned int
if
(pin < NUM_PINS) {
Serial.print(pin_name);
Serial.print(":
Serial.println(analogRead(pin));
}
else
{
Serial.print("Unknown pin:
Serial.println(pin);
}
}
else
{
Serial.print("Unknown pin name:
Serial.println(pin_name);
}
pin_name = "";
input_available = false;
}
}
void
serialEvent() {
while
(Serial.available()) {
const char
c = Serial.read();
if
(c == '\n')
input_available = true;
else
pin_name += c;
}
}
Serial Communication Using Various Languages
'a'
|| pin_name[0] == 'A'))
pin = pin_name.substring(1).toInt();
");
");
");
www.it-ebooks.info
255
report erratum
discuss

Hide quick links:

Advertisement

Table of Contents
loading
Need help?

Need help?

Do you have a question about the Arduino Uno and is the answer not in the manual?

Table of Contents