Skip to content

Latest commit

 

History

History
90 lines (56 loc) · 2.81 KB

readwrite.md

File metadata and controls

90 lines (56 loc) · 2.81 KB

Reading and Writing

Digital

These functions are use to get information from, and send information to, the digital pins.

digitalRead();
digitalWrite();

These functions are specific to the Arduino language, since they communicate directly with the hardware pins. Being digital, the expected responses are either 1 or 0 - in other words the pin can only be either on or off. It is, however, possible to alter the speed, or frequency, that the pins turn on and off at using a technique known as Pulse Width Modulation. In the Arduino world, not all pins are created equal, as only the digital pins specifically labelled with PWM are capable of this. PWM pins may also be identified by the tilde character, ~, beside the pin number.

Analog


analogRead();
analogWrite();

Serial

Rather than being functions by themselves, the following are functions that are made available through the Serial library. When printing data standard escape characters (create table) are supported, however the full functionalities of a function like printf() and scanf() in the C language are not available in Arduino.

Serial.begin();

Serial.available();

Serial.read();

Serial.write();

Serial.print();

Serial.println();


Chasing Chars

Typically converting between typed characters (Latin, Cyrillic, Arabic etc.) is handled by something like an ASCII table, or some extended version. [add some background]

The following gist gives an example of this. It stores the input as an integer and then displays it either as the keyboard character we just pressed or its underlying ASCII value:

Download Code

For you convenience I've also prepared a searchable table with 128 different characters and their corresponding numeric values.

Searchable ASCII Table

Traffic Lights Revisited

In this example, the Arduino accepts values through the serial monitor and changes the state of the LEDs accordingly.

Download Code

Stream

For the sake of completeness, it is worth mentioning the functions of the Stream library.

available()
read()
flush()
find()
findUntil()
peek()
readBytes()
readBytesUntil()
readString()
readStringUntil()
parseInt()
parsefloat()
setTimeout()

Stretch Goal

Where to?

Next Section Arduino Resources