January 2015
Beginner
324 pages
7h 42m
English
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 languages. 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] == 'a' || pin_name[0] == 'A')) |
| | { |
| | const unsigned int pin = pin_name.substring(1).toInt(); |
| | if (pin < NUM_PINS) { |
| | |
Read now
Unlock full access