EasyManuals Logo

Arduino Pro Mini User Manual

Arduino Pro Mini
311 pages
To Next Page IconTo Next Page
To Next Page IconTo Next Page
To Previous Page IconTo Previous Page
To Previous Page IconTo Previous Page
Page #268 background imageLoading...
Page #268 background image
Serial Communication Using Various Languages
When working with the Arduino, you often have to talk to it using a serial
port. In this section, youll learn how to do that in various programming lan-
guages. For demonstration purposes, well 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] == 'a' || pin_name[0] == 'A'))
{
const unsigned int pin = pin_name.substring(1).toInt();
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;
}
}
report erratum discuss
Serial Communication Using Various Languages 255
www.it-ebooks.info

Table of Contents

Questions and Answers:

Question and Answer IconNeed help?

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

Arduino Pro Mini Specifications

General IconGeneral
BrandArduino
ModelPro Mini
CategoryMotherboard
LanguageEnglish

Related product manuals