From 2232e7c10ec05aeadf86a9eb663e1c8e8a82fe8b Mon Sep 17 00:00:00 2001 From: Akshay Sharma Date: Tue, 17 Feb 2015 11:17:43 +0530 Subject: [PATCH 01/13] Add content Functions/Advanced IO --- Language/Functions/Advanced IO/noTone.adoc | 57 ++++++++ Language/Functions/Advanced IO/pulseIn.adoc | 71 ++++++++++ Language/Functions/Advanced IO/shiftIn.adoc | 62 +++++++++ Language/Functions/Advanced IO/shiftOut.adoc | 132 +++++++++++++++++++ Language/Functions/Advanced IO/tone.adoc | 78 +++++++++++ 5 files changed, 400 insertions(+) create mode 100644 Language/Functions/Advanced IO/noTone.adoc create mode 100644 Language/Functions/Advanced IO/pulseIn.adoc create mode 100644 Language/Functions/Advanced IO/shiftIn.adoc create mode 100644 Language/Functions/Advanced IO/shiftOut.adoc create mode 100644 Language/Functions/Advanced IO/tone.adoc diff --git a/Language/Functions/Advanced IO/noTone.adoc b/Language/Functions/Advanced IO/noTone.adoc new file mode 100644 index 000000000..2b8fba057 --- /dev/null +++ b/Language/Functions/Advanced IO/noTone.adoc @@ -0,0 +1,57 @@ +:source-highlighter: pygments +:pygments-style: arduino +:ext-relative: adoc + + += Entity title() + + +// OVERVIEW SECTION STARTS +[#overview] +-- + +[float] +=== Description +Stops the generation of a square wave triggered by `tone()`. Has no effect if no tone is being generated. +[%hardbreaks] + + +[float] +=== Syntax +`noTone(pin)` + + +[float] +=== Parameters +`pin`: the pin on which to stop generating the tone + +[float] +=== Returns +Nothing + +-- +// OVERVIEW SECTION ENDS + + + + +// HOW TO USE SECTION STARTS +[#howtouse] +-- + +[float] +=== Notes and Warnings +If you want to play different pitches on multiple pins, you need to call noTone() on one pin before calling `tone()` on the next pin. +[%hardbreaks] + +[float] +=== See also +// Link relevant content by category, such as other Reference terms (please add the tag #LANGUAGE#), +// definitions (please add the tag #DEFINITION#), and examples of Projects and Tutorials +// (please add the tag #EXAMPLE#) ►►►►► THIS SECTION IS MANDATORY ◄◄◄◄◄ + +[role="language"] +* #LANGUAGE# link:tone{ext-relative}[tone()] + +-- +// HOW TO USE SECTION ENDS diff --git a/Language/Functions/Advanced IO/pulseIn.adoc b/Language/Functions/Advanced IO/pulseIn.adoc new file mode 100644 index 000000000..08917c26d --- /dev/null +++ b/Language/Functions/Advanced IO/pulseIn.adoc @@ -0,0 +1,71 @@ +:source-highlighter: pygments +:pygments-style: arduino +:ext-relative: adoc + + += pulseIn() + + +// OVERVIEW SECTION STARTS +[#overview] +-- + +[float] +=== Description +Reads a pulse (either HIGH or LOW) on a pin. For example, if *value* is *HIGH*, `pulseIn()` waits for the pin to go *HIGH*, starts timing, then waits for the pin to go *LOW* and stops timing. Returns the length of the pulse in microseconds. Gives up and returns 0 if no pulse starts within a specified time out. + +The timing of this function has been determined empirically and will probably show errors in longer pulses. Works on pulses from 10 microseconds to 3 minutes in length. +[%hardbreaks] + + +[float] +=== Syntax +`pulseIn(pin, value)` + +`pulseIn(pin, value, timeout)` + +[float] +=== Parameters +`pin`: the number of the pin on which you want to read the pulse. (int) + +`value`: type of pulse to read: either link:HIGH{ext-relative}[HIGH] or link:LOW{ext-relative}[LOW]. (int) + +`timeout` (optional): the number of microseconds to wait for the pulse to start; default is one second (unsigned long) +[float] +=== Returns +the length of the pulse (in microseconds) or 0 if no pulse started before the timeout (unsigned long) + +-- +// OVERVIEW SECTION ENDS + + + + +// HOW TO USE SECTION STARTS +[#howtouse] +-- + +[float] +=== Example Code +// Describe what the example code is all about and add relevant code ►►►►► THIS SECTION IS MANDATORY ◄◄◄◄◄ +The example calculated the time duration of a pulse on pin 7. + +[source,arduino] +---- +int pin = 7; +unsigned long duration; + +void setup() +{ + pinMode(pin, INPUT); +} + +void loop() +{ + duration = pulseIn(pin, HIGH); +} +---- +[%hardbreaks] + +-- +// HOW TO USE SECTION ENDS diff --git a/Language/Functions/Advanced IO/shiftIn.adoc b/Language/Functions/Advanced IO/shiftIn.adoc new file mode 100644 index 000000000..795de0077 --- /dev/null +++ b/Language/Functions/Advanced IO/shiftIn.adoc @@ -0,0 +1,62 @@ +:source-highlighter: pygments +:pygments-style: arduino +:ext-relative: adoc + + += shiftIn() + + +// OVERVIEW SECTION STARTS +[#overview] +-- + +[float] +=== Description +Shifts in a byte of data one bit at a time. Starts from either the most (i.e. the leftmost) or least (rightmost) significant bit. For each bit, the clock pin is pulled high, the next bit is read from the data line, and then the clock pin is taken low. + +If you're interfacing with a device that's clocked by rising edges, you'll need to make sure that the clock pin is low before the first call to `shiftIn()`, e.g. with a call to `digitalWrite(clockPin, LOW)`. + +Note: this is a software implementation; Arduino also provides an link:SPI{ext-relative}[SPI library] that uses the hardware implementation, which is faster but only works on specific pins. +[%hardbreaks] + + +[float] +=== Syntax +`byte incoming = shiftIn(dataPin, clockPin, bitOrder)` + + +[float] +=== Parameters +`dataPin`: the pin on which to input each bit (int) + +`clockPin`: the pin to toggle to signal a read from *dataPin* + +`bitOrder`: which order to shift in the bits; either *MSBFIRST* or *LSBFIRST*. +(Most Significant Bit First, or, Least Significant Bit First) + +[float] +=== Returns +the value read (byte) + +-- +// OVERVIEW SECTION ENDS + + + + +// HOW TO USE SECTION STARTS +[#howtouse] +-- + +[float] +=== See also +// Link relevant content by category, such as other Reference terms (please add the tag #LANGUAGE#), +// definitions (please add the tag #DEFINITION#), and examples of Projects and Tutorials +// (please add the tag #EXAMPLE#) ►►►►► THIS SECTION IS MANDATORY ◄◄◄◄◄ + +[role="language"] +* #LANGUAGE# link:shiftOut{ext-relative}[shiftOut()] + +* #LANGUAGE# link:SPI{ext-relative}[SPI] + +-- +// HOW TO USE SECTION ENDS diff --git a/Language/Functions/Advanced IO/shiftOut.adoc b/Language/Functions/Advanced IO/shiftOut.adoc new file mode 100644 index 000000000..4ce70be84 --- /dev/null +++ b/Language/Functions/Advanced IO/shiftOut.adoc @@ -0,0 +1,132 @@ +:source-highlighter: pygments +:pygments-style: arduino +:ext-relative: adoc + + += shiftOut() + + +// OVERVIEW SECTION STARTS +[#overview] +-- + +[float] +=== Description +Shifts out a byte of data one bit at a time. Starts from either the most (i.e. the leftmost) or least (rightmost) significant bit. Each bit is written in turn to a data pin, after which a clock pin is pulsed (taken high, then low) to indicate that the bit is available. + +Note- if you're interfacing with a device that's clocked by rising edges, you'll need to make sure that the clock pin is low before the call to `shiftOut()`, e.g. with a call to `digitalWrite(clockPin, LOW)`. + +This is a software implementation; see also the link:SPI{ext-relative}[SPI library], which provides a hardware implementation that is faster but works only on specific pins. +[%hardbreaks] + + +[float] +=== Syntax +`shiftOut(dataPin, clockPin, bitOrder, value)` + + +[float] +=== Parameters +`dataPin`: the pin on which to output each bit (int) + +`clockPin`: the pin to toggle once the dataPin has been set to the correct value (int) + +`bitOrder`: which order to shift out the bits; either MSBFIRST or LSBFIRST. +(Most Significant Bit First, or, Least Significant Bit First) + +`value`: the data to shift out. (byte) + +[float] +=== Returns +Nothing + +-- +// OVERVIEW SECTION ENDS + + + + +// HOW TO USE SECTION STARTS +[#howtouse] +-- + +[float] +=== Example Code +// Describe what the example code is all about and add relevant code ►►►►► THIS SECTION IS MANDATORY ◄◄◄◄◄ +For accompanying circuit, see the http://arduino.cc/en/Tutorial/ShiftOut[tutorial on controlling a 74HC595 shift register]. + +[source,arduino] +---- +//**************************************************************// +// Name : shiftOutCode, Hello World // +// Author : Carlyn Maw,Tom Igoe // +// Date : 25 Oct, 2006 // +// Version : 1.0 // +// Notes : Code for using a 74HC595 Shift Register // +// : to count from 0 to 255 // +//**************************************************************** + +//Pin connected to ST_CP of 74HC595 +int latchPin = 8; +//Pin connected to SH_CP of 74HC595 +int clockPin = 12; +////Pin connected to DS of 74HC595 +int dataPin = 11; + +void setup() { + //set pins to output because they are addressed in the main loop + pinMode(latchPin, OUTPUT); + pinMode(clockPin, OUTPUT); + pinMode(dataPin, OUTPUT); +} + +void loop() { + //count up routine + for (int j = 0; j < 256; j++) { + //ground latchPin and hold low for as long as you are transmitting + digitalWrite(latchPin, LOW); + shiftOut(dataPin, clockPin, LSBFIRST, j); + //return the latch pin high to signal chip that it + //no longer needs to listen for information + digitalWrite(latchPin, HIGH); + delay(1000); + } +} +---- +[%hardbreaks] + +[float] +=== Notes and Warnings +The dataPin and clockPin must already be configured as outputs by a call to link:pinMode{ext-relative}[pinMode()]. + +shiftOut is currently written to output 1 byte (8 bits) so it requires a two step operation to output values larger than 255. +[source,arduino] +---- +// Do this for MSBFIRST serial +int data = 500; +// shift out highbyte +shiftOut(dataPin, clock, MSBFIRST, (data >> 8)); +// shift out lowbyte +shiftOut(dataPin, clock, MSBFIRST, data); + +// Or do this for LSBFIRST serial +data = 500; +// shift out lowbyte +shiftOut(dataPin, clock, LSBFIRST, data); +// shift out highbyte +shiftOut(dataPin, clock, LSBFIRST, (data >> 8)); +---- +[%hardbreaks] + +[float] +=== See also +// Link relevant content by category, such as other Reference terms (please add the tag #LANGUAGE#), +// definitions (please add the tag #DEFINITION#), and examples of Projects and Tutorials +// (please add the tag #EXAMPLE#) ►►►►► THIS SECTION IS MANDATORY ◄◄◄◄◄ + +[role="language"] +* #LANGUAGE# link:shiftIn{ext-relative}[shiftIn()] + +* #LANGUAGE# link:SPI{ext-relative}[SPI] + +-- +// HOW TO USE SECTION ENDS diff --git a/Language/Functions/Advanced IO/tone.adoc b/Language/Functions/Advanced IO/tone.adoc new file mode 100644 index 000000000..c890b0631 --- /dev/null +++ b/Language/Functions/Advanced IO/tone.adoc @@ -0,0 +1,78 @@ +:source-highlighter: pygments +:pygments-style: arduino +:ext-relative: adoc + + += tone() + + +// OVERVIEW SECTION STARTS +[#overview] +-- + +[float] +=== Description +Generates a square wave of the specified frequency (and 50% duty cycle) on a pin. A duration can be specified, otherwise the wave continues until a call to link:noTone{ext-relative}[noTone()]. The pin can be connected to a piezo buzzer or other speaker to play tones. + +Only one tone can be generated at a time. If a tone is already playing on a different pin, the call to tone() will have no effect. If the tone is playing on the same pin, the call will set its frequency. + +Use of the `tone()` function will interfere with PWM output on pins 3 and 11 (on boards other than the Mega). + +It is not possible to generate tones lower than 31Hz. For technical details, see https://code.google.com/p/rogue-code/wiki/ToneLibraryDocumentation#Ugly_Details[Brett Hagman's notes]. +[%hardbreaks] + + +[float] +=== Syntax +`tone(pin, frequency)` + +`tone(pin, frequency, duration)` +[%hardbreaks] + +[float] +=== Parameters +`pin`: the pin on which to generate the tone + +`frequency`: the frequency of the tone in hertz - `unsigned int` + +`duration`: the duration of the tone in milliseconds (optional) - `unsigned long` +[%hardbreaks] + +[float] +=== Returns +Nothing + +-- +// OVERVIEW SECTION ENDS + + + + +// HOW TO USE SECTION STARTS +[#howtouse] +-- + +[float] +=== Notes and Warnings +If you want to play different pitches on multiple pins, you need to call `noTone()` on one pin before calling `tone() on the next pin. +[%hardbreaks] + +[float] +=== See also +// Link relevant content by category, such as other Reference terms (please add the tag #LANGUAGE#), +// definitions (please add the tag #DEFINITION#), and examples of Projects and Tutorials +// (please add the tag #EXAMPLE#) ►►►►► THIS SECTION IS MANDATORY ◄◄◄◄◄ + +[role="language"] +* #LANGUAGE# link:noTone{ext-relative}[noTone()] + +* #LANGUAGE# link:analogWrite{ext-relative}[analogWrite()] + +[role="example"] +* #EXAMPLE# http://arduino.cc/en/Tutorial/Tone[Tone^] + +* #EXAMPLE# http://arduino.cc/en/Tutorial/Tone[Pitch follower^] + +* #EXAMPLE# http://arduino.cc/en/Tutorial/Tone3[Simple Keyboard^] + +* #EXAMPLE# http://arduino.cc/en/Tutorial/Tone4[multiple tones^] + +* #EXAMPLE# http://arduino.cc/en/Tutorial/PWM[PWM^] + +-- +// HOW TO USE SECTION ENDS From 7dccfa9dc237a65b13b4a20e7fb9d369a2309fa9 Mon Sep 17 00:00:00 2001 From: Akshay Sharma Date: Tue, 17 Feb 2015 15:31:42 +0530 Subject: [PATCH 02/13] Add content Functions/Analog IO --- Language/Functions/Analog IO/analogRead.adoc | 86 +++++++++++++++++++ .../Functions/Analog IO/analogReference.adoc | 70 +++++++++++++++ 2 files changed, 156 insertions(+) create mode 100644 Language/Functions/Analog IO/analogRead.adoc create mode 100644 Language/Functions/Analog IO/analogReference.adoc diff --git a/Language/Functions/Analog IO/analogRead.adoc b/Language/Functions/Analog IO/analogRead.adoc new file mode 100644 index 000000000..befd7ffb3 --- /dev/null +++ b/Language/Functions/Analog IO/analogRead.adoc @@ -0,0 +1,86 @@ +:source-highlighter: pygments +:pygments-style: arduino +:ext-relative: adoc + + += analogRead() + + +// OVERVIEW SECTION STARTS +[#overview] +-- + +[float] +=== Description +Reads the value from the specified analog pin. The Arduino board contains a 6 channel (8 channels on the Mini and Nano, 16 on the Mega), 10-bit analog to digital converter. This means that it will map input voltages between 0 and 5 volts into integer values between 0 and 1023. This yields a resolution between readings of: 5 volts / 1024 units or, .0049 volts (4.9 mV) per unit. The input range and resolution can be changed using link:analogReference{ext-relative}[analogReference()]`. + +It takes about 100 microseconds (0.0001 s) to read an analog input, so the maximum reading rate is about 10,000 times a second. +[%hardbreaks] + + +[float] +=== Syntax + +`analogRead(pin)` + +[float] +=== Parameters +`pin`: the number of the analog input pin to read from (0 to 5 on most boards, 0 to 7 on the Mini and Nano, 0 to 15 on the Mega) + +[float] +=== Returns +int(0 to 1023) + +-- +// OVERVIEW SECTION ENDS + + + + +// HOW TO USE SECTION STARTS +[#howtouse] +-- + +[float] +=== Example Code +// Describe what the example code is all about and add relevant code ►►►►► THIS SECTION IS MANDATORY ◄◄◄◄◄ +The code reads the voltage on analogPin and displays it. + +[source,arduino] +---- +int analogPin = 3; // potentiometer wiper (middle terminal) connected to analog pin 3 + // outside leads to ground and +5V +int val = 0; // variable to store the value read + +void setup() +{ + Serial.begin(9600); // setup serial +} + +void loop() +{ + val = analogRead(analogPin); // read the input pin + Serial.println(val); // debug value +} +---- +[%hardbreaks] + +[float] +=== Notes and Warnings +If the analog input pin is not connected to anything, the value returned by analogRead() will fluctuate based on a number of factors (e.g. the values of the other analog inputs, how close your hand is to the board, etc.). +[%hardbreaks] + +[float] +=== See also +// Link relevant content by category, such as other Reference terms (please add the tag #LANGUAGE#), +// definitions (please add the tag #DEFINITION#), and examples of Projects and Tutorials +// (please add the tag #EXAMPLE#) ►►►►► THIS SECTION IS MANDATORY ◄◄◄◄◄ + +[role="language"] +* #LANGUAGE# link:analogReference{ext-relative}[analogreference()] + +* #LANGUAGE# link:analogReadResolution{ext-relative}[analogReadResolution()] + +* #LANGUAGE# (http://arduino.cc/en/Tutorial/AnalogInputPins[Tutorial: Analog Input Pins]) + + +-- +// HOW TO USE SECTION ENDS diff --git a/Language/Functions/Analog IO/analogReference.adoc b/Language/Functions/Analog IO/analogReference.adoc new file mode 100644 index 000000000..4fd16cd1f --- /dev/null +++ b/Language/Functions/Analog IO/analogReference.adoc @@ -0,0 +1,70 @@ +:source-highlighter: pygments +:pygments-style: arduino +//:ext-relative: adoc + + += analogReference() + + +// OVERVIEW SECTION STARTS +[#overview] +-- + +[float] +=== Description +Configures the reference voltage used for analog input (i.e. the value used as the top of the input range). The options are: + +* DEFAULT: the default analog reference of 5 volts (on 5V Arduino boards) or 3.3 volts (on 3.3V Arduino boards) +* INTERNAL: an built-in reference, equal to 1.1 volts on the ATmega168 or ATmega328 and 2.56 volts on the ATmega8 (not available on the Arduino Mega) +* INTERNAL1V1: a built-in 1.1V reference (Arduino Mega only) +* INTERNAL2V56: a built-in 2.56V reference (Arduino Mega only) +* EXTERNAL: the voltage applied to the AREF pin (0 to 5V only) is used as the reference. +[%hardbreaks] + + +[float] +=== Syntax +`analogReference(type)` + + +[float] +=== Parameters +`type`: which type of reference to use (DEFAULT, INTERNAL, INTERNAL1V1, INTERNAL2V56, or EXTERNAL). + +[float] +=== Returns +Nothing + +-- +// OVERVIEW SECTION ENDS + + + + +// HOW TO USE SECTION STARTS +[#howtouse] +-- + +[float] +=== Notes and Warnings +After changing the analog reference, the first few readings from `analogRead()` may not be accurate. + +*Don't use anything less than 0V or more than 5V for external reference voltage on the AREF pin! If you're using an external reference on the AREF pin, you must set the analog reference to EXTERNAL before calling `analogRead()`.* Otherwise, you will short together the active reference voltage (internally generated) and the AREF pin, possibly damaging the microcontroller on your Arduino board. + +Alternatively, you can connect the external reference voltage to the AREF pin through a 5K resistor, allowing you to switch between external and internal reference voltages. Note that the resistor will alter the voltage that gets used as the reference because there is an internal 32K resistor on the AREF pin. The two act as a voltage divider, so, for example, 2.5V applied through the resistor will yield 2.5 * 32 / (32 + 5) = ~2.2V at the AREF pin. +[%hardbreaks] + +[float] +=== See also +// Link relevant content by category, such as other Reference terms (please add the tag #LANGUAGE#), +// definitions (please add the tag #DEFINITION#), and examples of Projects and Tutorials +// (please add the tag #EXAMPLE#) ►►►►► THIS SECTON IS MANDATORY ◄◄◄◄◄ + +[role="example"] +* #EXAMPLE# http://arduino.cc/en/Tutorial/AnalogInputPins[Description of analog input pins] + +[role="language"] +* #LANGUAGE# link:analogRead{ext-relative}[analogRead()] + +-- +// HOW TO USE SECTION ENDS From 3693e2987c27da7fe0aceea06e2056d2ce87b161 Mon Sep 17 00:00:00 2001 From: Akshay Sharma Date: Tue, 17 Feb 2015 15:51:43 +0530 Subject: [PATCH 03/13] Add content Functions/Arduino Due only --- .../analogReadResolution.adoc | 110 ++++++++++++++++ .../analogWriteResolution.adoc | 120 ++++++++++++++++++ 2 files changed, 230 insertions(+) create mode 100644 Language/Functions/Arduino DUE only/analogReadResolution.adoc create mode 100644 Language/Functions/Arduino DUE only/analogWriteResolution.adoc diff --git a/Language/Functions/Arduino DUE only/analogReadResolution.adoc b/Language/Functions/Arduino DUE only/analogReadResolution.adoc new file mode 100644 index 000000000..a89830750 --- /dev/null +++ b/Language/Functions/Arduino DUE only/analogReadResolution.adoc @@ -0,0 +1,110 @@ +:source-highlighter: pygments +:pygments-style: arduino +:ext-relative: adoc + += analogReadResolution() + + +// OVERVIEW SECTION STARTS +[#overview] +-- + +[float] +=== Description +analogReadResolution() is an extension of the Analog API for the Arduino Due. + +Sets the size (in bits) of the value returned by analogRead(). It defaults to 10 bits (returns values between 0-1023) for backward compatibility with AVR based boards. + +The *Due has 12-bit ADC capabilities* that can be accessed by changing the resolution to 12. This will return values from analogRead() between 0 and 4095. +[%hardbreaks] + + +[float] +=== Syntax +`analogReadResolution(bits)` + + +[float] +=== Parameters +`bits`: determines the resolution (in bits) of the value returned by `analogRead()` function. You can set this 1 and 32. You can set resolutions higher than 12 but values returned by `analogRead()` will suffer approximation. See the note below for details. + +[float] +=== Returns +Nothing + +-- +// OVERVIEW SECTION ENDS + + + + +// HOW TO USE SECTION STARTS +[#howtouse] +-- + +[float] +=== Example Code +// Describe what the example code is all about and add relevant code ►►►►► THIS SECTION IS MANDATORY ◄◄◄◄◄ +The code shows how to use ADC with different resolutions. + +[source,arduino] +---- +void setup() { + // open a serial connection + Serial.begin(9600); +} + +void loop() { + // read the input on A0 at default resolution (10 bits) + // and send it out the serial connection + analogReadResolution(10); + Serial.print("ADC 10-bit (default) : "); + Serial.print(analogRead(A0)); + + // change the resolution to 12 bits and read A0 + analogReadResolution(12); + Serial.print(", 12-bit : "); + Serial.print(analogRead(A0)); + + // change the resolution to 16 bits and read A0 + analogReadResolution(16); + Serial.print(", 16-bit : "); + Serial.print(analogRead(A0)); + + // change the resolution to 8 bits and read A0 + analogReadResolution(8); + Serial.print(", 8-bit : "); + Serial.println(analogRead(A0)); + + // a little delay to not hog serial monitor + delay(100); +} +---- +[%hardbreaks] + +[float] +=== Notes and Warnings +If you set the `analogReadResolution()` value to a value higher than your board's capabilities, the Arduino will only report back at its highest resolution padding the extra bits with zeros. + +For example: using the Due with `analogReadResolution(16)` will give you an approximated 16-bit number with the first 12 bits containing the real ADC reading and the last 4 bits *padded with zeros*. + +If you set the `analogReadResolution()` value to a value lower than your board's capabilities, the extra least significant bits read from the ADC will be *discarded*. + +Using a 16 bit resolution (or any resolution *higher* than actual hardware capabilities) allows you to write sketches that automatically handle devices with a higher resolution ADC when these become available on future boards without changing a line of code. +[%hardbreaks] + +[float] +=== See also +// Link relevant content by category, such as other Reference terms (please add the tag #LANGUAGE#), +// definitions (please add the tag #DEFINITION#), and examples of Projects and Tutorials +// (please add the tag #EXAMPLE#) ►►►►► THIS SECTION IS MANDATORY ◄◄◄◄◄ + +[role="example"] +* #EXAMPLE# http://arduino.cc/en/Tutorial/AnalogInputPins[Description of the analog input pins] + +[role="language"] +* #LANGUAGE# link:analofRead{ext-relative}[analogRead()] + + +-- +// HOW TO USE SECTION ENDS diff --git a/Language/Functions/Arduino DUE only/analogWriteResolution.adoc b/Language/Functions/Arduino DUE only/analogWriteResolution.adoc new file mode 100644 index 000000000..712a0f2fb --- /dev/null +++ b/Language/Functions/Arduino DUE only/analogWriteResolution.adoc @@ -0,0 +1,120 @@ +:source-highlighter: pygments +:pygments-style: arduino +:ext-relative: adoc + += analogWriteResolution() + + +// OVERVIEW SECTION STARTS +[#overview] +-- + +[float] +=== Description +`analogWriteResolution()` is an extension of the Analog API for the Arduino Due. + +`analogWriteResolution()` sets the resolution of the `analogWrite()` function. It defaults to 8 bits (values between 0-255) for backward compatibility with AVR based boards. + +The Due has the following hardare capabilities +* 12 pins which default to 8-bit PWM, like the AVR-based boards. These can be changed to 12-bit resolution. +* Pns with 12-bit DAC (Digital-to-Analog Converter). + +By setting the write resolution to 12, you can use `analogWrite()` with values between 0 and 4095 to exploit the full DAC resolution or to set the PWM signal without rolling over. +[%hardbreaks] + + +[float] +=== Syntax +`analogWriteResolution(bits)` + + +[float] +=== Parameters +`bits`: determines the resolution (in bits) of the values used in the `analogWrite()` function. The value can range from 1 to 32. If you choose a resolution higher or lower than your board's hardware capabilities, the value used in `analogWrite()` will be either truncated if it's too high or padded with zeros if it's too low. See the note below for details. + +[float] +=== Returns +Nothing + +-- +// OVERVIEW SECTION ENDS + + + + +// HOW TO USE SECTION STARTS +[#howtouse] +-- + +[float] +=== Example Code +// Describe what the example code is all about and add relevant code ►►►►► THIS SECTION IS MANDATORY ◄◄◄◄◄ +Explain Code + +[source,arduino] +---- +void setup(){ + // open a serial connection + Serial.begin(9600); + // make our digital pin an output + pinMode(11, OUTPUT); + pinMode(12, OUTPUT); + pinMode(13, OUTPUT); +} + +void loop(){ + // read the input on A0 and map it to a PWM pin + // with an attached LED + int sensorVal = analogRead(A0); + Serial.print("Analog Read) : "); + Serial.print(sensorVal); + + // the default PWM resolution + analogWriteResolution(8); + analogWrite(11, map(sensorVal, 0, 1023, 0 ,255)); + Serial.print(" , 8-bit PWM value : "); + Serial.print(map(sensorVal, 0, 1023, 0 ,255)); + + // change the PWM resolution to 12 bits + // the full 12 bit resolution is only supported + // on the Due + analogWriteResolution(12); + analogWrite(12, map(sensorVal, 0, 1023, 0, 4095)); + Serial.print(" , 12-bit PWM value : "); + Serial.print(map(sensorVal, 0, 1023, 0, 4095)); + + // change the PWM resolution to 4 bits + analogWriteResolution(4); + analogWrite(13, map(sensorVal, 0, 1023, 0, 127)); + Serial.print(", 4-bit PWM value : "); + Serial.println(map(sensorVal, 0, 1023, 0, 127)); + + delay(5); +} +---- +[%hardbreaks] + +[float] +=== Notes and Warnings +If you set the `analogWriteResolution()` value to a value higher than your board's capabilities, the Arduino will discard the extra bits. For example: using the Due with `analogWriteResolution(16)` on a 12-bit DAC pin, only the first 12 bits of the values passed to `analogWrite()` will be used and the last 4 bits will be discarded. + +If you set the `analogWriteResolution()` value to a value lower than your board's capabilities, the missing bits will be *padded with zeros* to fill the hardware required size. For example: using the Due with analogWriteResolution(8) on a 12-bit DAC pin, the Arduino will add 4 zero bits to the 8-bit value used in `analogWrite()` to obtain the 12 bits required. +[%hardbreaks] + +[float] +=== See also +// Link relevant content by category, such as other Reference terms (please add the tag #LANGUAGE#), +// definitions (please add the tag #DEFINITION#), and examples of Projects and Tutorials +// (please add the tag #EXAMPLE#) ►►►►► THIS SECTION IS MANDATORY ◄◄◄◄◄ + +[role="example"] +* #EXAMPLE# http://arduino.cc/en/Tutorial/AnalogInputPins[Description of the analog input pins] + +[role="language"] +* #LANGUAGE# link:analogWrite{ext-relative}[analogWrite()] + +* #LANGUAGE# link:analogRead{ext-relative}[analogRead()] + +* #LANGUAGE# link:map{ext-relative}[map()] + + +-- +// HOW TO USE SECTION ENDS From 0385efa5ac7b5074049b7c86ab443afe844ffdd4 Mon Sep 17 00:00:00 2001 From: Akshay Sharma Date: Tue, 17 Feb 2015 15:55:12 +0530 Subject: [PATCH 04/13] Add content Functions/Bits and Bytes --- Language/Functions/Bits and Bytes/bit.adoc | 55 +++++++++++++++++ .../Functions/Bits and Bytes/bitClear.adoc | 56 ++++++++++++++++++ .../Functions/Bits and Bytes/bitRead.adoc | 56 ++++++++++++++++++ Language/Functions/Bits and Bytes/bitSet.adoc | 56 ++++++++++++++++++ .../Functions/Bits and Bytes/bitWrite.adoc | 59 +++++++++++++++++++ .../Functions/Bits and Bytes/highByte.adoc | 53 +++++++++++++++++ .../Functions/Bits and Bytes/lowByte.adoc | 52 ++++++++++++++++ 7 files changed, 387 insertions(+) create mode 100644 Language/Functions/Bits and Bytes/bit.adoc create mode 100644 Language/Functions/Bits and Bytes/bitClear.adoc create mode 100644 Language/Functions/Bits and Bytes/bitRead.adoc create mode 100644 Language/Functions/Bits and Bytes/bitSet.adoc create mode 100644 Language/Functions/Bits and Bytes/bitWrite.adoc create mode 100644 Language/Functions/Bits and Bytes/highByte.adoc create mode 100644 Language/Functions/Bits and Bytes/lowByte.adoc diff --git a/Language/Functions/Bits and Bytes/bit.adoc b/Language/Functions/Bits and Bytes/bit.adoc new file mode 100644 index 000000000..10fdf11b5 --- /dev/null +++ b/Language/Functions/Bits and Bytes/bit.adoc @@ -0,0 +1,55 @@ +:source-highlighter: pygments +:pygments-style: arduino +:ext-relative: adoc + + += bit() + + +// OVERVIEW SECTION STARTS +[#overview] +-- + +[float] +=== Description +Computes the value of the specified bit (bit 0 is 1, bit 1 is 2, bit 2 is 4, etc.). +[%hardbreaks] + + +[float] +=== Syntax +`bit(n)` + + +[float] +=== Parameters +`n`: the bit whose value to compute + +[float] +=== Returns +The value of the bit. + +-- +// OVERVIEW SECTION ENDS + + + + +// HOW TO USE SECTION STARTS +[#howtouse] +-- + +[float] +=== See also +// Link relevant content by category, such as other Reference terms (please add the tag #LANGUAGE#), +// definitions (please add the tag #DEFINITION#), and examples of Projects and Tutorials +// (please add the tag #EXAMPLE#) ►►►►► THIS SECTION IS MANDATORY ◄◄◄◄◄ + +[role="language"] +* #LANGUAGE# link:bitRead{ext-relative}[bitRead()] + +* #LANGUAGE# link:bitWrite{ext-relative}[bitWrite()] + +* #LANGUAGE# link:bitSet{ext-relative}[bitSet()] + +* #LANGUAGE# link:bitClear{ext-relative}[bitClear()] + +-- +// HOW TO USE SECTION ENDS diff --git a/Language/Functions/Bits and Bytes/bitClear.adoc b/Language/Functions/Bits and Bytes/bitClear.adoc new file mode 100644 index 000000000..7e9063baa --- /dev/null +++ b/Language/Functions/Bits and Bytes/bitClear.adoc @@ -0,0 +1,56 @@ +:source-highlighter: pygments +:pygments-style: arduino +:ext-relative: adoc + + += bitClear() + + +// OVERVIEW SECTION STARTS +[#overview] +-- + +[float] +=== Description +Clears (writes a 0 to) a bit of a numeric variable. +[%hardbreaks] + + +[float] +=== Syntax +`bitClear(x, n)` + + +[float] +=== Parameters +`x`: the numeric variable whose bit to clear + +`n`: which bit to clear, starting at 0 for the least-significant (rightmost) bit + +[float] +=== Returns +Nothing + +-- +// OVERVIEW SECTION ENDS + + + + +// HOW TO USE SECTION STARTS +[#howtouse] +-- + +[float] +=== See also +// Link relevant content by category, such as other Reference terms (please add the tag #LANGUAGE#), +// definitions (please add the tag #DEFINITION#), and examples of Projects and Tutorials +// (please add the tag #EXAMPLE#) ►►►►► THIS SECTION IS MANDATORY ◄◄◄◄◄ + +[role="language"] +* #LANGUAGE# link:bit{ext-relative}[bit()] + +* #LANGUAGE# link:bitRead{ext-relative}[bitRead()] + +* #LANGUAGE# link:bitWrite{ext-relative}[bitWrite()] + +* #LANGUAGE# link:bitSet{ext-relative}[bitSet()] +-- +// HOW TO USE SECTION ENDS diff --git a/Language/Functions/Bits and Bytes/bitRead.adoc b/Language/Functions/Bits and Bytes/bitRead.adoc new file mode 100644 index 000000000..63ad1a0e8 --- /dev/null +++ b/Language/Functions/Bits and Bytes/bitRead.adoc @@ -0,0 +1,56 @@ +:source-highlighter: pygments +:pygments-style: arduino +:ext-relative: adoc + + += bitRead() + + +// OVERVIEW SECTION STARTS +[#overview] +-- + +[float] +=== Description +Reads a bit of a number. +[%hardbreaks] + + +[float] +=== Syntax +`bitRead(x, n)` + + +[float] +=== Parameters +`x`: the number from which to read + +`n`: which bit to read, starting at 0 for the least-significant (rightmost) bit + + +[float] +=== Returns +the value of the bit (0 or 1). + +-- +// OVERVIEW SECTION ENDS + + + + +// HOW TO USE SECTION STARTS +[#howtouse] +-- + +[float] +=== See also +// Link relevant content by category, such as other Reference terms (please add the tag #LANGUAGE#), +// definitions (please add the tag #DEFINITION#), and examples of Projects and Tutorials +// (please add the tag #EXAMPLE#) ►►►►► THIS SECTION IS MANDATORY ◄◄◄◄◄ + +[role="language"] +* #LANGUAGE# link:bit{ext-relative}[bit()] + +* #LANGUAGE# link:bitWrite{ext-relative}[bitWrite()] + +-- +// HOW TO USE SECTION ENDS diff --git a/Language/Functions/Bits and Bytes/bitSet.adoc b/Language/Functions/Bits and Bytes/bitSet.adoc new file mode 100644 index 000000000..518c3b458 --- /dev/null +++ b/Language/Functions/Bits and Bytes/bitSet.adoc @@ -0,0 +1,56 @@ +:source-highlighter: pygments +:pygments-style: arduino +:ext-relative: adoc + + += bitSet() + + +// OVERVIEW SECTION STARTS +Sets (writes a 1 to) a bit of a numeric variable. +[#overview] +-- + +[float] +=== Description +[%hardbreaks] + + +[float] +=== Syntax +`bitSet(x, n)` + + +[float] +=== Parameters +`x`: the numeric variable whose bit to set + +`n`: which bit to set, starting at 0 for the least-significant (rightmost) bit + +[float] +=== Returns +Nothing + +-- +// OVERVIEW SECTION ENDS + + + + +// HOW TO USE SECTION STARTS +[#howtouse] +-- + +[float] +=== See also +// Link relevant content by category, such as other Reference terms (please add the tag #LANGUAGE#), +// definitions (please add the tag #DEFINITION#), and examples of Projects and Tutorials +// (please add the tag #EXAMPLE#) ►►►►► THIS SECTION IS MANDATORY ◄◄◄◄◄ + +[role="language"] +* #LANGUAGE# link:bit{ext-relative}[bit()] + +* #LANGUAGE# link:bitRead{ext-relative}[bitRead()] + +* #LANGUAGE# link:bitWrite{ext-relative}[bitWrite()] + +* #LANGUAGE# link:bitClear{ext-relative}[bitClear()] +-- +// HOW TO USE SECTION ENDS diff --git a/Language/Functions/Bits and Bytes/bitWrite.adoc b/Language/Functions/Bits and Bytes/bitWrite.adoc new file mode 100644 index 000000000..fa968f4dc --- /dev/null +++ b/Language/Functions/Bits and Bytes/bitWrite.adoc @@ -0,0 +1,59 @@ +:source-highlighter: pygments +:pygments-style: arduino +:ext-relative: adoc + + += bitWrite() + + +// OVERVIEW SECTION STARTS +[#overview] +-- + +[float] +=== Description +Writes a bit of a numeric variable. +[%hardbreaks] + + +[float] +=== Syntax +`bitWrite(x, n, b)` + + +[float] +=== Parameters +`x`: the numeric variable to which to write + +`n`: which bit of the number to write, starting at 0 for the least-significant (rightmost) bit + +`b`: the value to write to the bit (0 or 1) + +[float] +=== Returns +Nothing + +-- +// OVERVIEW SECTION ENDS + + + + +// HOW TO USE SECTION STARTS +[#howtouse] +-- + +[float] +=== See also +// Link relevant content by category, such as other Reference terms (please add the tag #LANGUAGE#), +// definitions (please add the tag #DEFINITION#), and examples of Projects and Tutorials +// (please add the tag #EXAMPLE#) ►►►►► THIS SECTION IS MANDATORY ◄◄◄◄◄ + +[role="language"] +* #LANGUAGE# link:bit{ext-relative}[bit()] + +* #LANGUAGE# link:bitRead{ext-relative}[bitRead()] + +* #LANGUAGE# link:bitSet{ext-relative}[bitSet()] + +* #LANGUAGE# link:bitClear{ext-relative}[bitClear()] + +-- +// HOW TO USE SECTION ENDS diff --git a/Language/Functions/Bits and Bytes/highByte.adoc b/Language/Functions/Bits and Bytes/highByte.adoc new file mode 100644 index 000000000..0afe4f2be --- /dev/null +++ b/Language/Functions/Bits and Bytes/highByte.adoc @@ -0,0 +1,53 @@ +:source-highlighter: pygments +:pygments-style: arduino +:ext-relative: adoc + + += highByte() + + +// OVERVIEW SECTION STARTS +[#overview] +-- + +[float] +=== Description +Extracts the high-order (leftmost) byte of a word (or the second lowest byte of a larger data type). +[%hardbreaks] + + +[float] +=== Syntax +`highByte(x)` + + +[float] +=== Parameters +`x`: a value of any type + +[float] +=== Returns +byte + +-- +// OVERVIEW SECTION ENDS + + + + +// HOW TO USE SECTION STARTS +[#howtouse] +-- + +[float] +=== See also +// Link relevant content by category, such as other Reference terms (please add the tag #LANGUAGE#), +// definitions (please add the tag #DEFINITION#), and examples of Projects and Tutorials +// (please add the tag #EXAMPLE#) ►►►►► THIS SECTION IS MANDATORY ◄◄◄◄◄ + +[role="language"] +* #LANGUAGE# link:lowByte{ext-relative}[lowByte()] + +* #LANGUAGE# link:word{ext-relative}[word()] + +-- +// HOW TO USE SECTION ENDS diff --git a/Language/Functions/Bits and Bytes/lowByte.adoc b/Language/Functions/Bits and Bytes/lowByte.adoc new file mode 100644 index 000000000..1cab5efbd --- /dev/null +++ b/Language/Functions/Bits and Bytes/lowByte.adoc @@ -0,0 +1,52 @@ +:source-highlighter: pygments +:pygments-style: arduino +:ext-relative: adoc + + += lowByte() + + +// OVERVIEW SECTION STARTS +[#overview] +-- + +[float] +=== Description +Extracts the low-order (rightmost) byte of a variable (e.g. a word). +[%hardbreaks] + + +[float] +=== Syntax +`lowByte(x)` + + +[float] +=== Parameters +`x`: a value of any type + +[float] +=== Returns +byte +-- +// OVERVIEW SECTION ENDS + + + + +// HOW TO USE SECTION STARTS +[#howtouse] +-- + +[float] +=== See also +// Link relevant content by category, such as other Reference terms (please add the tag #LANGUAGE#), +// definitions (please add the tag #DEFINITION#), and examples of Projects and Tutorials +// (please add the tag #EXAMPLE#) ►►►►► THIS SECTION IS MANDATORY ◄◄◄◄◄ + +[role="language"] +* #LANGUAGE# link:highByte{ext-relative}[highByte()] + +* #LANGUAGE# link:word{ext-relative}[word()] + +-- +// HOW TO USE SECTION ENDS From 864d3b48c5a8b9b323842c9d341dc9e4aee6c6f5 Mon Sep 17 00:00:00 2001 From: Akshay Sharma Date: Tue, 17 Feb 2015 15:57:40 +0530 Subject: [PATCH 05/13] Add Content Functions/Digital IO --- .../Functions/Digital IO/digitalRead.adoc | 87 ++ .../Functions/Digital IO/digitalRead.html | 867 ++++++++++++++++++ .../Functions/Digital IO/digitalWrite.adoc | 91 ++ Language/Functions/Digital IO/pinMode.adoc | 89 ++ 4 files changed, 1134 insertions(+) create mode 100644 Language/Functions/Digital IO/digitalRead.adoc create mode 100644 Language/Functions/Digital IO/digitalRead.html create mode 100644 Language/Functions/Digital IO/digitalWrite.adoc create mode 100644 Language/Functions/Digital IO/pinMode.adoc diff --git a/Language/Functions/Digital IO/digitalRead.adoc b/Language/Functions/Digital IO/digitalRead.adoc new file mode 100644 index 000000000..50d491068 --- /dev/null +++ b/Language/Functions/Digital IO/digitalRead.adoc @@ -0,0 +1,87 @@ +:source-highlighter: pygments +:pygments-style: arduino +//:ext-relative: adoc +:ext-relative: .html + += digitalRead() + + +// OVERVIEW SECTION STARTS +[#overview] +-- + +[float] +=== Description +Reads the value from a specified digital pin, either `HIGH` or `LOW`. +[%hardbreaks] + + +[float] +=== Syntax +`digitalRead(pin)` + + +[float] +=== Parameters + + +[float] +=== Returns +`HIGH` or `LOW` + +-- +// OVERVIEW SECTION ENDS + + + + +// HOW TO USE SECTION STARTS +[#howtouse] +-- + +[float] +=== Example Code +// Describe what the example code is all about and add relevant code ►►►►► THIS SECTION IS MANDATORY ◄◄◄◄◄ +Sets pin 13 to the same value as pin 7, declared as an input. + +//[source,arduino] +---- +int ledPin = 13; // LED connected to digital pin 13 +int inPin = 7; // pushbutton connected to digital pin 7 +int val = 0; // variable to store the read value + +void setup() +{ + pinMode(ledPin, OUTPUT); // sets the digital pin 13 as output + pinMode(inPin, INPUT); // sets the digital pin 7 as input +} + +void loop() +{ + val = digitalRead(inPin); // read the input pin + digitalWrite(ledPin, val); // sets the LED to the button's value +} +---- +[%hardbreaks] + +[float] +=== Notes and Warnings +If the pin isn't connected to anything, digitalRead() can return either HIGH or LOW (and this can change randomly). + +The analog input pins can be used as digital pins, referred to as A0, A1, etc. +[%hardbreaks] + +[float] +=== See also +// Link relevant content by category, such as other Reference terms (please add the tag #LANGUAGE#), +// definitions (please add the tag #DEFINITION#), and examples of Projects and Tutorials +// (please add the tag #EXAMPLE#) ►►►►► THIS SECTION IS MANDATORY ◄◄◄◄◄ +[role="language"] +* #LANGUAGE# link:pinMode{ext-relative}[pinMode()] + +* #LANGUAGE# link:digitalWrite{ext-relative}[digitalWrite()] + +[role="example"] +* #EXAMPLE# Tutorial: (http://arduino.cc/en/Tutorial/DigitalPins[Digital Pins]) + +-- +// HOW TO USE SECTION ENDS diff --git a/Language/Functions/Digital IO/digitalRead.html b/Language/Functions/Digital IO/digitalRead.html new file mode 100644 index 000000000..b58127b29 --- /dev/null +++ b/Language/Functions/Digital IO/digitalRead.html @@ -0,0 +1,867 @@ + + + + + +digitalRead() + + + + + +
+
+
+
+
+

Description

+

Reads the value from a specified digital pin, either HIGH or LOW.

+

Syntax

+

digitalRead(pin)

+

Parameters

+

Returns

+

HIGH or LOW

+
+
+
+

Example Code

+

Sets pin 13 to the same value as pin 7, declared as an input.

+
+
+
int ledPin = 13;   // LED connected to digital pin 13
+int inPin = 7;     // pushbutton connected to digital pin 7
+int val = 0;       // variable to store the read value
+
+void setup()
+{
+  pinMode(ledPin, OUTPUT);      // sets the digital pin 13 as output
+  pinMode(inPin, INPUT);        // sets the digital pin 7 as input
+}
+
+void loop()
+{
+  val = digitalRead(inPin);     // read the input pin
+  digitalWrite(ledPin, val);    // sets the LED to the button's value
+}
+
+

Notes and Warnings

+

If the pin isn’t connected to anything, digitalRead() can return either HIGH or LOW (and this can change randomly).

+

The analog input pins can be used as digital pins, referred to as A0, A1, etc.

+

See also

+
+
+
+
+
+

+ + + diff --git a/Language/Functions/Digital IO/digitalWrite.adoc b/Language/Functions/Digital IO/digitalWrite.adoc new file mode 100644 index 000000000..e3e0ad2ff --- /dev/null +++ b/Language/Functions/Digital IO/digitalWrite.adoc @@ -0,0 +1,91 @@ +:source-highlighter: pygments +:pygments-style: arduino +//:ext-relative: adoc +:ext-relative: .html + += digitalWrite() + + +// OVERVIEW SECTION STARTS +[#overview] +-- + +[float] +=== Description +Write a `HIGH` or a `LOW` value to a digital pin. + +If the pin has been configured as an OUTPUT with `pinMode()`, its voltage will be set to the corresponding value: 5V (or 3.3V on 3.3V boards) for `HIGH`, 0V (ground) for `LOW`. +[%hardbreaks] + +If the pin is configured as an INPUT, `digitalWrite()` will enable (HIGH) or disable (LOW) the internal pullup on the input pin. It is recommended to set the pinMode() to INPUT_PULLUP to enable the internal pull-up resistor. See the digital pins tutorial for more information. +[%hardbreaks] + +If you do not set the `pinMode()` to `OUTPUT`, and connect an LED to a pin, when calling `digitalWrite(HIGH)`, the LED may appear dim. Without explicitly setting `pinMode()`, `digitalWrite()` will have enabled the internal pull-up resistor, which acts like a large current-limiting resistor. +[%hardbreaks] + +[float] +=== Syntax +`digitalWrite(pin, value)` + + +[float] +=== Parameters +`pin`: the pin number + +`value`: `HIGH` or `LOW` + +[float] +=== Returns +Nothing + +-- +// OVERVIEW SECTION ENDS + + + + +// HOW TO USE SECTION STARTS +[#howtouse] +-- + +[float] +=== Example Code +// Describe what the example code is all about and add relevant code ►►►►► THIS SECTION IS MANDATORY ◄◄◄◄◄ +The code makes the digital pin 13 `OUTPUT` and Togles it `HIGH` and `LOW` + +//[source,arduino] +---- +void setup() +{ + pinMode(13, OUTPUT); // sets the digital pin 13 as output +} + +void loop() +{ + digitalWrite(13, HIGH); // sets the digital pin 13 on + delay(1000); // waits for a second + digitalWrite(13, LOW); // sets the digital pin 13 off + delay(1000); // waits for a second +} +---- +[%hardbreaks] + +[float] +=== Notes and Warnings +The analog input pins can be used as digital pins, referred to as A0, A1, etc. +[%hardbreaks] + +[float] +=== See also +// Link relevant content by category, such as other Reference terms (please add the tag #LANGUAGE#), +// definitions (please add the tag #DEFINITION#), and examples of Projects and Tutorials +// (please add the tag #EXAMPLE#) ►►►►► THIS SECTION IS MANDATORY ◄◄◄◄◄ +[role="language"] +* #LANGUAGE# link:pinMode{ext-relative}[pinMode()] + +* #LANGUAGE# link:digitalRead{ext-relative}[digitalRead()] + + +[role="example"] +* #EXAMPLE# http://arduino.cc/en/Tutorial/DigitalPins[Tutorial: Digital Pins] + +-- +// HOW TO USE SECTION ENDS diff --git a/Language/Functions/Digital IO/pinMode.adoc b/Language/Functions/Digital IO/pinMode.adoc new file mode 100644 index 000000000..781037362 --- /dev/null +++ b/Language/Functions/Digital IO/pinMode.adoc @@ -0,0 +1,89 @@ +:source-highlighter: pygments +:pygments-style: arduino +//:ext-relative: adoc +:ext-relative: .html + += pinMode() + + +// OVERVIEW SECTION STARTS +[#overview] +-- + +[float] +=== Description +Configures the specified pin to behave either as an input or an output. See the description of (http://arduino.cc/en/Tutorial/DigitalPins[digital pins]) for details on the functionality of the pins. +[%hardbreaks] +As of Arduino 1.0.1, it is possible to enable the internal pullup resistors with the mode INPUT_PULLUP. Additionally, the INPUT mode explicitly disables the internal pullups. +[%hardbreaks] + + +[float] +=== Syntax +`pinMode(pin, mode)` + +[float] +=== Parameters +`pin`: the number of the pin whose mode you wish to set + +`mode`: `INPUT`, `OUTPUT`, or `INPUT_PULLUP`. (see the (http://arduino.cc/en/Tutorial/DigitalPins[digital pins]) page for a more complete description of the functionality.) + +//Check how to add links + +[float] +=== Returns +Nothing + +-- +// OVERVIEW SECTION ENDS + + + + +// HOW TO USE SECTION STARTS +[#howtouse] +-- + +[float] +=== Example Code +The code makes the digital pin 13 `OUTPUT` and Togles it `HIGH` and `LOW` + +//[source,arduino] +---- +void setup() +{ + pinMode(13, OUTPUT); // sets the digital pin 13 as output +} + +void loop() +{ + digitalWrite(13, HIGH); // sets the digital pin 13 on + delay(1000); // waits for a second + digitalWrite(13, LOW); // sets the digital pin 13 off + delay(1000); // waits for a second +} +---- +[%hardbreaks] + +[float] +=== Notes and Warnings +The analog input pins can be used as digital pins, referred to as A0, A1, etc. +[%hardbreaks] + +[float] +=== See also +// Link relevant content by category, such as other Reference terms (please add the tag #LANGUAGE#), +// definitions (please add the tag #DEFINITION#), and examples of Projects and Tutorials +// (please add the tag #EXAMPLE#) ►►►►► THIS SECTION IS MANDATORY ◄◄◄◄◄ +[role="definition"] +* #DEFINITION# constants + // add link + +[role="language"] +* #LANGUAGE# link:digitalWrite{ext-relative}[digitalWrite()] + +* #LANGUAGE# link:digitalRead{ext-relative}[digitalRead()] + +[role="example"] +* #EXAMPLE# http://arduino.cc/en/Tutorial/DigitalPins[Description of the pins on an Arduino board^] + +-- +// HOW TO USE SECTION ENDS From f772195a05f747bb7c56fe75a5a7c69f7680726c Mon Sep 17 00:00:00 2001 From: Akshay Sharma Date: Tue, 17 Feb 2015 15:59:26 +0530 Subject: [PATCH 06/13] Add Content Functions/External Interrupts --- .../External Interrupts/attachInterrupt.adoc | 0 .../External Interrupts/detachInterrupt.adoc | 53 +++++++++++++++++++ 2 files changed, 53 insertions(+) create mode 100644 Language/Functions/External Interrupts/attachInterrupt.adoc create mode 100644 Language/Functions/External Interrupts/detachInterrupt.adoc diff --git a/Language/Functions/External Interrupts/attachInterrupt.adoc b/Language/Functions/External Interrupts/attachInterrupt.adoc new file mode 100644 index 000000000..e69de29bb diff --git a/Language/Functions/External Interrupts/detachInterrupt.adoc b/Language/Functions/External Interrupts/detachInterrupt.adoc new file mode 100644 index 000000000..a4cadc9de --- /dev/null +++ b/Language/Functions/External Interrupts/detachInterrupt.adoc @@ -0,0 +1,53 @@ +:source-highlighter: pygments +:pygments-style: arduino +:ext-relative: adoc + + += detachInterrupt() + + +// OVERVIEW SECTION STARTS +[#overview] +-- + +[float] +=== Description +Turns off the given interrupt. +[%hardbreaks] + + +[float] +=== Syntax +`detachInterrupt()` + +`detachInterrupt(pin)` (Arduino Due only) + +[float] +=== Parameters +`interrupt`: the number of the interrupt to disable (see link:attachInterrupt{ext-relative}[attachInterrupt()] for more details). + +`pin`: the pin number of the interrupt to disable (Arduino Due only) + +[float] +=== Returns +Nothing + +-- +// OVERVIEW SECTION ENDS + + + + +// HOW TO USE SECTION STARTS +[#howtouse] +-- + +[float] +=== See also +// Link relevant content by category, such as other Reference terms (please add the tag #LANGUAGE#), +// definitions (please add the tag #DEFINITION#), and examples of Projects and Tutorials +// (please add the tag #EXAMPLE#) ►►►►► THIS SECTION IS MANDATORY ◄◄◄◄◄ +[role="language"] +* #LANGUAGE# link:attachInterrupt{ext-relative}[attachInterrupt()] + +-- +// HOW TO USE SECTION ENDS From 7c90a6daba00fcc238bfcbb5483b344fcecfb10f Mon Sep 17 00:00:00 2001 From: Akshay Sharma Date: Tue, 17 Feb 2015 16:38:48 +0530 Subject: [PATCH 07/13] Add Content Functions (Most of the the Terms) --- .../Communication/Serial/available.adoc | 113 ++++++++++++++ .../Functions/Communication/Serial/begin.adoc | 138 +++++++++++++++++ .../Functions/Communication/Serial/end.adoc | 66 ++++++++ .../Functions/Communication/Serial/find.adoc | 53 +++++++ .../Communication/Serial/findUntil.adoc | 61 ++++++++ .../Functions/Communication/Serial/flush.adoc | 69 +++++++++ .../Communication/Serial/ifSerial.adoc | 96 ++++++++++++ .../Communication/Serial/parseFloat.adoc | 54 +++++++ .../Communication/Serial/parseInt.adoc | 70 +++++++++ .../Functions/Communication/Serial/peek.adoc | 68 +++++++++ .../Functions/Communication/Serial/print.adoc | 75 +++++++++ .../Communication/Serial/println.adoc | 97 ++++++++++++ .../Functions/Communication/Serial/read.adoc | 96 ++++++++++++ .../Communication/Serial/readBytes.adoc | 59 ++++++++ .../Communication/Serial/readBytesUntil.adoc | 59 ++++++++ .../Communication/Serial/serialEvent.adoc | 90 +++++++++++ .../Communication/Serial/setTimeout.adoc | 53 +++++++ .../Functions/Communication/Serial/write.adoc | 91 +++++++++++ .../Communication/Stream/streamAvailable.adoc | 53 +++++++ .../Communication/Stream/streamFind.adoc | 58 +++++++ .../Communication/Stream/streamFindUntil.adoc | 58 +++++++ .../Communication/Stream/streamFlush.adoc | 53 +++++++ .../Stream/streamParseFloat.adoc | 58 +++++++ .../Communication/Stream/streamParseInt.adoc | 58 +++++++ .../Communication/Stream/streamPeek.adoc | 58 +++++++ .../Communication/Stream/streamRead.adoc | 53 +++++++ .../Communication/Stream/streamReadBytes.adoc | 63 ++++++++ .../Stream/streamReadBytesUntil.adoc | 64 ++++++++ .../Stream/streamReadString.adoc | 56 +++++++ .../Stream/streamReadStringUntil.adoc | 56 +++++++ .../Stream/streamSetTimeout.adoc | 55 +++++++ Language/Functions/Interrupts/interrupts.adoc | 73 +++++++++ .../Functions/Interrupts/noInterrupts.adoc | 71 +++++++++ Language/Functions/Math/abs.adoc | 58 +++++++ Language/Functions/Math/constrain.adoc | 71 +++++++++ Language/Functions/Math/map.adoc | 67 ++++++++ Language/Functions/Math/max.adoc | 80 ++++++++++ Language/Functions/Math/min.adoc | 80 ++++++++++ Language/Functions/Math/pow.adoc | 61 ++++++++ Language/Functions/Math/sq.adoc | 53 +++++++ Language/Functions/Math/sqrt.adoc | 52 +++++++ Language/Functions/Random Numbers/random.adoc | 94 ++++++++++++ .../Functions/Random Numbers/randomSeed.adoc | 77 ++++++++++ Language/Functions/Time/delay.adoc | 89 +++++++++++ .../Functions/Time/delayMicroseconds.adoc | 86 +++++++++++ Language/Functions/Time/micros.adoc | 79 ++++++++++ Language/Functions/Time/millis.adoc | 83 ++++++++++ Language/Functions/Trigonometry/cos.adoc | 53 +++++++ Language/Functions/Trigonometry/sin.adoc | 53 +++++++ Language/Functions/Trigonometry/tan.adoc | 53 +++++++ .../Keyboard/keyboardBegin.adoc | 84 ++++++++++ .../Keyboard/keyboardEnd.adoc | 81 ++++++++++ .../Keyboard/keyboardPress.adoc | 98 ++++++++++++ .../Keyboard/keyboardPrint.adoc | 90 +++++++++++ .../Keyboard/keyboardPrintln.adoc | 90 +++++++++++ .../Keyboard/keyboardRelease.adoc | 98 ++++++++++++ .../Keyboard/keyboardReleaseAll.adoc | 97 ++++++++++++ .../Keyboard/keyboardWrite.adoc | 98 ++++++++++++ .../Mouse/mouseBegin.adoc | 78 ++++++++++ .../Mouse/mouseClick.adoc | 90 +++++++++++ .../Mouse/mouseEnd.adoc | 82 ++++++++++ .../Mouse/mouseIsPressed.adoc | 102 +++++++++++++ .../Mouse/mouseMove.adoc | 143 ++++++++++++++++++ .../Mouse/mousePress.adoc | 101 +++++++++++++ .../Mouse/mouseRelease.adoc | 96 ++++++++++++ 65 files changed, 4912 insertions(+) create mode 100644 Language/Functions/Communication/Serial/available.adoc create mode 100644 Language/Functions/Communication/Serial/begin.adoc create mode 100644 Language/Functions/Communication/Serial/end.adoc create mode 100644 Language/Functions/Communication/Serial/find.adoc create mode 100644 Language/Functions/Communication/Serial/findUntil.adoc create mode 100644 Language/Functions/Communication/Serial/flush.adoc create mode 100644 Language/Functions/Communication/Serial/ifSerial.adoc create mode 100644 Language/Functions/Communication/Serial/parseFloat.adoc create mode 100644 Language/Functions/Communication/Serial/parseInt.adoc create mode 100644 Language/Functions/Communication/Serial/peek.adoc create mode 100644 Language/Functions/Communication/Serial/print.adoc create mode 100644 Language/Functions/Communication/Serial/println.adoc create mode 100644 Language/Functions/Communication/Serial/read.adoc create mode 100644 Language/Functions/Communication/Serial/readBytes.adoc create mode 100644 Language/Functions/Communication/Serial/readBytesUntil.adoc create mode 100644 Language/Functions/Communication/Serial/serialEvent.adoc create mode 100644 Language/Functions/Communication/Serial/setTimeout.adoc create mode 100644 Language/Functions/Communication/Serial/write.adoc create mode 100644 Language/Functions/Communication/Stream/streamAvailable.adoc create mode 100644 Language/Functions/Communication/Stream/streamFind.adoc create mode 100644 Language/Functions/Communication/Stream/streamFindUntil.adoc create mode 100644 Language/Functions/Communication/Stream/streamFlush.adoc create mode 100644 Language/Functions/Communication/Stream/streamParseFloat.adoc create mode 100644 Language/Functions/Communication/Stream/streamParseInt.adoc create mode 100644 Language/Functions/Communication/Stream/streamPeek.adoc create mode 100644 Language/Functions/Communication/Stream/streamRead.adoc create mode 100644 Language/Functions/Communication/Stream/streamReadBytes.adoc create mode 100644 Language/Functions/Communication/Stream/streamReadBytesUntil.adoc create mode 100644 Language/Functions/Communication/Stream/streamReadString.adoc create mode 100644 Language/Functions/Communication/Stream/streamReadStringUntil.adoc create mode 100644 Language/Functions/Communication/Stream/streamSetTimeout.adoc create mode 100644 Language/Functions/Interrupts/interrupts.adoc create mode 100644 Language/Functions/Interrupts/noInterrupts.adoc create mode 100644 Language/Functions/Math/abs.adoc create mode 100644 Language/Functions/Math/constrain.adoc create mode 100644 Language/Functions/Math/map.adoc create mode 100644 Language/Functions/Math/max.adoc create mode 100644 Language/Functions/Math/min.adoc create mode 100644 Language/Functions/Math/pow.adoc create mode 100644 Language/Functions/Math/sq.adoc create mode 100644 Language/Functions/Math/sqrt.adoc create mode 100644 Language/Functions/Random Numbers/random.adoc create mode 100644 Language/Functions/Random Numbers/randomSeed.adoc create mode 100644 Language/Functions/Time/delay.adoc create mode 100644 Language/Functions/Time/delayMicroseconds.adoc create mode 100644 Language/Functions/Time/micros.adoc create mode 100644 Language/Functions/Time/millis.adoc create mode 100644 Language/Functions/Trigonometry/cos.adoc create mode 100644 Language/Functions/Trigonometry/sin.adoc create mode 100644 Language/Functions/Trigonometry/tan.adoc create mode 100644 Language/Functions/USB (Leonardo and DUE only)/Keyboard/keyboardBegin.adoc create mode 100644 Language/Functions/USB (Leonardo and DUE only)/Keyboard/keyboardEnd.adoc create mode 100644 Language/Functions/USB (Leonardo and DUE only)/Keyboard/keyboardPress.adoc create mode 100644 Language/Functions/USB (Leonardo and DUE only)/Keyboard/keyboardPrint.adoc create mode 100644 Language/Functions/USB (Leonardo and DUE only)/Keyboard/keyboardPrintln.adoc create mode 100644 Language/Functions/USB (Leonardo and DUE only)/Keyboard/keyboardRelease.adoc create mode 100644 Language/Functions/USB (Leonardo and DUE only)/Keyboard/keyboardReleaseAll.adoc create mode 100644 Language/Functions/USB (Leonardo and DUE only)/Keyboard/keyboardWrite.adoc create mode 100644 Language/Functions/USB (Leonardo and DUE only)/Mouse/mouseBegin.adoc create mode 100644 Language/Functions/USB (Leonardo and DUE only)/Mouse/mouseClick.adoc create mode 100644 Language/Functions/USB (Leonardo and DUE only)/Mouse/mouseEnd.adoc create mode 100644 Language/Functions/USB (Leonardo and DUE only)/Mouse/mouseIsPressed.adoc create mode 100644 Language/Functions/USB (Leonardo and DUE only)/Mouse/mouseMove.adoc create mode 100644 Language/Functions/USB (Leonardo and DUE only)/Mouse/mousePress.adoc create mode 100644 Language/Functions/USB (Leonardo and DUE only)/Mouse/mouseRelease.adoc diff --git a/Language/Functions/Communication/Serial/available.adoc b/Language/Functions/Communication/Serial/available.adoc new file mode 100644 index 000000000..c98b0643e --- /dev/null +++ b/Language/Functions/Communication/Serial/available.adoc @@ -0,0 +1,113 @@ +:source-highlighter: pygments +:pygments-style: arduino +:ext-relative: adoc + + += available() + + +// OVERVIEW SECTION STARTS +[#overview] +-- + +[float] +=== Description +Get the number of bytes (characters) available for reading from the serial port. This is data that's already arrived and stored in the serial receive buffer (which holds 64 bytes). `available()` inherits from the Stream utility class. +[%hardbreaks] + + +[float] +=== Syntax +`Serial.available()` + +_Arduino Mega only:_ + +`Serial1.available()` + +`Serial2.available()` + +`Serial3.available()` + + +[float] +=== Parameters +Nothing + +[float] +=== Returns +The number of bytes available to read . +-- +// OVERVIEW SECTION ENDS + + + + +// HOW TO USE SECTION STARTS +[#howtouse] +-- + +[source,arduino] +---- +int incomingByte = 0; // for incoming serial data + +void setup() { + Serial.begin(9600); // opens serial port, sets data rate to 9600 bps +} + +void loop() { + + // send data only when you receive data: + if (Serial.available() > 0) { + // read the incoming byte: + incomingByte = Serial.read(); + + // say what you got: + Serial.print("I received: "); + Serial.println(incomingByte, DEC); + } +} +---- +[%hardbreaks] + +*Arduino Mega example:* +[source,arduino] +---- +void setup() { + Serial.begin(9600); + Serial1.begin(9600); + +} + +void loop() { + // read from port 0, send to port 1: + if (Serial.available()) { + int inByte = Serial.read(); + Serial1.print(inByte, BYTE); + + } + // read from port 1, send to port 0: + if (Serial1.available()) { + int inByte = Serial1.read(); + Serial.print(inByte, BYTE); + } +} +---- + +[float] +=== See also +// Link relevant content by category, such as other Reference terms (please add the tag #LANGUAGE#), +// definitions (please add the tag #DEFINITION#), and examples of Projects and Tutorials +// (please add the tag #EXAMPLE#) ►►►►► THIS SECTION IS MANDATORY ◄◄◄◄◄ +[role="language"] +* #LANGUAGE# link:begin{ext-relative}[begin()] + +* #LANGUAGE# link:end{ext-relative}[end()] + +* #LANGUAGE# link:available{ext-relative}[available()] + +* #LANGUAGE# link:read{ext-relative}[read()] + +* #LANGUAGE# link:peek{ext-relative}[peek()] + +* #LANGUAGE# link:flush{ext-relative}[flush()] + +* #LANGUAGE# link:print{ext-relative}[print()] + +* #LANGUAGE# link:println{ext-relative}[println()] + +* #LANGUAGE# link:write{ext-relative}[write()] + +* #LANGUAGE# link:serialEvent{ext-relative}[SerialEvent()] + +* #LANGUAGE# link:serialAvailable{ext-relative}[(Serial.available)] + +-- +// HOW TO USE SECTION ENDS diff --git a/Language/Functions/Communication/Serial/begin.adoc b/Language/Functions/Communication/Serial/begin.adoc new file mode 100644 index 000000000..468883488 --- /dev/null +++ b/Language/Functions/Communication/Serial/begin.adoc @@ -0,0 +1,138 @@ +:source-highlighter: pygments +:pygments-style: arduino +:ext-relative: adoc + + += begin() + + +// OVERVIEW SECTION STARTS +[#overview] +-- + +[float] +=== Description +Sets the data rate in bits per second (baud) for serial data transmission. For communicating with the computer, use one of these rates: 300, 600, 1200, 2400, 4800, 9600, 14400, 19200, 28800, 38400, 57600, or 115200. You can, however, specify other rates - for example, to communicate over pins 0 and 1 with a component that requires a particular baud rate. + +An optional second argument configures the data, parity, and stop bits. The default is 8 data bits, no parity, one stop bit. +[%hardbreaks] + + +[float] +=== Syntax +`Serial.begin(speed)` +`Serial.begin(speed, config)` + +_Arduino Mega only:_ + +`Serial1.begin(speed)` + +`Serial2.begin(speed)` + +`Serial3.begin(speed)` + +`Serial1.begin(speed, config)` + +`Serial2.begin(speed, config)` + +`Serial3.begin(speed, config)` + + + +[float] +=== Parameters +`speed`: in bits per second (baud) - `long` + +`config`: sets data, parity, and stop bits. Valid values are + +`SERIAL_5N1` + +`SERIAL_6N1` + +`SERIAL_7N1` + +`SERIAL_8N1` (the default) + +`SERIAL_5N2` + +`SERIAL_6N2` + +`SERIAL_7N2` + +`SERIAL_8N2` + +`SERIAL_5E1` + +`SERIAL_6E1` + +`SERIAL_7E1` + +`SERIAL_8E1` + +`SERIAL_5E2` + +`SERIAL_6E2` + +`SERIAL_7E2` + +`SERIAL_8E2` + +`SERIAL_5O1` + +`SERIAL_6O1` + +`SERIAL_7O1` + +`SERIAL_8O1` + +`SERIAL_5O2` + +`SERIAL_6O2` + +`SERIAL_7O2` + +`SERIAL_8O2` + + +[float] +=== Returns +Nothing + +-- +// OVERVIEW SECTION ENDS + + + + +// HOW TO USE SECTION STARTS +[#howtouse] +-- + +[float] +=== Example Code +// Describe what the example code is all about and add relevant code ►►►►► THIS SECTION IS MANDATORY ◄◄◄◄◄ + + +[source,arduino] +---- +void setup() { + Serial.begin(9600); // opens serial port, sets data rate to 9600 bps +} + +void loop() {} +---- +[%hardbreaks] + +*Arduino Mega example:* +[source,arduino] +---- +// Arduino Mega using all four of its Serial ports +// (Serial, Serial1, Serial2, Serial3), +// with different baud rates: + +void setup(){ + Serial.begin(9600); + Serial1.begin(38400); + Serial2.begin(19200); + Serial3.begin(4800); + + Serial.println("Hello Computer"); + Serial1.println("Hello Serial 1"); + Serial2.println("Hello Serial 2"); + Serial3.println("Hello Serial 3"); +} +void loop() {} +---- +[%hardbreaks] +Thanks to Jeff Gray for the mega example + +[float] +=== See also +// Link relevant content by category, such as other Reference terms (please add the tag #LANGUAGE#), +// definitions (please add the tag #DEFINITION#), and examples of Projects and Tutorials +// (please add the tag #EXAMPLE#) ►►►►► THIS SECTION IS MANDATORY ◄◄◄◄◄ +[role="language"] +* #LANGUAGE# link:begin{ext-relative}[begin()] + +* #LANGUAGE# link:end{ext-relative}[end()] + +* #LANGUAGE# link:available{ext-relative}[available()] + +* #LANGUAGE# link:read{ext-relative}[read()] + +* #LANGUAGE# link:peek{ext-relative}[peek()] + +* #LANGUAGE# link:flush{ext-relative}[flush()] + +* #LANGUAGE# link:print{ext-relative}[print()] + +* #LANGUAGE# link:println{ext-relative}[println()] + +* #LANGUAGE# link:write{ext-relative}[write()] + +* #LANGUAGE# link:serialEvent{ext-relative}[SerialEvent()] + +-- +// HOW TO USE SECTION ENDS diff --git a/Language/Functions/Communication/Serial/end.adoc b/Language/Functions/Communication/Serial/end.adoc new file mode 100644 index 000000000..a63830e56 --- /dev/null +++ b/Language/Functions/Communication/Serial/end.adoc @@ -0,0 +1,66 @@ +:source-highlighter: pygments +:pygments-style: arduino +:ext-relative: adoc + + += end() + + +// OVERVIEW SECTION STARTS +[#overview] +-- + +[float] +=== Description +Disables serial communication, allowing the RX and TX pins to be used for general input and output. To re-enable serial communication, call link:begin{ext-relative}[Serial.begin()]. +[%hardbreaks] + + +[float] +=== Syntax +`Serial.end()` + +_Arduino Mega only:_ + +`Serial1.end()` + +`Serial2.end()` + +`Serial3.end()` + + + +[float] +=== Parameters +Nothing + +[float] +=== Returns +Nothing + +-- +// OVERVIEW SECTION ENDS + + + + +// HOW TO USE SECTION STARTS +[#howtouse] +-- + +[float] +=== See also +// Link relevant content by category, such as other Reference terms (please add the tag #LANGUAGE#), +// definitions (please add the tag #DEFINITION#), and examples of Projects and Tutorials +// (please add the tag #EXAMPLE#) ►►►►► THIS SECTION IS MANDATORY ◄◄◄◄◄ +[role="language"] +* #LANGUAGE# link:begin{ext-relative}[begin()] + +* #LANGUAGE# link:end{ext-relative}[end()] + +* #LANGUAGE# link:available{ext-relative}[available()] + +* #LANGUAGE# link:read{ext-relative}[read()] + +* #LANGUAGE# link:peek{ext-relative}[peek()] + +* #LANGUAGE# link:flush{ext-relative}[flush()] + +* #LANGUAGE# link:print{ext-relative}[print()] + +* #LANGUAGE# link:println{ext-relative}[println()] + +* #LANGUAGE# link:write{ext-relative}[write()] + +* #LANGUAGE# link:serialEvent{ext-relative}[SerialEvent()] + +-- +// HOW TO USE SECTION ENDS diff --git a/Language/Functions/Communication/Serial/find.adoc b/Language/Functions/Communication/Serial/find.adoc new file mode 100644 index 000000000..c5723a68e --- /dev/null +++ b/Language/Functions/Communication/Serial/find.adoc @@ -0,0 +1,53 @@ +:source-highlighter: pygments +:pygments-style: arduino +:ext-relative: adoc + + += Serial.find() + + +// OVERVIEW SECTION STARTS +[#overview] +-- + +[float] +=== Description +Serial.find() reads data from the serial buffer until the target string of given length is found. The function returns true if target string is found, false if it times out. + +Serial.find() inherits from the link:stream{ext-relative}[Stream] utility class. +[%hardbreaks] + + +[float] +=== Syntax +`Serial.find(target)` + +[float] +=== Parameters +`target` : the string to search for (char) + +[float] +=== Returns +`boolean` + +-- +// OVERVIEW SECTION ENDS + + + + +// HOW TO USE SECTION STARTS +[#howtouse] +-- + +[float] +=== See also +// Link relevant content by category, such as other Reference terms (please add the tag #LANGUAGE#), +// definitions (please add the tag #DEFINITION#), and examples of Projects and Tutorials +// (please add the tag #EXAMPLE#) ►►►►► THIS SECTION IS MANDATORY ◄◄◄◄◄ +[role="language"] +* #LANGUAGE# link:stream{ext-relative}[stream] + +* #LANGUAGE# link:streamFind{ext-relative}[stream.find()] + +-- +// HOW TO USE SECTION ENDS diff --git a/Language/Functions/Communication/Serial/findUntil.adoc b/Language/Functions/Communication/Serial/findUntil.adoc new file mode 100644 index 000000000..d9a8890a0 --- /dev/null +++ b/Language/Functions/Communication/Serial/findUntil.adoc @@ -0,0 +1,61 @@ +:source-highlighter: pygments +:pygments-style: arduino +:ext-relative: adoc + + += Serial.findUntil() + + +// OVERVIEW SECTION STARTS +[#overview] +-- + +[float] +=== Description +Serial.findUntil() reads data from the serial buffer until a target string of given length or terminator string is found. + +The function returns true if the target string is found, false if it times out. + +Serial.findUntil() inherits from the link:stream{ext-relative}[Stream] utility class. +[%hardbreaks] + + +[float] +=== Syntax +`Serial.findUntil(target, terminal)` + + +[float] +=== Parameters +`target` : the string to search for (char) +`terminal` : the terminal string in the search (char) + +[float] +=== Returns +`boolean` + +-- +// OVERVIEW SECTION ENDS + + + + +// HOW TO USE SECTION STARTS +[#howtouse] +-- + +[float] +=== Notes and Warnings +[%hardbreaks] + +[float] +=== See also +// Link relevant content by category, such as other Reference terms (please add the tag #LANGUAGE#), +// definitions (please add the tag #DEFINITION#), and examples of Projects and Tutorials +// (please add the tag #EXAMPLE#) ►►►►► THIS SECTION IS MANDATORY ◄◄◄◄◄ +[role="language"] +* #LANGUAGE# link:stream{ext-relative}[stream] + +* #LANGUAGE# link:streamFindUntil{ext-relative}[stream.findUntil()] + +-- +// HOW TO USE SECTION ENDS diff --git a/Language/Functions/Communication/Serial/flush.adoc b/Language/Functions/Communication/Serial/flush.adoc new file mode 100644 index 000000000..9e4c0a1fd --- /dev/null +++ b/Language/Functions/Communication/Serial/flush.adoc @@ -0,0 +1,69 @@ +:source-highlighter: pygments +:pygments-style: arduino +:ext-relative: adoc + + += flush() + + +// OVERVIEW SECTION STARTS +[#overview] +-- + +[float] +=== Description +Waits for the transmission of outgoing serial data to complete. (Prior to Arduino 1.0, this instead removed any buffered incoming serial data.) + +`flush()` inherits from the link:flush{ext-relative}[Stream] utility class. +[%hardbreaks] + + +[float] +=== Syntax +`Serial.flush()` + +_Arduino Mega only:_ + +`Serial1.flush()` + +`Serial2.flush()` + +`Serial3.flush()` + + +[float] +=== Parameters +Nothing + +[float] +=== Returns +Nothing + +-- +// OVERVIEW SECTION ENDS + + + + +// HOW TO USE SECTION STARTS +[#howtouse] +-- + +[float] +=== See also +// Link relevant content by category, such as other Reference terms (please add the tag #LANGUAGE#), +// definitions (please add the tag #DEFINITION#), and examples of Projects and Tutorials +// (please add the tag #EXAMPLE#) ►►►►► THIS SECTION IS MANDATORY ◄◄◄◄◄ +[role="language"] +* #LANGUAGE# link:begin{ext-relative}[begin()] + +* #LANGUAGE# link:end{ext-relative}[end()] + +* #LANGUAGE# link:available{ext-relative}[available()] + +* #LANGUAGE# link:read{ext-relative}[read()] + +* #LANGUAGE# link:peek{ext-relative}[peek()] + +* #LANGUAGE# link:flush{ext-relative}[flush()] + +* #LANGUAGE# link:print{ext-relative}[print()] + +* #LANGUAGE# link:println{ext-relative}[println()] + +* #LANGUAGE# link:write{ext-relative}[write()] + +* #LANGUAGE# link:serialEvent{ext-relative}[SerialEvent()] + +* #LANGUAGE# link:streamFlush{ext-relative}[Stream.flush()] + +-- +// HOW TO USE SECTION ENDSp diff --git a/Language/Functions/Communication/Serial/ifSerial.adoc b/Language/Functions/Communication/Serial/ifSerial.adoc new file mode 100644 index 000000000..eb7eca3a4 --- /dev/null +++ b/Language/Functions/Communication/Serial/ifSerial.adoc @@ -0,0 +1,96 @@ +:source-highlighter: pygments +:pygments-style: arduino +:ext-relative: adoc + + += if (Serial) + + +// OVERVIEW SECTION STARTS +[#overview] +-- + +[float] +=== Description +Indicates if the specified Serial port is ready. + +On the Leonardo, `if (Serial)` indicates wether or not the USB CDC serial connection is open. For all other instances, including `if (Serial1)` on the Leonardo, this will always returns true. + +This was introduced in Arduino 1.0.1. +[%hardbreaks] + + +[float] +=== Syntax +_All boards:_ + +`if (Serial)` + +_Arduino Leonardo specific:_ + +`if (Serial1)` + +_Arduino Mega specific:_ + +`if (Serial1)` + +`if (Serial2)` + +`if (Serial3)` + +[float] +=== Parameters +Nothing + +[float] +=== Returns +`boolean` : returns true if the specified serial port is available. This will only return false if querying the Leonardo's USB CDC serial connection before it is ready. + +-- +// OVERVIEW SECTION ENDS + + + + +// HOW TO USE SECTION STARTS +[#howtouse] +-- + +[float] +=== Example Code +// Describe what the example code is all about and add relevant code ►►►►► THIS SECTION IS MANDATORY ◄◄◄◄◄ + + +[source,arduino] +---- +void setup() { + //Initialize serial and wait for port to open: + Serial.begin(9600); + while (!Serial) { + ; // wait for serial port to connect. Needed for Leonardo only + } +} + +void loop() { + //proceed normally +} +---- +[%hardbreaks] + +[float] +=== See also +// Link relevant content by category, such as other Reference terms (please add the tag #LANGUAGE#), +// definitions (please add the tag #DEFINITION#), and examples of Projects and Tutorials +// (please add the tag #EXAMPLE#) ►►►►► THIS SECTION IS MANDATORY ◄◄◄◄◄ +[role="language"] +* #LANGUAGE# link:begin{ext-relative}[begin()] + +* #LANGUAGE# link:end{ext-relative}[end()] + +* #LANGUAGE# link:available{ext-relative}[available()] + +* #LANGUAGE# link:read{ext-relative}[read()] + +* #LANGUAGE# link:peek{ext-relative}[peek()] + +* #LANGUAGE# link:flush{ext-relative}[flush()] + +* #LANGUAGE# link:print{ext-relative}[print()] + +* #LANGUAGE# link:println{ext-relative}[println()] + +* #LANGUAGE# link:write{ext-relative}[write()] + +* #LANGUAGE# link:serialEvent{ext-relative}[SerialEvent()] + +-- +// HOW TO USE SECTION ENDS diff --git a/Language/Functions/Communication/Serial/parseFloat.adoc b/Language/Functions/Communication/Serial/parseFloat.adoc new file mode 100644 index 000000000..c27e36692 --- /dev/null +++ b/Language/Functions/Communication/Serial/parseFloat.adoc @@ -0,0 +1,54 @@ +:source-highlighter: pygments +:pygments-style: arduino +:ext-relative: adoc + + += Serial.parseFloat() + + +// OVERVIEW SECTION STARTS +[#overview] +-- + +[float] +=== Description +`Serial.parseFloat()` returns the first valid floating point number from the Serial buffer. Characters that are not digits (or the minus sign) are skipped. `parseFloat()` is terminated by the first character that is not a floating point number. + +`Serial.parseFloat()` inherits from the link:stream{ext-relative}[Stream] utility class. +[%hardbreaks] + + +[float] +=== Syntax +`Serial.parseFloat()` + + +[float] +=== Parameters +Nothing + +[float] +=== Returns +`float` + +-- +// OVERVIEW SECTION ENDS + + + + +// HOW TO USE SECTION STARTS +[#howtouse] +-- + +[float] +=== See also +// Link relevant content by category, such as other Reference terms (please add the tag #LANGUAGE#), +// definitions (please add the tag #DEFINITION#), and examples of Projects and Tutorials +// (please add the tag #EXAMPLE#) ►►►►► THIS SECTION IS MANDATORY ◄◄◄◄◄ +[role="language"] +* #LANGUAGE# link:stream{ext-relative}[stream()] + +* #LANGUAGE# link:streamParsefloat{ext-relative}[Stream.parseFloat()] + +-- +// HOW TO USE SECTION ENDS diff --git a/Language/Functions/Communication/Serial/parseInt.adoc b/Language/Functions/Communication/Serial/parseInt.adoc new file mode 100644 index 000000000..503706c92 --- /dev/null +++ b/Language/Functions/Communication/Serial/parseInt.adoc @@ -0,0 +1,70 @@ +:source-highlighter: pygments +:pygments-style: arduino +:ext-relative: adoc + + += parseInt() + + +// OVERVIEW SECTION STARTS +[#overview] +-- + +[float] +=== Description +Looks for the next valid integer in the incoming serial stream. `parseInt()` inherits from the link:stream{ext-relative}[Stream] utility class. + +If no valid integer is found within one second (adjustable through link:serialTimeout{ext-relative}[Serial.setTimeout()] ) a default value of 0 will be returned. +[%hardbreaks] + + +[float] +=== Syntax +`Serial.parseInt()` + + +_Arduino Mega only:_ + +`Serial1.parseInt()` + +`Serial2.parseInt()` + +`Serial3.parseInt()` + + +[float] +=== Parameters +Nothing + +[float] +=== Returns +`int` : the next valid integer + +-- +// OVERVIEW SECTION ENDS + + + + +// HOW TO USE SECTION STARTS +[#howtouse] +-- + +[float] +=== See also +// Link relevant content by category, such as other Reference terms (please add the tag #LANGUAGE#), +// definitions (please add the tag #DEFINITION#), and examples of Projects and Tutorials +// (please add the tag #EXAMPLE#) ►►►►► THIS SECTION IS MANDATORY ◄◄◄◄◄ +[role="language"] +* #LANGUAGE# link:begin{ext-relative}[begin()] + +* #LANGUAGE# link:end{ext-relative}[end()] + +* #LANGUAGE# link:available{ext-relative}[available()] + +* #LANGUAGE# link:read{ext-relative}[read()] + +* #LANGUAGE# link:peek{ext-relative}[peek()] + +* #LANGUAGE# link:flush{ext-relative}[flush()] + +* #LANGUAGE# link:print{ext-relative}[print()] + +* #LANGUAGE# link:println{ext-relative}[println()] + +* #LANGUAGE# link:write{ext-relative}[write()] + +* #LANGUAGE# link:serialEvent{ext-relative}[SerialEvent()] + +* #LANGUAGE# link:streamParsefloat{ext-relative}[Stream.parseFloat()] + +-- +// HOW TO USE SECTION ENDS diff --git a/Language/Functions/Communication/Serial/peek.adoc b/Language/Functions/Communication/Serial/peek.adoc new file mode 100644 index 000000000..9301d4839 --- /dev/null +++ b/Language/Functions/Communication/Serial/peek.adoc @@ -0,0 +1,68 @@ +:source-highlighter: pygments +:pygments-style: arduino +:ext-relative: adoc + + += peek() + + +// OVERVIEW SECTION STARTS +[#overview] +-- + +[float] +=== Description +Returns the next byte (character) of incoming serial data without removing it from the internal serial buffer. That is, successive calls to `peek()` will return the same character, as will the next call to `read()`. `peek()` inherits from the link:stream{ext-relative}[Stream] utility class. +[%hardbreaks] + + +[float] +=== Syntax +`Serial.peek()` + +_Arduino Mega only:_ + +`Serial1.peek()` + +`Serial2.peek()` + +`Serial3.peek()` + + +[float] +=== Parameters +Nothing + +[float] +=== Returns +The first byte of incoming serial data available (or -1 if no data is available) - `int` + +-- +// OVERVIEW SECTION ENDS + + + + +// HOW TO USE SECTION STARTS +[#howtouse] +-- + +[float] +=== See also +// Link relevant content by category, such as other Reference terms (please add the tag #LANGUAGE#), +// definitions (please add the tag #DEFINITION#), and examples of Projects and Tutorials +// (please add the tag #EXAMPLE#) ►►►►► THIS SECTION IS MANDATORY ◄◄◄◄◄ +[role="language"] +* #LANGUAGE# link:begin{ext-relative}[begin()] + +* #LANGUAGE# link:end{ext-relative}[end()] + +* #LANGUAGE# link:available{ext-relative}[available()] + +* #LANGUAGE# link:read{ext-relative}[read()] + +* #LANGUAGE# link:peek{ext-relative}[peek()] + +* #LANGUAGE# link:flush{ext-relative}[flush()] + +* #LANGUAGE# link:print{ext-relative}[print()] + +* #LANGUAGE# link:println{ext-relative}[println()] + +* #LANGUAGE# link:write{ext-relative}[write()] + +* #LANGUAGE# link:serialEvent{ext-relative}[SerialEvent()] + +* #LANGUAGE# link:streamPeek{ext-relative}[Stream.peek()] + + +-- +// HOW TO USE SECTION ENDS diff --git a/Language/Functions/Communication/Serial/print.adoc b/Language/Functions/Communication/Serial/print.adoc new file mode 100644 index 000000000..47824f2eb --- /dev/null +++ b/Language/Functions/Communication/Serial/print.adoc @@ -0,0 +1,75 @@ +:source-highlighter: pygments +:pygments-style: arduino +:ext-relative: adoc + + += print() + + +// OVERVIEW SECTION STARTS +[#overview] +-- + +[float] +=== Description +[%hardbreaks] + + +[float] +=== Syntax + + + +[float] +=== Parameters + + +[float] +=== Returns +Nothing + +-- +// OVERVIEW SECTION ENDS + + + + +// HOW TO USE SECTION STARTS +[#howtouse] +-- + +[float] +=== Example Code +// Describe what the example code is all about and add relevant code ►►►►► THIS SECTION IS MANDATORY ◄◄◄◄◄ + + +[source,arduino] +---- + +---- +[%hardbreaks] + +[float] +=== Notes and Warnings +[%hardbreaks] + +[float] +=== See also +// Link relevant content by category, such as other Reference terms (please add the tag #LANGUAGE#), +// definitions (please add the tag #DEFINITION#), and examples of Projects and Tutorials +// (please add the tag #EXAMPLE#) ►►►►► THIS SECTION IS MANDATORY ◄◄◄◄◄ +[role="language"] +* #LANGUAGE# link:begin{ext-relative}[begin()] + +* #LANGUAGE# link:end{ext-relative}[end()] + +* #LANGUAGE# link:available{ext-relative}[available()] + +* #LANGUAGE# link:read{ext-relative}[read()] + +* #LANGUAGE# link:peek{ext-relative}[peek()] + +* #LANGUAGE# link:flush{ext-relative}[flush()] + +* #LANGUAGE# link:print{ext-relative}[print()] + +* #LANGUAGE# link:println{ext-relative}[println()] + +* #LANGUAGE# link:write{ext-relative}[write()] + +* #LANGUAGE# link:serialEvent{ext-relative}[SerialEvent()] + +* #LANGUAGE# link:Memory{ext-relative}[Memory] + +-- +// HOW TO USE SECTION ENDS diff --git a/Language/Functions/Communication/Serial/println.adoc b/Language/Functions/Communication/Serial/println.adoc new file mode 100644 index 000000000..ddf65396b --- /dev/null +++ b/Language/Functions/Communication/Serial/println.adoc @@ -0,0 +1,97 @@ +:source-highlighter: pygments +:pygments-style: arduino +:ext-relative: adoc + + += println() + + +// OVERVIEW SECTION STARTS +[#overview] +-- + +[float] +=== Description +Prints data to the serial port as human-readable ASCII text followed by a carriage return character (ASCII 13, or '\r') and a newline character (ASCII 10, or '\n'). This command takes the same forms as link:print{ext-relative}[Serial.print(). +[%hardbreaks] + + +[float] +=== Syntax +`Serial.println(val)` + +`Serial.println(val, format)` + + +[float] +=== Parameters +`val`: the value to print - any data type + +`format`: specifies the number base (for integral data types) or number of decimal places (for floating point types) + +[float] +=== Returns +`size_t` (`long`): `println()` returns the number of bytes written, though reading that number is optional +-- +// OVERVIEW SECTION ENDS + + + + +// HOW TO USE SECTION STARTS +[#howtouse] +-- + +[float] +=== Example Code +// Describe what the example code is all about and add relevant code ►►►►► THIS SECTION IS MANDATORY ◄◄◄◄◄ + + +[source,arduino] +---- +/* + Analog input reads an analog input on analog in 0, prints the value out. + created 24 March 2006 + by Tom Igoe + */ + +int analogValue = 0; // variable to hold the analog value + +void setup() { + // open the serial port at 9600 bps: + Serial.begin(9600); +} + +void loop() { + // read the analog input on pin 0: + analogValue = analogRead(0); + + // print it out in many formats: + Serial.println(analogValue); // print as an ASCII-encoded decimal + Serial.println(analogValue, DEC); // print as an ASCII-encoded decimal + Serial.println(analogValue, HEX); // print as an ASCII-encoded hexadecimal + Serial.println(analogValue, OCT); // print as an ASCII-encoded octal + Serial.println(analogValue, BIN); // print as an ASCII-encoded binary + + // delay 10 milliseconds before the next reading: + delay(10); +---- +[%hardbreaks] + +[float] +=== See also +// Link relevant content by category, such as other Reference terms (please add the tag #LANGUAGE#), +// definitions (please add the tag #DEFINITION#), and examples of Projects and Tutorials +// (please add the tag #EXAMPLE#) ►►►►► THIS SECTION IS MANDATORY ◄◄◄◄◄ +[role="language"] +* #LANGUAGE# link:begin{ext-relative}[begin()] + +* #LANGUAGE# link:end{ext-relative}[end()] + +* #LANGUAGE# link:available{ext-relative}[available()] + +* #LANGUAGE# link:read{ext-relative}[read()] + +* #LANGUAGE# link:peek{ext-relative}[peek()] + +* #LANGUAGE# link:flush{ext-relative}[flush()] + +* #LANGUAGE# link:print{ext-relative}[print()] + +* #LANGUAGE# link:println{ext-relative}[println()] + +* #LANGUAGE# link:write{ext-relative}[write()] + +* #LANGUAGE# link:serialEvent{ext-relative}[SerialEvent()] +-- +// HOW TO USE SECTION ENDS diff --git a/Language/Functions/Communication/Serial/read.adoc b/Language/Functions/Communication/Serial/read.adoc new file mode 100644 index 000000000..fddf97eed --- /dev/null +++ b/Language/Functions/Communication/Serial/read.adoc @@ -0,0 +1,96 @@ +:source-highlighter: pygments +:pygments-style: arduino +:ext-relative: adoc + + += read() + + +// OVERVIEW SECTION STARTS +[#overview] +-- + +[float] +=== Description +Reads incoming serial data. read() inherits from the link:stream{ext-relative}[Stream] utility class. +[%hardbreaks] + + +[float] +=== Syntax +`Serial.read()` + +_Arduino Mega only:_ + +`Serial1.read()` + +`Serial2.read()` + +`Serial3.read()` + + +[float] +=== Parameters +Nothing + +[float] +=== Returns +The first byte of incoming serial data available (or -1 if no data is available) - `int`. + +-- +// OVERVIEW SECTION ENDS + + + + +// HOW TO USE SECTION STARTS +[#howtouse] +-- + +[float] +=== Example Code +// Describe what the example code is all about and add relevant code ►►►►► THIS SECTION IS MANDATORY ◄◄◄◄◄ + + +[source,arduino] +---- +int incomingByte = 0; // for incoming serial data + +void setup() { + Serial.begin(9600); // opens serial port, sets data rate to 9600 bps +} + +void loop() { + + // send data only when you receive data: + if (Serial.available() > 0) { + // read the incoming byte: + incomingByte = Serial.read(); + + // say what you got: + Serial.print("I received: "); + Serial.println(incomingByte, DEC); + } +} +---- +[%hardbreaks] + + +[float] +=== See also +// Link relevant content by category, such as other Reference terms (please add the tag #LANGUAGE#), +// definitions (please add the tag #DEFINITION#), and examples of Projects and Tutorials +// (please add the tag #EXAMPLE#) ►►►►► THIS SECTION IS MANDATORY ◄◄◄◄◄ +[role="language"] +* #LANGUAGE# link:begin{ext-relative}[begin()] + +* #LANGUAGE# link:end{ext-relative}[end()] + +* #LANGUAGE# link:available{ext-relative}[available()] + +* #LANGUAGE# link:read{ext-relative}[read()] + +* #LANGUAGE# link:peek{ext-relative}[peek()] + +* #LANGUAGE# link:flush{ext-relative}[flush()] + +* #LANGUAGE# link:print{ext-relative}[print()] + +* #LANGUAGE# link:println{ext-relative}[println()] + +* #LANGUAGE# link:write{ext-relative}[write()] + +* #LANGUAGE# link:serialEvent{ext-relative}[SerialEvent()] + +* #LANGUAGE# link:serialRead{ext-relative}[Serial.read()] + +-- +// HOW TO USE SECTION ENDS diff --git a/Language/Functions/Communication/Serial/readBytes.adoc b/Language/Functions/Communication/Serial/readBytes.adoc new file mode 100644 index 000000000..1282b5f60 --- /dev/null +++ b/Language/Functions/Communication/Serial/readBytes.adoc @@ -0,0 +1,59 @@ +:source-highlighter: pygments +:pygments-style: arduino +:ext-relative: adoc + + += Serial.readBytes() + + +// OVERVIEW SECTION STARTS +[#overview] +-- + +[float] +=== Description +`Serial.readBytes()` reads characters from the serial port into a buffer. The function terminates if the determined length has been read, or it times out (see link:serialTimeout{ext-relative}[Serial.setTimeout()]). + +`Serial.readBytes()` returns the number of characters placed in the buffer. A 0 means no valid data was found. + +`Serial.readBytes()` inherits from the link:stream{ext-relative}[Stream] utility class. +[%hardbreaks] + + +[float] +=== Syntax +`Serial.readBytes(buffer, length)` + + +[float] +=== Parameters +`buffer`: the buffer to store the bytes in (`char[]` or `byte[]`) + +`length` : the number of bytes to read (`int`) + +[float] +=== Returns +`byte` + +-- +// OVERVIEW SECTION ENDS + + + + +// HOW TO USE SECTION STARTS +[#howtouse] +-- + + +[float] +=== See also +// Link relevant content by category, such as other Reference terms (please add the tag #LANGUAGE#), +// definitions (please add the tag #DEFINITION#), and examples of Projects and Tutorials +// (please add the tag #EXAMPLE#) ►►►►► THIS SECTION IS MANDATORY ◄◄◄◄◄ +[role="language"] +* #LANGUAGE# link:stream{ext-relative}[stream] + +* #LANGUAGE# link:streamReadByte{ext-relative}[stream.readByte()] + +-- +// HOW TO USE SECTION ENDS diff --git a/Language/Functions/Communication/Serial/readBytesUntil.adoc b/Language/Functions/Communication/Serial/readBytesUntil.adoc new file mode 100644 index 000000000..ff062d49c --- /dev/null +++ b/Language/Functions/Communication/Serial/readBytesUntil.adoc @@ -0,0 +1,59 @@ +:source-highlighter: pygments +:pygments-style: arduino +:ext-relative: adoc + + += Serial.readBytesUntil() + + +// OVERVIEW SECTION STARTS +[#overview] +-- + +[float] +=== Description +Serial.readBytesUntil() reads characters from the serial buffer into an array. The function terminates if the terminator character is detected, the determined length has been read, or it times out (see link:serialTimeout{ext-relative}[Serial.setTimeout()]). + +`Serial.readBytesUntil()` returns the number of characters read into the buffer. A 0 means no valid data was found. + +`Serial.readBytesUntil()` inherits from the link:stream{ext-relative}[Stream] utility class. +[%hardbreaks] + + +[float] +=== Syntax +`Serial.readBytesUntil(character, buffer, length)` + + +[float] +=== Parameters +`character` : the character to search for (`char`) + +`buffer`: the buffer to store the bytes in (`char[]` or `byte[]`) + +`length` : the number of bytes to read (`int`) + +[float] +=== Returns +`byte` + +-- +// OVERVIEW SECTION ENDS + + + + +// HOW TO USE SECTION STARTS +[#howtouse] +-- + +[float] +=== See also +// Link relevant content by category, such as other Reference terms (please add the tag #LANGUAGE#), +// definitions (please add the tag #DEFINITION#), and examples of Projects and Tutorials +// (please add the tag #EXAMPLE#) ►►►►► THIS SECTION IS MANDATORY ◄◄◄◄◄ +[role="language"] +* #LANGUAGE# link:stream{ext-relative}[stream] + +* #LANGUAGE# link:streamReadByteUntil{ext-relative}[stream.readByteUntil()] +-- +// HOW TO USE SECTION ENDS diff --git a/Language/Functions/Communication/Serial/serialEvent.adoc b/Language/Functions/Communication/Serial/serialEvent.adoc new file mode 100644 index 000000000..f7a042226 --- /dev/null +++ b/Language/Functions/Communication/Serial/serialEvent.adoc @@ -0,0 +1,90 @@ +:source-highlighter: pygments +:pygments-style: arduino +:ext-relative: adoc + + += serialEvent() + + +// OVERVIEW SECTION STARTS +[#overview] +-- + +[float] +=== Description +Called when data is available. Use `Serial.read()` to capture this data. + +NB : Currently, `serialEvent()` is not compatible with the Esplora, Leonardo, or Micro +[%hardbreaks] + + +[float] +=== Syntax + +[source,arduino] +---- +void serialEvent(){ +//statements +} +---- +Arduino Mega only: +[source,arduino] +---- +void serialEvent1(){ +//statements +} + +void serialEvent2(){ +//statements +} + +void serialEvent3(){ +//statements +} +---- + +[float] +=== Parameters +`statements`: any valid statements + +[float] +=== Returns +Nothing + +-- +// OVERVIEW SECTION ENDS + + + + +// HOW TO USE SECTION STARTS +[#howtouse] +-- + +[float] +=== Notes and Warnings +[%hardbreaks] + +[float] +=== See also +// Link relevant content by category, such as other Reference terms (please add the tag #LANGUAGE#), +// definitions (please add the tag #DEFINITION#), and examples of Projects and Tutorials +// (please add the tag #EXAMPLE#) ►►►►► THIS SECTION IS MANDATORY ◄◄◄◄◄ +[role="example"] +* #EXAMPLE# http://arduino.cc/en/Tutorial/SerialEvent[SerialEvent Tutorial] + +[role="language"] +* #LANGUAGE# link:begin{ext-relative}[begin()] + +* #LANGUAGE# link:end{ext-relative}[end()] + +* #LANGUAGE# link:available{ext-relative}[available()] + +* #LANGUAGE# link:read{ext-relative}[read()] + +* #LANGUAGE# link:peek{ext-relative}[peek()] + +* #LANGUAGE# link:flush{ext-relative}[flush()] + +* #LANGUAGE# link:print{ext-relative}[print()] + +* #LANGUAGE# link:println{ext-relative}[println()] + +* #LANGUAGE# link:write{ext-relative}[write()] + +* #LANGUAGE# link:serialEvent{ext-relative}[SerialEvent()] + + +-- +// HOW TO USE SECTION ENDS diff --git a/Language/Functions/Communication/Serial/setTimeout.adoc b/Language/Functions/Communication/Serial/setTimeout.adoc new file mode 100644 index 000000000..4d0fa03f6 --- /dev/null +++ b/Language/Functions/Communication/Serial/setTimeout.adoc @@ -0,0 +1,53 @@ +:source-highlighter: pygments +:pygments-style: arduino +:ext-relative: adoc + + += Serial.setTimeout() + + +// OVERVIEW SECTION STARTS +[#overview] +-- + +[float] +=== Description +`Serial.setTimeout()` sets the maximum milliseconds to wait for serial data when using link:streamReadByteUntil{ext-relative}[stream.readByteUntil()] or link:streamReadByte{ext-relative}[stream.readByte()]. It defaults to 1000 milliseconds. + +`Serial.setTimeout()` inherits from the link:stream{ext-relative}[Stream] utility class. +[%hardbreaks] + + +[float] +=== Syntax +`Serial.setTimeout(time)` + +[float] +=== Parameters +`time` : timeout duration in milliseconds (`long`). + +[float] +=== Returns +Nothing + +-- +// OVERVIEW SECTION ENDS + + + + +// HOW TO USE SECTION STARTS +[#howtouse] +-- + +[float] +=== See also +// Link relevant content by category, such as other Reference terms (please add the tag #LANGUAGE#), +// definitions (please add the tag #DEFINITION#), and examples of Projects and Tutorials +// (please add the tag #EXAMPLE#) ►►►►► THIS SECTION IS MANDATORY ◄◄◄◄◄ +[role="language"] +* #LANGUAGE# link:stream{ext-relative}[stream] + +* #LANGUAGE# link:streamSetTimeout{ext-relative}[stream.setTimeout()] + +-- +// HOW TO USE SECTION ENDS diff --git a/Language/Functions/Communication/Serial/write.adoc b/Language/Functions/Communication/Serial/write.adoc new file mode 100644 index 000000000..0cdd80ab7 --- /dev/null +++ b/Language/Functions/Communication/Serial/write.adoc @@ -0,0 +1,91 @@ +:source-highlighter: pygments +:pygments-style: arduino +:ext-relative: adoc + + += write() + + +// OVERVIEW SECTION STARTS +[#overview] +-- + +[float] +=== Description +Writes binary data to the serial port. This data is sent as a byte or series of bytes; to send the characters representing the digits of a number use the link:print{ext-relative}[print()] function instead. +[%hardbreaks] + + +[float] +=== Syntax +`Serial.write(val)` + +`Serial.write(str)` + +`Serial.write(buf, len)` + +_Arduino Mega also supports:_ + +`Serial1`, `Serial2`, `Serial3` (in place of `Serial`) + + +[float] +=== Parameters +`val`: a value to send as a single byte + +`str`: a string to send as a series of bytes + +`buf`: an array to send as a series of bytes + +[float] +=== Returns +`byte` + +`write()` will return the number of bytes written, though reading that number is optional + +-- +// OVERVIEW SECTION ENDS + + + + +// HOW TO USE SECTION STARTS +[#howtouse] +-- +[float] +=== Example Code +// Describe what the example code is all about and add relevant code ►►►►► THIS SECTION IS MANDATORY ◄◄◄◄◄ + + +[source,arduino] +---- +void setup(){ + Serial.begin(9600); +} + +void loop(){ + Serial.write(45); // send a byte with the value 45 + + int bytesSent = Serial.write(“hello”); //send the string “hello” and return the length of the string. +} +---- +[%hardbreaks] + + +[float] +=== See also +// Link relevant content by category, such as other Reference terms (please add the tag #LANGUAGE#), +// definitions (please add the tag #DEFINITION#), and examples of Projects and Tutorials +// (please add the tag #EXAMPLE#) ►►►►► THIS SECTION IS MANDATORY ◄◄◄◄◄ +[role="language"] +* #LANGUAGE# link:begin{ext-relative}[begin()] + +* #LANGUAGE# link:end{ext-relative}[end()] + +* #LANGUAGE# link:available{ext-relative}[available()] + +* #LANGUAGE# link:read{ext-relative}[read()] + +* #LANGUAGE# link:peek{ext-relative}[peek()] + +* #LANGUAGE# link:flush{ext-relative}[flush()] + +* #LANGUAGE# link:print{ext-relative}[print()] + +* #LANGUAGE# link:println{ext-relative}[println()] + +* #LANGUAGE# link:write{ext-relative}[write()] + +* #LANGUAGE# link:serialEvent{ext-relative}[SerialEvent()] + +-- +// HOW TO USE SECTION ENDS diff --git a/Language/Functions/Communication/Stream/streamAvailable.adoc b/Language/Functions/Communication/Stream/streamAvailable.adoc new file mode 100644 index 000000000..c268edbe6 --- /dev/null +++ b/Language/Functions/Communication/Stream/streamAvailable.adoc @@ -0,0 +1,53 @@ +:source-highlighter: pygments +:pygments-style: arduino +:ext-relative: adoc + + += available() + + +// OVERVIEW SECTION STARTS +[#overview] +-- + +[float] +=== Description +`available()` gets the number of bytes available in the stream. This is only for bytes that have already arrived. + +This function is part of the Stream class, and is called by any class that inherits from it (Wire, Serial, etc). See the link:stream{ext-relative}[Stream class] main page for more information. +[%hardbreaks] + + +[float] +=== Syntax +`stream.available()` + + +[float] +=== Parameters +`stream` : an instance of a class that inherits from Stream. + +[float] +=== Returns +`int` : the number of bytes available to read + +-- +// OVERVIEW SECTION ENDS + + + + +// HOW TO USE SECTION STARTS +[#howtouse] +-- + +[float] +=== See also +// Link relevant content by category, such as other Reference terms (please add the tag #LANGUAGE#), +// definitions (please add the tag #DEFINITION#), and examples of Projects and Tutorials +// (please add the tag #EXAMPLE#) ►►►►► THIS SECTION IS MANDATORY ◄◄◄◄◄ +[role="language"] +* #LANGUAGE# link:stream{ext-relative}[stream] + +-- +// HOW TO USE SECTION ENDS diff --git a/Language/Functions/Communication/Stream/streamFind.adoc b/Language/Functions/Communication/Stream/streamFind.adoc new file mode 100644 index 000000000..0438d357f --- /dev/null +++ b/Language/Functions/Communication/Stream/streamFind.adoc @@ -0,0 +1,58 @@ +:source-highlighter: pygments +:pygments-style: arduino +:ext-relative: adoc + + += find() + + +// OVERVIEW SECTION STARTS +[#overview] +-- + +[float] +=== Description +`find()` reads data from the stream until the target string of given length is found The function returns true if target string is found, false if timed out. + +This function is part of the Stream class, and is called by any class that inherits from it (Wire, Serial, etc). See the link:stream{ext-relative}[stream class] main page for more information. +[%hardbreaks] + + +[float] +=== Syntax +`stream.find(target)` + + +[float] +=== Parameters +`stream` : an instance of a class that inherits from Stream. + +`target` : the string to search for (char) + +[float] +=== Returns +`boolean` + +-- +// OVERVIEW SECTION ENDS + + + + +// HOW TO USE SECTION STARTS +[#howtouse] +-- + +[float] +=== Example Code +// Describe what the example code is all about and add relevant code ►►►►► THIS SECTION IS MANDATORY ◄◄◄◄◄ + +[float] +=== See also +// Link relevant content by category, such as other Reference terms (please add the tag #LANGUAGE#), +// definitions (please add the tag #DEFINITION#), and examples of Projects and Tutorials +// (please add the tag #EXAMPLE#) ►►►►► THIS SECTION IS MANDATORY ◄◄◄◄◄ +[role="language"] +* #LANGUAGE# link:stream{ext-relative}[stream] +-- +// HOW TO USE SECTION ENDS diff --git a/Language/Functions/Communication/Stream/streamFindUntil.adoc b/Language/Functions/Communication/Stream/streamFindUntil.adoc new file mode 100644 index 000000000..4044b080e --- /dev/null +++ b/Language/Functions/Communication/Stream/streamFindUntil.adoc @@ -0,0 +1,58 @@ +:source-highlighter: pygments +:pygments-style: arduino +:ext-relative: adoc + + += Entity title() + + +// OVERVIEW SECTION STARTS +[#overview] +-- + +[float] +=== Description +`findUntil()` reads data from the stream until the target string of given length or terminator string is found. + +The function returns true if target string is found, false if timed out + +This function is part of the Stream class, and is called by any class that inherits from it (Wire, Serial, etc). See the #LANGUAGE# link:stream{ext-relative}[Stream class] main page for more information. +[%hardbreaks] + + +[float] +=== Syntax +`stream.findUntil(target, terminal)` + + +[float] +=== Parameters +`stream.findUntil(target, terminal)` + +[float] +=== Returns +`boolean` + +-- +// OVERVIEW SECTION ENDS + + + + +// HOW TO USE SECTION STARTS +[#howtouse] +-- + +[float] +=== Example Code +// Describe what the example code is all about and add relevant code ►►►►► THIS SECTION IS MANDATORY ◄◄◄◄◄ + +[float] +=== See also +// Link relevant content by category, such as other Reference terms (please add the tag #LANGUAGE#), +// definitions (please add the tag #DEFINITION#), and examples of Projects and Tutorials +// (please add the tag #EXAMPLE#) ►►►►► THIS SECTION IS MANDATORY ◄◄◄◄◄ +[role="language"] +* #LANGUAGE# link:stream{ext-relative}[stream] +-- +// HOW TO USE SECTION ENDS diff --git a/Language/Functions/Communication/Stream/streamFlush.adoc b/Language/Functions/Communication/Stream/streamFlush.adoc new file mode 100644 index 000000000..5ea22db6d --- /dev/null +++ b/Language/Functions/Communication/Stream/streamFlush.adoc @@ -0,0 +1,53 @@ +:source-highlighter: pygments +:pygments-style: arduino +:ext-relative: adoc + + += flush() + + +// OVERVIEW SECTION STARTS +[#overview] +-- + +[float] +=== Description +`flush()` clears the buffer once all outgoing characters have been sent. + +This function is part of the Stream class, and is called by any class that inherits from it (Wire, Serial, etc). See the link:stream{ext-relative}[stream class] main page for more information. +[%hardbreaks] + + +[float] +=== Syntax +`stream.flush()` + + +[float] +=== Parameters +`stream` : an instance of a class that inherits from Stream. + +[float] +=== Returns +`boolean` + +-- +// OVERVIEW SECTION ENDS + + + + +// HOW TO USE SECTION STARTS +[#howtouse] +-- + +[float] +=== See also +// Link relevant content by category, such as other Reference terms (please add the tag #LANGUAGE#), +// definitions (please add the tag #DEFINITION#), and examples of Projects and Tutorials +// (please add the tag #EXAMPLE#) ►►►►► THIS SECTION IS MANDATORY ◄◄◄◄◄ +[role="language"] +* #LANGUAGE# link:stream{ext-relative}[stream] + +-- +// HOW TO USE SECTION ENDS diff --git a/Language/Functions/Communication/Stream/streamParseFloat.adoc b/Language/Functions/Communication/Stream/streamParseFloat.adoc new file mode 100644 index 000000000..4c9a098d4 --- /dev/null +++ b/Language/Functions/Communication/Stream/streamParseFloat.adoc @@ -0,0 +1,58 @@ +:source-highlighter: pygments +:pygments-style: arduino +:ext-relative: adoc + + += parseFloat() + + +// OVERVIEW SECTION STARTS +[#overview] +-- + +[float] +=== Description +`parseFloat()` returns the first valid floating point number from the current position. Initial characters that are not digits (or the minus sign) are skipped. `parseFloat()` is terminated by the first character that is not a floating point number. + +This function is part of the Stream class, and is called by any class that inherits from it (Wire, Serial, etc). See the link:stream{ext-relative}[Stream class] main page for more informatio +[%hardbreaks] + + +[float] +=== Syntax +`stream.parseFloat(list)` + + +[float] +=== Parameters +`stream` : an instance of a class that inherits from Stream. + +`list` : the stream to check for floats (`char`) + +[float] +=== Returns +`float` + +-- +// OVERVIEW SECTION ENDS + + + + +// HOW TO USE SECTION STARTS +[#howtouse] +-- + +[float] +=== Example Code +// Describe what the example code is all about and add relevant code ►►►►► THIS SECTION IS MANDATORY ◄◄◄◄◄ + +[float] +=== See also +// Link relevant content by category, such as other Reference terms (please add the tag #LANGUAGE#), +// definitions (please add the tag #DEFINITION#), and examples of Projects and Tutorials +// (please add the tag #EXAMPLE#) ►►►►► THIS SECTION IS MANDATORY ◄◄◄◄◄ +[role="language"] +* #LANGUAGE# link:stream{ext-relative}[stream] +-- +// HOW TO USE SECTION ENDS diff --git a/Language/Functions/Communication/Stream/streamParseInt.adoc b/Language/Functions/Communication/Stream/streamParseInt.adoc new file mode 100644 index 000000000..7daf2efcd --- /dev/null +++ b/Language/Functions/Communication/Stream/streamParseInt.adoc @@ -0,0 +1,58 @@ +:source-highlighter: pygments +:pygments-style: arduino +:ext-relative: adoc + + += parseInt() + + +// OVERVIEW SECTION STARTS +[#overview] +-- + +[float] +=== Description +`parseInt()` returns the first valid (long) integer number from the current position. Initial characters that are not integers (or the minus sign) are skipped. `parseInt()` is terminated by the first character that is not a digit. + +This function is part of the Stream class, and is called by any class that inherits from it (Wire, Serial, etc). See the link:stream{ext-relative}[Stream class] main page for more information. +[%hardbreaks] + + +[float] +=== Syntax +`stream.parseInt(list)` + + +[float] +=== Parameters +`stream` : an instance of a class that inherits from Stream. + +`list` : the stream to check for ints (`char`) + +[float] +=== Returns +`int` + +-- +// OVERVIEW SECTION ENDS + + + + +// HOW TO USE SECTION STARTS +[#howtouse] +-- + +[float] +=== Example Code +// Describe what the example code is all about and add relevant code ►►►►► THIS SECTION IS MANDATORY ◄◄◄◄◄ + +[float] +=== See also +// Link relevant content by category, such as other Reference terms (please add the tag #LANGUAGE#), +// definitions (please add the tag #DEFINITION#), and examples of Projects and Tutorials +// (please add the tag #EXAMPLE#) ►►►►► THIS SECTION IS MANDATORY ◄◄◄◄◄ +[role="language"] +* #LANGUAGE# link:stream{ext-relative}[stream] +-- +// HOW TO USE SECTION ENDS diff --git a/Language/Functions/Communication/Stream/streamPeek.adoc b/Language/Functions/Communication/Stream/streamPeek.adoc new file mode 100644 index 000000000..97ea5d8bf --- /dev/null +++ b/Language/Functions/Communication/Stream/streamPeek.adoc @@ -0,0 +1,58 @@ +:source-highlighter: pygments +:pygments-style: arduino +:ext-relative: adoc + + += peek() + + +// OVERVIEW SECTION STARTS +[#overview] +-- + +[float] +=== Description +Read a byte from the file without advancing to the next one. That is, successive calls to `peek()` will return the same value, as will the next call to `read()`. + +This function is part of the Stream class, and is called by any class that inherits from it (Wire, Serial, etc). See the link:stream{ext-relative}[Stream class] main page for more information. +[%hardbreaks] + + +[float] +=== Syntax +`stream.peek()` + + +[float] +=== Parameters +`stream` : an instance of a class that inherits from Stream. + +[float] +=== Returns +The next byte (or character), or -1 if none is available. + +-- +// OVERVIEW SECTION ENDS + + + + +// HOW TO USE SECTION STARTS +[#howtouse] +-- + +[float] +=== Example Code +// Describe what the example code is all about and add relevant code ►►►►► THIS SECTION IS MANDATORY ◄◄◄◄◄ + +[float] +=== See also +// Link relevant content by category, such as other Reference terms (please add the tag #LANGUAGE#), +// definitions (please add the tag #DEFINITION#), and examples of Projects and Tutorials +// (please add the tag #EXAMPLE#) ►►►►► THIS SECTION IS MANDATORY ◄◄◄◄◄ +[role="language"] +* #LANGUAGE# link:streamAvailable{ext-relative}[available()] + +* #LANGUAGE# link:streamRead{ext-relative}[read()] + +-- +// HOW TO USE SECTION ENDS diff --git a/Language/Functions/Communication/Stream/streamRead.adoc b/Language/Functions/Communication/Stream/streamRead.adoc new file mode 100644 index 000000000..e83ad1630 --- /dev/null +++ b/Language/Functions/Communication/Stream/streamRead.adoc @@ -0,0 +1,53 @@ +:source-highlighter: pygments +:pygments-style: arduino +:ext-relative: adoc + + += read() + + +// OVERVIEW SECTION STARTS +[#overview] +-- + +[float] +=== Description +`read()` reads characters from an incoming stream to the buffer. + +This function is part of the Stream class, and is called by any class that inherits from it (Wire, Serial, etc). See the link:stream{ext-relative}[stream class] main page for more information. +[%hardbreaks] + + +[float] +=== Syntax +`stream.read()` + + +[float] +=== Parameters +`stream` : an instance of a class that inherits from Stream. + +[float] +=== Returns +The first byte of incoming data available (or -1 if no data is available). + +-- +// OVERVIEW SECTION ENDS + + + + +// HOW TO USE SECTION STARTS +[#howtouse] +-- + +[float] +=== See also +// Link relevant content by category, such as other Reference terms (please add the tag #LANGUAGE#), +// definitions (please add the tag #DEFINITION#), and examples of Projects and Tutorials +// (please add the tag #EXAMPLE#) ►►►►► THIS SECTION IS MANDATORY ◄◄◄◄◄ +[role="language"] +* #LANGUAGE# link:stream{ext-relative}[stream] + +-- +// HOW TO USE SECTION ENDS diff --git a/Language/Functions/Communication/Stream/streamReadBytes.adoc b/Language/Functions/Communication/Stream/streamReadBytes.adoc new file mode 100644 index 000000000..944d411aa --- /dev/null +++ b/Language/Functions/Communication/Stream/streamReadBytes.adoc @@ -0,0 +1,63 @@ +:source-highlighter: pygments +:pygments-style: arduino +:ext-relative: adoc + + += readBytes() + + +// OVERVIEW SECTION STARTS +[#overview] +-- + +[float] +=== Description +`readBytes()` read characters from a stream into a buffer. The function terminates if the determined length has been read, or it times out (see link:streamSetTimeout{ext-relative}[setTimeout()]). + +`readBytes()` returns the number of bytes placed in the buffer. A 0 means no valid data was found. + +This function is part of the Stream class, and is called by any class that inherits from it (Wire, Serial, etc). See the link:stream{ext-relative}[Stream class] main page for more information. +[%hardbreaks] + + +[float] +=== Syntax +`stream.readBytes(buffer, length)` + + +[float] +=== Parameters +`stream` : an instance of a class that inherits from Stream. + +`buffer` : the buffer to store the bytes in (`char[]` or `byte[]`) + +`length` : the number of bytes to `read(int)` + +[float] +=== Returns +The number of bytes placed in the buffer. + +-- +// OVERVIEW SECTION ENDS + + + + +// HOW TO USE SECTION STARTS +[#howtouse] +-- + +[float] +=== Example Code +// Describe what the example code is all about and add relevant code ►►►►► THIS SECTION IS MANDATORY ◄◄◄◄◄ + +[float] +=== See also +// Link relevant content by category, such as other Reference terms (please add the tag #LANGUAGE#), +// definitions (please add the tag #DEFINITION#), and examples of Projects and Tutorials +// (please add the tag #EXAMPLE#) ►►►►► THIS SECTION IS MANDATORY ◄◄◄◄◄ +[role="language"] +* #LANGUAGE# link:stream{ext-relative}[stream] + +-- +// HOW TO USE SECTION ENDS diff --git a/Language/Functions/Communication/Stream/streamReadBytesUntil.adoc b/Language/Functions/Communication/Stream/streamReadBytesUntil.adoc new file mode 100644 index 000000000..f91478118 --- /dev/null +++ b/Language/Functions/Communication/Stream/streamReadBytesUntil.adoc @@ -0,0 +1,64 @@ +:source-highlighter: pygments +:pygments-style: arduino +:ext-relative: adoc + + += readBytesUntil() + + +// OVERVIEW SECTION STARTS +[#overview] +-- + +[float] +=== Description +`readBytesUntil()` reads characters from a stream into a buffer. The function terminates if the terminator character is detected, the determined length has been read, or it times out (see link:streamSetTimeout{ext-relative}[setTimeout()]). + +`readBytesUntil()` returns the number of bytes placed in the buffer. A 0 means no valid data was found. + +This function is part of the Stream class, and is called by any class that inherits from it (Wire, Serial, etc). See the link:stream{ext-relative}[Stream class] main page for more information. +[%hardbreaks] + + +[float] +=== Syntax +`stream.readBytesUntil(character, buffer, length)` + + +[float] +=== Parameters +`stream` : an instance of a class that inherits from Stream. + +`character` : the character to search for (`char`) + +`buffer`: the buffer to store the bytes in (`char[]` or `byte[]`) + +`length : the number of bytes to `read(int)` + +[float] +=== Returns +The number of bytes placed in the buffer. + +-- +// OVERVIEW SECTION ENDS + + + + +// HOW TO USE SECTION STARTS +[#howtouse] +-- + +[float] +=== Example Code +// Describe what the example code is all about and add relevant code ►►►►► THIS SECTION IS MANDATORY ◄◄◄◄◄ + +[float] +=== See also +// Link relevant content by category, such as other Reference terms (please add the tag #LANGUAGE#), +// definitions (please add the tag #DEFINITION#), and examples of Projects and Tutorials +// (please add the tag #EXAMPLE#) ►►►►► THIS SECTION IS MANDATORY ◄◄◄◄◄ +[role="language"] +* #LANGUAGE# link:stream{ext-relative}[stream] +-- +// HOW TO USE SECTION ENDS diff --git a/Language/Functions/Communication/Stream/streamReadString.adoc b/Language/Functions/Communication/Stream/streamReadString.adoc new file mode 100644 index 000000000..5dfd0a7ca --- /dev/null +++ b/Language/Functions/Communication/Stream/streamReadString.adoc @@ -0,0 +1,56 @@ +:source-highlighter: pygments +:pygments-style: arduino +:ext-relative: adoc + + += readString() + + +// OVERVIEW SECTION STARTS +[#overview] +-- + +[float] +=== Description +`readString()` reads characters from a stream into a string. The function terminates if it times out (see link:streamSetTimeout{ext-relative}[setTimeout()]). + +This function is part of the Stream class, and is called by any class that inherits from it (Wire, Serial, etc). See the link:stream{ext-relative}[Stream class] main page for more information. +[%hardbreaks] + + +[float] +=== Syntax +`stream.readString()` + + +[float] +=== Parameters +Nothing + +[float] +=== Returns +A string read from a stream. + +-- +// OVERVIEW SECTION ENDS + + + + +// HOW TO USE SECTION STARTS +[#howtouse] +-- + +[float] +=== Example Code +// Describe what the example code is all about and add relevant code ►►►►► THIS SECTION IS MANDATORY ◄◄◄◄◄ + +[float] +=== See also +// Link relevant content by category, such as other Reference terms (please add the tag #LANGUAGE#), +// definitions (please add the tag #DEFINITION#), and examples of Projects and Tutorials +// (please add the tag #EXAMPLE#) ►►►►► THIS SECTION IS MANDATORY ◄◄◄◄◄ +[role="language"] +* #LANGUAGE# link:stream{ext-relative}[stream] +-- +// HOW TO USE SECTION ENDS diff --git a/Language/Functions/Communication/Stream/streamReadStringUntil.adoc b/Language/Functions/Communication/Stream/streamReadStringUntil.adoc new file mode 100644 index 000000000..f066e4a85 --- /dev/null +++ b/Language/Functions/Communication/Stream/streamReadStringUntil.adoc @@ -0,0 +1,56 @@ +:source-highlighter: pygments +:pygments-style: arduino +:ext-relative: adoc + + += readStringUntil() + + +// OVERVIEW SECTION STARTS +[#overview] +-- + +[float] +=== Description +`readStringUntil()` reads characters from a stream into a string. The function terminates if the terminator character is detected or it times out (see link:streamSetTimeout{ext-relative}[setTimeout()]). + +This function is part of the Stream class, and is called by any class that inherits from it (Wire, Serial, etc). See the link:stream{ext-relative}[Stream class] main page for more information. +[%hardbreaks] + + +[float] +=== Syntax +`stream.readString(terminator)` + + +[float] +=== Parameters +`terminator` : the character to search for (`char`) + +[float] +=== Returns +The entire string read from a stream, until the terminator character is detected. + +-- +// OVERVIEW SECTION ENDS + + + + +// HOW TO USE SECTION STARTS +[#howtouse] +-- + +[float] +=== Example Code +// Describe what the example code is all about and add relevant code ►►►►► THIS SECTION IS MANDATORY ◄◄◄◄◄ + +[float] +=== See also +// Link relevant content by category, such as other Reference terms (please add the tag #LANGUAGE#), +// definitions (please add the tag #DEFINITION#), and examples of Projects and Tutorials +// (please add the tag #EXAMPLE#) ►►►►► THIS SECTION IS MANDATORY ◄◄◄◄◄ +[role="language"] +* #LANGUAGE# link:stream{ext-relative}[stream] +-- +// HOW TO USE SECTION ENDS diff --git a/Language/Functions/Communication/Stream/streamSetTimeout.adoc b/Language/Functions/Communication/Stream/streamSetTimeout.adoc new file mode 100644 index 000000000..861cb8d66 --- /dev/null +++ b/Language/Functions/Communication/Stream/streamSetTimeout.adoc @@ -0,0 +1,55 @@ +:source-highlighter: pygments +:pygments-style: arduino +:ext-relative: adoc + + += setTimeout() + + +// OVERVIEW SECTION STARTS +[#overview] +-- + +[float] +=== Description +`setTimeout()` sets the maximum milliseconds to wait for stream data, it defaults to 1000 milliseconds. This function is part of the Stream class, and is called by any class that inherits from it (Wire, Serial, etc). See the #LANGUAGE# link:stream{ext-relative}[Stream class] main page for more information. +[%hardbreaks] + + +[float] +=== Syntax +`stream.setTimeout(time)` + + +[float] +=== Parameters +`stream` : an instance of a class that inherits from Stream. +`time` : timeout duration in milliseconds (`long`). + +[float] +=== Returns +Nothing + +-- +// OVERVIEW SECTION ENDS + + + + +// HOW TO USE SECTION STARTS +[#howtouse] +-- + +[float] +=== Example Code +// Describe what the example code is all about and add relevant code ►►►►► THIS SECTION IS MANDATORY ◄◄◄◄◄ + +[float] +=== See also +// Link relevant content by category, such as other Reference terms (please add the tag #LANGUAGE#), +// definitions (please add the tag #DEFINITION#), and examples of Projects and Tutorials +// (please add the tag #EXAMPLE#) ►►►►► THIS SECTION IS MANDATORY ◄◄◄◄◄ +[role="language"] +* #LANGUAGE# link:stream{ext-relative}[stream] +-- +// HOW TO USE SECTION ENDS diff --git a/Language/Functions/Interrupts/interrupts.adoc b/Language/Functions/Interrupts/interrupts.adoc new file mode 100644 index 000000000..4b570ec6c --- /dev/null +++ b/Language/Functions/Interrupts/interrupts.adoc @@ -0,0 +1,73 @@ +:source-highlighter: pygments +:pygments-style: arduino +:ext-relative: adoc + + += interrupts() + + +// OVERVIEW SECTION STARTS +[#overview] +-- + +[float] +=== Description +Re-enables interrupts (after they've been disabled by link:noInterrupt{ext-relative}[noInterrupts()]). Interrupts allow certain important tasks to happen in the background and are enabled by default. Some functions will not work while interrupts are disabled, and incoming communication may be ignored. Interrupts can slightly disrupt the timing of code, however, and may be disabled for particularly critical sections of code. +[%hardbreaks] + + +[float] +=== Syntax +`interrupts()` + + +[float] +=== Parameters +Nothing + +[float] +=== Returns +Nothing + +-- +// OVERVIEW SECTION ENDS + + + + +// HOW TO USE SECTION STARTS +[#howtouse] +-- + +[float] +=== Example Code +// Describe what the example code is all about and add relevant code ►►►►► THIS SECTION IS MANDATORY ◄◄◄◄◄ +The code enables Interrupts. + +[source,arduino] +---- +void setup() {} + +void loop() +{ + noInterrupts(); + // critical, time-sensitive code here + interrupts(); + // other code here +} +---- +[%hardbreaks] + + +[float] +=== See also +// Link relevant content by category, such as other Reference terms (please add the tag #LANGUAGE#), +// definitions (please add the tag #DEFINITION#), and examples of Projects and Tutorials +// (please add the tag #EXAMPLE#) ►►►►► THIS SECTION IS MANDATORY ◄◄◄◄◄ +[role="language"] +* #LANGUAGE# link:noInterrupts{ext-relatives}[noInterrupts()] + +* #LANGUAGE# link:attachInterrupts{ext-relatives}[attachInterrupts()] + +* #LANGUAGE# link:detachInterrupts{ext-relatives}[detachInterrupts()] + +-- +// HOW TO USE SECTION ENDS diff --git a/Language/Functions/Interrupts/noInterrupts.adoc b/Language/Functions/Interrupts/noInterrupts.adoc new file mode 100644 index 000000000..51ba264d8 --- /dev/null +++ b/Language/Functions/Interrupts/noInterrupts.adoc @@ -0,0 +1,71 @@ +:source-highlighter: pygments +:pygments-style: arduino +:ext-relative: adoc + + += noInterrupts() + + +// OVERVIEW SECTION STARTS +[#overview] +-- + +[float] +=== Description +Disables interrupts (you can re-enable them with `interrupts()`). Interrupts allow certain important tasks to happen in the background and are enabled by default. Some functions will not work while interrupts are disabled, and incoming communication may be ignored. Interrupts can slightly disrupt the timing of code, however, and may be disabled for particularly critical sections of code. +[%hardbreaks] + + +[float] +=== Syntax +`noInterrupts()` + + +[float] +=== Parameters +Nothing + +[float] +=== Returns +Nothing + +-- +// OVERVIEW SECTION ENDS + + + + +// HOW TO USE SECTION STARTS +[#howtouse] +-- + +[float] +=== Example Code +// Describe what the example code is all about and add relevant code ►►►►► THIS SECTION IS MANDATORY ◄◄◄◄◄ +The code shows how to enable interrupts. + +[source,arduino] +---- +void setup() {} + +void loop() +{ + noInterrupts(); + // critical, time-sensitive code here + interrupts(); + // other code here +} +---- +[%hardbreaks] + +[float] +=== See also +// Link relevant content by category, such as other Reference terms (please add the tag #LANGUAGE#), +// definitions (please add the tag #DEFINITION#), and examples of Projects and Tutorials +// (please add the tag #EXAMPLE#) ►►►►► THIS SECTION IS MANDATORY ◄◄◄◄◄ +[role="language"] +* #LANGUAGE# link:interrupts{ext-relatives}[interrupts()] + + +-- +// HOW TO USE SECTION ENDS diff --git a/Language/Functions/Math/abs.adoc b/Language/Functions/Math/abs.adoc new file mode 100644 index 000000000..3c06fa830 --- /dev/null +++ b/Language/Functions/Math/abs.adoc @@ -0,0 +1,58 @@ +:source-highlighter: pygments +:pygments-style: arduino +:ext-relative: adoc + + += abs(x) + + +// OVERVIEW SECTION STARTS +[#overview] +-- + +[float] +=== Description +Calculates the maximum of two numbers. +[%hardbreaks] + + +[float] +=== Syntax +`abs(x)` + +[float] +=== Parameters +`x`: the number + +[float] +=== Returns +`x`: if x is greater than or equal to 0. + +`-x`: if x is less than 0. + +-- +// OVERVIEW SECTION ENDS + + + + +// HOW TO USE SECTION STARTS +[#howtouse] +-- + + +[float] +=== Notes and Warnings +Because of the way the abs() function is implemented, avoid using other functions inside the brackets, it may lead to incorrect results. +[source,arduino] +---- +abs(a++); // avoid this - yields incorrect results + +a++; // use this instead - +abs(a); // keep other math outside the function +---- +[%hardbreaks] + + +-- +// HOW TO USE SECTION ENDS diff --git a/Language/Functions/Math/constrain.adoc b/Language/Functions/Math/constrain.adoc new file mode 100644 index 000000000..f57799e9b --- /dev/null +++ b/Language/Functions/Math/constrain.adoc @@ -0,0 +1,71 @@ +:source-highlighter: pygments +:pygments-style: arduino +:ext-relative: adoc + + += constrain(x, a, b) + + +// OVERVIEW SECTION STARTS +[#overview] +-- + +[float] +=== Description +Constrains a number to be within a range. +[%hardbreaks] + + +[float] +=== Syntax +`constrain(x, a, b)` + + +[float] +=== Parameters +`x`: the number to constrain, all data types +`a`: the lower end of the range, all data types +`b`: the upper end of the range, all data types + +[float] +=== Returns +x: if x is between a and b + +a: if x is less than a + +b: if x is greater than b + +-- +// OVERVIEW SECTION ENDS + + + + +// HOW TO USE SECTION STARTS +[#howtouse] +-- + +[float] +=== Example Code +// Describe what the example code is all about and add relevant code ►►►►► THIS SECTION IS MANDATORY ◄◄◄◄◄ +The code limits the sensor values to between 10 to 150. + +[source,arduino] +---- +sensVal = constrain(sensVal, 10, 150); // limits range of sensor values to between 10 and 150 +---- +[%hardbreaks] + + +[float] +=== See also +// Link relevant content by category, such as other Reference terms (please add the tag #LANGUAGE#), +// definitions (please add the tag #DEFINITION#), and examples of Projects and Tutorials +// (please add the tag #EXAMPLE#) ►►►►► THIS SECTION IS MANDATORY ◄◄◄◄◄ +[role="language"] +* #LANGUAGE# link:min{ext-relative}[min()] + +* #LANGUAGE# link:max{ext-relative}[max()] + + +-- +// HOW TO USE SECTION ENDS diff --git a/Language/Functions/Math/map.adoc b/Language/Functions/Math/map.adoc new file mode 100644 index 000000000..bc75c0cf8 --- /dev/null +++ b/Language/Functions/Math/map.adoc @@ -0,0 +1,67 @@ +:source-highlighter: pygments +:pygments-style: arduino +:ext-relative: adoc + + += map(value, fromLow, fromHigh, toLow, toHigh) + + +// OVERVIEW SECTION STARTS +[#overview] +-- + +[float] +=== Description +[%hardbreaks] + + +[float] +=== Syntax + + + +[float] +=== Parameters + + +[float] +=== Returns +Nothing + +-- +// OVERVIEW SECTION ENDS + + + + +// HOW TO USE SECTION STARTS +[#howtouse] +-- + +[float] +=== Example Code +// Describe what the example code is all about and add relevant code ►►►►► THIS SECTION IS MANDATORY ◄◄◄◄◄ + + +[source,arduino] +---- + +---- +[%hardbreaks] + +[float] +=== Notes and Warnings +[%hardbreaks] + +[float] +=== See also +// Link relevant content by category, such as other Reference terms (please add the tag #LANGUAGE#), +// definitions (please add the tag #DEFINITION#), and examples of Projects and Tutorials +// (please add the tag #EXAMPLE#) ►►►►► THIS SECTION IS MANDATORY ◄◄◄◄◄ +[role="language"] +* #LANGUAGE# +* #DEFINITION# +* #EXAMPLE# + +-- +// HOW TO USE SECTION ENDS diff --git a/Language/Functions/Math/max.adoc b/Language/Functions/Math/max.adoc new file mode 100644 index 000000000..4a1ebbc4f --- /dev/null +++ b/Language/Functions/Math/max.adoc @@ -0,0 +1,80 @@ +:source-highlighter: pygments +:pygments-style: arduino +:ext-relative: adoc + + += max(x, y) + + +// OVERVIEW SECTION STARTS +[#overview] +-- + +[float] +=== Description +Calculates the maximum of two numbers. +[%hardbreaks] + + +[float] +=== Syntax +`max(x, y)` + + +[float] +=== Parameters +`x`: the first number, any data type +`y`: the second number, any data type + +[float] +=== Returns +The larger of the two parameter values. + +-- +// OVERVIEW SECTION ENDS + + + + +// HOW TO USE SECTION STARTS +[#howtouse] +-- + +[float] +=== Example Code +// Describe what the example code is all about and add relevant code ►►►►► THIS SECTION IS MANDATORY ◄◄◄◄◄ +The code ensures that sensVal is at least 20. + +[source,arduino] +---- +sensVal = max(senVal, 20); // assigns sensVal to the larger of sensVal or 20 + // (effectively ensuring that it is at least 20) +---- +[%hardbreaks] + +[float] +=== Notes and Warnings +Perhaps counter-intuitively, `max()` is often used to constrain the lower end of a variable's range, while `min()` is used to constrain the upper end of the range. + +Because of the way the `max()` function is implemented, avoid using other functions inside the brackets, it may lead to incorrect results +[source,arduino] +---- +max(a--, 0); // avoid this - yields incorrect results + +a--; // use this instead - +max(a, 0); // keep other math outside the function +---- +[%hardbreaks] + +[float] +=== See also +// Link relevant content by category, such as other Reference terms (please add the tag #LANGUAGE#), +// definitions (please add the tag #DEFINITION#), and examples of Projects and Tutorials +// (please add the tag #EXAMPLE#) ►►►►► THIS SECTION IS MANDATORY ◄◄◄◄◄ +[role="language"] +* #LANGUAGE# link:min{ext-relative}[min()] + +* #LANGUAGE# link:constrain{ext-relative}[constrain()] + + +-- +// HOW TO USE SECTION ENDS diff --git a/Language/Functions/Math/min.adoc b/Language/Functions/Math/min.adoc new file mode 100644 index 000000000..5eea7d198 --- /dev/null +++ b/Language/Functions/Math/min.adoc @@ -0,0 +1,80 @@ +:source-highlighter: pygments +:pygments-style: arduino +:ext-relative: adoc + + += min(x, y) + + +// OVERVIEW SECTION STARTS +[#overview] +-- + +[float] +=== Description +Calculates the minimum of two numbers. +[%hardbreaks] + + +[float] +=== Syntax +`min(x, y)` + + +[float] +=== Parameters +`x`: the first number, any data type + +`y`: the second number, any data type + +[float] +=== Returns +The smaller of the two numbers. + +-- +// OVERVIEW SECTION ENDS + + + + +// HOW TO USE SECTION STARTS +[#howtouse] +-- + +[float] +=== Example Code +// Describe what the example code is all about and add relevant code ►►►►► THIS SECTION IS MANDATORY ◄◄◄◄◄ +The code ensures that it never gets above 100. + +[source,arduino] +---- +sensVal = min(sensVal, 100); // assigns sensVal to the smaller of sensVal or 100 + // ensuring that it never gets above 100. +---- +[%hardbreaks] + +[float] +=== Notes and Warnings +Perhaps counter-intuitively, `max()` is often used to constrain the lower end of a variable's range, while `min()` is used to constrain the upper end of the range. + +Because of the way the `min()` function is implemented, avoid using other functions inside the brackets, it may lead to incorrect results +[source,arduino] +---- +min(a++, 100); // avoid this - yields incorrect results + +a++; +min(a, 100); // use this instead - keep other math outside the function +---- +[%hardbreaks] + +[float] +=== See also +// Link relevant content by category, such as other Reference terms (please add the tag #LANGUAGE#), +// definitions (please add the tag #DEFINITION#), and examples of Projects and Tutorials +// (please add the tag #EXAMPLE#) ►►►►► THIS SECTION IS MANDATORY ◄◄◄◄◄ +[role="language"] +* #LANGUAGE# link:max{ext-relative}[max()] + +* #LANGUAGE# link:constrain{ext-relative}[constrain()] + +-- +// HOW TO USE SECTION ENDS diff --git a/Language/Functions/Math/pow.adoc b/Language/Functions/Math/pow.adoc new file mode 100644 index 000000000..5207ea058 --- /dev/null +++ b/Language/Functions/Math/pow.adoc @@ -0,0 +1,61 @@ +:source-highlighter: pygments +:pygments-style: arduino +:ext-relative: adoc + + += pow(base, exponent) + + +// OVERVIEW SECTION STARTS +[#overview] +-- + +[float] +=== Description +Calculates the value of a number raised to a power. `Pow()` can be used to raise a number to a fractional power. This is useful for generating exponential mapping of values or curves. +[%hardbreaks] + + +[float] +=== Syntax +`pow(base, exponent)` + + +[float] +=== Parameters +`base`: the number (float) + +`exponent`: the power to which the base is raised (float) + +[float] +=== Returns +The result of the exponentiation. (double) + +-- +// OVERVIEW SECTION ENDS + + + + +// HOW TO USE SECTION STARTS +[#howtouse] +-- + +[float] +=== Example Code +// Describe what the example code is all about and add relevant code ►►►►► THIS SECTION IS MANDATORY ◄◄◄◄◄ +See the (http://arduino.cc/playground/Main/Fscale[fscale]) function in the code library. +[%hardbreaks] + +[float] +=== See also +// Link relevant content by category, such as other Reference terms (please add the tag #LANGUAGE#), +// definitions (please add the tag #DEFINITION#), and examples of Projects and Tutorials +// (please add the tag #EXAMPLE#) ►►►►► THIS SECTION IS MANDATORY ◄◄◄◄◄ +[role="language"] +* #LANGUAGE# link:sqrt{ext-relative}[sqrt()] + +* #LANGUAGE# link:float{ext-relative}[float] + +* #LANGUAGE# link:double{ext-relative}[double] + +-- +// HOW TO USE SECTION ENDS diff --git a/Language/Functions/Math/sq.adoc b/Language/Functions/Math/sq.adoc new file mode 100644 index 000000000..f364f658b --- /dev/null +++ b/Language/Functions/Math/sq.adoc @@ -0,0 +1,53 @@ +:source-highlighter: pygments +:pygments-style: arduino +:ext-relative: adoc + + += sq(x) + + +// OVERVIEW SECTION STARTS +[#overview] +-- + +[float] +=== Description +Calculates the square of a number: the number multiplied by itself. +[%hardbreaks] + + +[float] +=== Syntax +`sq(x)` + + +[float] +=== Parameters +`x`: the number, any data type + +[float] +=== Returns +The square of the number. (double) + +-- +// OVERVIEW SECTION ENDS + + + + +// HOW TO USE SECTION STARTS +[#howtouse] +-- + +[float] +=== See also +// Link relevant content by category, such as other Reference terms (please add the tag #LANGUAGE#), +// definitions (please add the tag #DEFINITION#), and examples of Projects and Tutorials +// (please add the tag #EXAMPLE#) ►►►►► THIS SECTION IS MANDATORY ◄◄◄◄◄ + +[role="language"] +* #LANGUAGE# link:pow{ext-relative}[pow()] + +* #LANGUAGE# link:sqrt{ext-relative}[sqrt()] + +-- +// HOW TO USE SECTION ENDS diff --git a/Language/Functions/Math/sqrt.adoc b/Language/Functions/Math/sqrt.adoc new file mode 100644 index 000000000..206cbb410 --- /dev/null +++ b/Language/Functions/Math/sqrt.adoc @@ -0,0 +1,52 @@ +:source-highlighter: pygments +:pygments-style: arduino +:ext-relative: adoc + + += sqrt(x) + + +// OVERVIEW SECTION STARTS +Calculates the square root of a number. +[#overview] +-- + +[float] +=== Description +[%hardbreaks] + + +[float] +=== Syntax +`sqrt(x)` + + +[float] +=== Parameters +`x`: the number, any data type + +[float] +=== Returns +The number's square root. (double) + +-- +// OVERVIEW SECTION ENDS + + + + +// HOW TO USE SECTION STARTS +[#howtouse] +-- + +[float] +=== See also +// Link relevant content by category, such as other Reference terms (please add the tag #LANGUAGE#), +// definitions (please add the tag #DEFINITION#), and examples of Projects and Tutorials +// (please add the tag #EXAMPLE#) ►►►►► THIS SECTION IS MANDATORY ◄◄◄◄◄ +[role="language"] +* #LANGUAGE# link:pow{ext-relative}[pow()] + +* #LANGUAGE# link:sq{ext-relative}[sq()] + +-- +// HOW TO USE SECTION ENDS diff --git a/Language/Functions/Random Numbers/random.adoc b/Language/Functions/Random Numbers/random.adoc new file mode 100644 index 000000000..eb704a9f7 --- /dev/null +++ b/Language/Functions/Random Numbers/random.adoc @@ -0,0 +1,94 @@ +:source-highlighter: pygments +:pygments-style: arduino +:ext-relative: adoc + + += random() + + +// OVERVIEW SECTION STARTS +[#overview] +-- + +[float] +=== Description +The random function generates pseudo-random numbers. +[%hardbreaks] + + +[float] +=== Syntax +`random(max)` + +`random(min, max)` + + +[float] +=== Parameters +`min` - lower bound of the random value, inclusive (optional) + +`max` - upper bound of the random value, exclusive + +[float] +=== Returns +A random number between min and max-1 (`long`) . + +-- +// OVERVIEW SECTION ENDS + + + + +// HOW TO USE SECTION STARTS +[#howtouse] +-- + +[float] +=== Example Code +// Describe what the example code is all about and add relevant code ►►►►► THIS SECTION IS MANDATORY ◄◄◄◄◄ +The code generates random numbers and displays them. + +[source,arduino] +---- +long randNumber; + +void setup(){ + Serial.begin(9600); + + // if analog input pin 0 is unconnected, random analog + // noise will cause the call to randomSeed() to generate + // different seed numbers each time the sketch runs. + // randomSeed() will then shuffle the random function. + randomSeed(analogRead(0)); +} + +void loop() { + // print a random number from 0 to 299 + randNumber = random(300); + Serial.println(randNumber); + + // print a random number from 10 to 19 + randNumber = random(10, 20); + Serial.println(randNumber); + + delay(50); +} +---- +[%hardbreaks] + +[float] +=== Notes and Warnings +If it is important for a sequence of values generated by `random()` to differ, on subsequent executions of a sketch, use `randomSeed()` to initialize the random number generator with a fairly random input, such as `analogRead()` on an unconnected pin. + +Conversely, it can occasionally be useful to use pseudo-random sequences that repeat exactly. This can be accomplished by calling `randomSeed()` with a fixed number, before starting the random sequence. +[%hardbreaks] + +[float] +=== See also +// Link relevant content by category, such as other Reference terms (please add the tag #LANGUAGE#), +// definitions (please add the tag #DEFINITION#), and examples of Projects and Tutorials +// (please add the tag #EXAMPLE#) ►►►►► THIS SECTION IS MANDATORY ◄◄◄◄◄ +[role="language"] +* #LANGUAGE# link:randomSeed{ext-relative}[randomSeed()] + +-- +// HOW TO USE SECTION ENDS diff --git a/Language/Functions/Random Numbers/randomSeed.adoc b/Language/Functions/Random Numbers/randomSeed.adoc new file mode 100644 index 000000000..a69ab64bd --- /dev/null +++ b/Language/Functions/Random Numbers/randomSeed.adoc @@ -0,0 +1,77 @@ +:source-highlighter: pygments +:pygments-style: arduino +:ext-relative: adoc + + += randomSeed(seed) + + +// OVERVIEW SECTION STARTS +[#overview] +-- + +[float] +=== Description +`randomSeed()` initializes the pseudo-random number generator, causing it to start at an arbitrary point in its random sequence. This sequence, while very long, and random, is always the same. + +If it is important for a sequence of values generated by `random()` to differ, on subsequent executions of a sketch, use randomSeed() to initialize the random number generator with a fairly random input, such as `analogRead()` on an unconnected pin. + +Conversely, it can occasionally be useful to use pseudo-random sequences that repeat exactly. This can be accomplished by calling `randomSeed()` with a fixed number, before starting the random sequence. +[%hardbreaks] + + + + + +[float] +=== Parameters +`long`, `int` - pass a number to generate the seed. + +[float] +=== Returns +Nothing + +-- +// OVERVIEW SECTION ENDS + + + + +// HOW TO USE SECTION STARTS +[#howtouse] +-- + +[float] +=== Example Code +// Describe what the example code is all about and add relevant code ►►►►► THIS SECTION IS MANDATORY ◄◄◄◄◄ +The code explanation required. + +[source,arduino] +---- +long randNumber; + +void setup(){ + Serial.begin(9600); + randomSeed(analogRead(0)); +} + +void loop(){ + randNumber = random(300); + Serial.println(randNumber); + + delay(50); +} +---- +[%hardbreaks] + +[float] +=== See also +// Link relevant content by category, such as other Reference terms (please add the tag #LANGUAGE#), +// definitions (please add the tag #DEFINITION#), and examples of Projects and Tutorials +// (please add the tag #EXAMPLE#) ►►►►► THIS SECTION IS MANDATORY ◄◄◄◄◄ +[role="language" +* #LANGUAGE# link:random{ext-relative}[random] + + +-- +// HOW TO USE SECTION ENDS diff --git a/Language/Functions/Time/delay.adoc b/Language/Functions/Time/delay.adoc new file mode 100644 index 000000000..15a7934a8 --- /dev/null +++ b/Language/Functions/Time/delay.adoc @@ -0,0 +1,89 @@ +:source-highlighter: pygments +:pygments-style: arduino +:ext-relative: adoc + + += delay() + + +// OVERVIEW SECTION STARTS +[#overview] +-- + +[float] +=== Description +Pauses the program for the amount of time (in miliseconds) specified as parameter. (There are 1000 milliseconds in a second.) +[%hardbreaks] + + +[float] +=== Syntax +`delay(ms)` + + +[float] +=== Parameters +`ms`: the number of milliseconds to pause (`unsigned long`) + +[float] +=== Returns +Nothing + +-- +// OVERVIEW SECTION ENDS + + + + +// HOW TO USE SECTION STARTS +[#howtouse] +-- + +[float] +=== Example Code +// Describe what the example code is all about and add relevant code ►►►►► THIS SECTION IS MANDATORY ◄◄◄◄◄ +The code pauses the program for one second before toggling the output pin. + +[source,arduino] +---- +int ledPin = 13; // LED connected to digital pin 13 + +void setup() +{ + pinMode(ledPin, OUTPUT); // sets the digital pin as output +} + +void loop() +{ + digitalWrite(ledPin, HIGH); // sets the LED on + delay(1000); // waits for a second + digitalWrite(ledPin, LOW); // sets the LED off + delay(1000); // waits for a second +} +---- +[%hardbreaks] + +[float] +=== Notes and Warnings +While it is easy to create a blinking LED with the `delay()` function, and many sketches use short delays for such tasks as switch debouncing, the use of `delay()` in a sketch has significant drawbacks. No other reading of sensors, mathematical calculations, or pin manipulation can go on during the delay function, so in effect, it brings most other activity to a halt. For alternative approaches to controlling timing see the link:millis{ext-relative}[millis()] function and the sketch sited below. More knowledgeable programmers usually avoid the use of `delay()` for timing of events longer than 10's of milliseconds unless the Arduino sketch is very simple. + +Certain things do go on while the delay() function is controlling the Atmega chip however, because the delay function does not disable interrupts. Serial communication that appears at the RX pin is recorded, PWM (link:analogWrite{ext-relative}[analogWrite]) values and pin states are maintained, and link:attachInterrupt{ext-relative}[interrupts] will work as they should. +[%hardbreaks] + +[float] +=== See also +// Link relevant content by category, such as other Reference terms (please add the tag #LANGUAGE#), +// definitions (please add the tag #DEFINITIThis function works very accurately in the range 3 microseconds and up. We cannot assure that delayMicroseconds will perform precisely for smaller delay-times. + +As of Arduino 0018, delayMicroseconds() no longer disables interrupts. ON#), and examples of Projects and Tutorials +// (please add the tag #EXAMPLE#) ►►►►► THIS SECTION IS MANDATORY ◄◄◄◄◄ +[role="language"] +* #LANGUAGE# link:millis{ext-relative}[millis()] + +* #LANGUAGE# link:micros{ext-relative}[micros()] + +* #LANGUAGE# link:delayMicroseconds{ext-relative}[delayMicroseconds()] + +[role="example"] +* #EXAMPLE# http://arduino.cc/en/Tutorial/BlinkWithoutDelay[Blink Without Delay] + +-- +// HOW TO USE SECTION ENDS diff --git a/Language/Functions/Time/delayMicroseconds.adoc b/Language/Functions/Time/delayMicroseconds.adoc new file mode 100644 index 000000000..954430bc6 --- /dev/null +++ b/Language/Functions/Time/delayMicroseconds.adoc @@ -0,0 +1,86 @@ +:source-highlighter: pygments +:pygments-style: arduino +:ext-relative: adoc + + += delayMicroseconds() + + +// OVERVIEW SECTION STARTS +[#overview] +-- + +[float] +=== Description +Pauses the program for the amount of time (in microseconds) specified as parameter. There are a thousand microseconds in a millisecond, and a million microseconds in a second. + +Currently, the largest value that will produce an accurate delay is 16383. This could change in future Arduino releases. For delays longer than a few thousand microseconds, you should use `delay()` instead. +[%hardbreaks] + + +[float] +=== Syntax +`delayMicroseconds(us)` + + +[float] +=== Parameters +`us`: the number of microseconds to pause (`unsigned int`) + +[float] +=== Returns +Nothing + +-- +// OVERVIEW SECTION ENDS + + + + +// HOW TO USE SECTION STARTS +[#howtouse] +-- + +[float] +=== Example Code +// Describe what the example code is all about and add relevant code ►►►►► THIS SECTION IS MANDATORY ◄◄◄◄◄ +The code configures pin number 8 to work as an output pin. It sends a train of pulses with 100 microseconds period. + +[source,arduino] +---- +int outPin = 8; // digital pin 8 + +void setup() +{ + pinMode(outPin, OUTPUT); // sets the digital pin as output +} + +void loop() +{ + digitalWrite(outPin, HIGH); // sets the pin on + delayMicroseconds(50); // pauses for 50 microseconds + digitalWrite(outPin, LOW); // sets the pin off + delayMicroseconds(50); // pauses for 50 microseconds +} +---- +[%hardbreaks] + +[float] +=== Notes and Warnings +This function works very accurately in the range 3 microseconds and up. We cannot assure that delayMicroseconds will perform precisely for smaller delay-times. + +As of Arduino 0018, delayMicroseconds() no longer disables interrupts. +[%hardbreaks] + +[float] +=== See also +// Link relevant content by category, such as other Reference terms (please add the tag #LANGUAGE#), +// definitions (please add the tag #DEFINITION#), and examples of Projects and Tutorials +// (please add the tag #EXAMPLE#) ►►►►► THIS SECTION IS MANDATORY ◄◄◄◄◄ +[role="language"] +* #LANGUAGE# link:millis{ext-relative}[millis()] + +* #LANGUAGE# link:micros{ext-relative}[micros()] + +* #LANGUAGE# link:delay{ext-relative}[delay()] + +-- +// HOW TO USE SECTION ENDS diff --git a/Language/Functions/Time/micros.adoc b/Language/Functions/Time/micros.adoc new file mode 100644 index 000000000..e345d89f7 --- /dev/null +++ b/Language/Functions/Time/micros.adoc @@ -0,0 +1,79 @@ +:source-highlighter: pygments +:pygments-style: arduino +:ext-relative: adoc + + += micros() + + +// OVERVIEW SECTION STARTS +[#overview] +-- + +[float] +=== Description +Returns the number of microseconds since the Arduino board began running the current program. This number will overflow (go back to zero), after approximately 70 minutes. On 16 MHz Arduino boards (e.g. Duemilanove and Nano), this function has a resolution of four microseconds (i.e. the value returned is always a multiple of four). On 8 MHz Arduino boards (e.g. the LilyPad), this function has a resolution of eight microseconds. +[%hardbreaks] + + +[float] +=== Syntax +`time = micros()` + + +[float] +=== Parameters +Nothing + +[float] +=== Returns +Nothing + +-- +// OVERVIEW SECTION ENDS + + + + +// HOW TO USE SECTION STARTS +[#howtouse] +-- + +[float] +=== Example Code +// Describe what the example code is all about and add relevant code ►►►►► THIS SECTION IS MANDATORY ◄◄◄◄◄ +The code returns the number of microseconds since the Arduino board began. + +[source,arduino] +---- +unsigned long time; + +void setup(){ + Serial.begin(9600); +} +void loop(){ + Serial.print("Time: "); + time = micros(); + + Serial.println(time); //prints time since program started + delay(1000); // wait a second so as not to send massive amounts of data +} +---- +[%hardbreaks] + +[float] +=== Notes and Warnings +There are 1,000 microseconds in a millisecond and 1,000,000 microseconds in a second. +[%hardbreaks] + +[float] +=== See also +// Link relevant content by category, such as other Reference terms (please add the tag #LANGUAGE#), +// definitions (please add the tag #DEFINITION#), and examples of Projects and Tutorials +// (please add the tag #EXAMPLE#) ►►►►► THIS SECTION IS MANDATORY ◄◄◄◄◄ +[role="language"] +* #LANGUAGE# link:millis{ext-relative}[millis()] + +* #LANGUAGE# link:delay{ext-relative}[delay()] + +* #LANGUAGE# link:delayMicroseconds{ext-relative}[delayMicroseconds()] +-- +// HOW TO USE SECTION ENDS diff --git a/Language/Functions/Time/millis.adoc b/Language/Functions/Time/millis.adoc new file mode 100644 index 000000000..72e98eed7 --- /dev/null +++ b/Language/Functions/Time/millis.adoc @@ -0,0 +1,83 @@ +:source-highlighter: pygments +:pygments-style: arduino +:ext-relative: adoc + + += millis() + + +// OVERVIEW SECTION STARTS +[#overview] +-- + +[float] +=== Description +Returns the number of milliseconds since the Arduino board began running the current program. This number will overflow (go back to zero), after approximately 50 days. +[%hardbreaks] + + +[float] +=== Syntax +`time = millis()` + + +[float] +=== Parameters +Nothing + +[float] +=== Returns +Number of milliseconds since the program started (unsigned long) + +-- +// OVERVIEW SECTION ENDS + + + + +// HOW TO USE SECTION STARTS +[#howtouse] +-- + +[float] +=== Example Code +// Describe what the example code is all about and add relevant code ►►►►► THIS SECTION IS MANDATORY ◄◄◄◄◄ +The code reads the milllisecond since the Arduino board bagan. + +[source,arduino] +---- +unsigned long time; + +void setup(){ + Serial.begin(9600); +} +void loop(){ + Serial.print("Time: "); + time = millis(); + + Serial.println(time); //prints time since program started + delay(1000); // wait a second so as not to send massive amounts of data +} +---- +[%hardbreaks] + +[float] +=== Notes and Warnings +Note that the parameter for millis is an unsigned long, errors may be generated if a programmer tries to do math with other datatypes such as ints. +[%hardbreaks] + +[float] +=== See also +// Link relevant content by category, such as other Reference terms (please add the tag #LANGUAGE#), +// definitions (please add the tag #DEFINITION#), and examples of Projects and Tutorials +// (please add the tag #EXAMPLE#) ►►►►► THIS SECTION IS MANDATORY ◄◄◄◄◄ +[role="language"] +* #LANGUAGE# link:micros{ext-relative}[micros()] + +* #LANGUAGE# link:delay{ext-relative}[delay()] + +* #LANGUAGE# link:delayMicroseconds{ext-relative}[delayMicrosecond()] + +[role="example"] +* #EXAMPLE# http://arduino.cc/en/Tutorial/BlinkWithoutDelay[Blink Without Delay] + +-- +// HOW TO USE SECTION ENDS diff --git a/Language/Functions/Trigonometry/cos.adoc b/Language/Functions/Trigonometry/cos.adoc new file mode 100644 index 000000000..898e48801 --- /dev/null +++ b/Language/Functions/Trigonometry/cos.adoc @@ -0,0 +1,53 @@ +:source-highlighter: pygments +:pygments-style: arduino +:ext-relative: adoc + + += cos(rad) + + +// OVERVIEW SECTION STARTS +[#overview] +-- + +[float] +=== Description +Calculates the cos of an angle (in radians). The result will be between -1 and 1. +[%hardbreaks] + + +[float] +=== Syntax +`cos(rad)` + + +[float] +=== Parameters +`rad`: The angle in Radians (float). + +[float] +=== Returns +The cos of the angle (`double`). + +-- +// OVERVIEW SECTION ENDS + + + + +// HOW TO USE SECTION STARTS +[#howtouse] +-- + +[float] +=== See also +// Link relevant content by category, such as other Reference terms (please add the tag #LANGUAGE#), +// definitions (please add the tag #DEFINITION#), and examples of Projects and Tutorials +// (please add the tag #EXAMPLE#) ►►►►► THIS SECTION IS MANDATORY ◄◄◄◄◄ +[role="language"] +* #LANGUAGE# link:sin{ext-relative}[sin()] + +* #LANGUAGE# link:tan{ext-relative}[tan()] + +* #LANGUAGE# link:float{ext-relative}[float] + +* #LANGUAGE# link:double{ext-relative}[double] +-- +// HOW TO USE SECTION ENDS diff --git a/Language/Functions/Trigonometry/sin.adoc b/Language/Functions/Trigonometry/sin.adoc new file mode 100644 index 000000000..781b9114d --- /dev/null +++ b/Language/Functions/Trigonometry/sin.adoc @@ -0,0 +1,53 @@ +:source-highlighter: pygments +:pygments-style: arduino +:ext-relative: adoc + + += sin(rad) + + +// OVERVIEW SECTION STARTS +[#overview] +-- + +[float] +=== Description +Calculates the sine of an angle (in radians). The result will be between -1 and 1. +[%hardbreaks] + + +[float] +=== Syntax +`sin(rad)` + + +[float] +=== Parameters +`rad`: The angle in Radians (`float`). + +[float] +=== Returns +The sine of the angle (`double`). + +-- +// OVERVIEW SECTION ENDS + + + + +// HOW TO USE SECTION STARTS +[#howtouse] +-- + +[float] +=== See also +// Link relevant content by category, such as other Reference terms (please add the tag #LANGUAGE#), +// definitions (please add the tag #DEFINITION#), and examples of Projects and Tutorials +// (please add the tag #EXAMPLE#) ►►►►► THIS SECTION IS MANDATORY ◄◄◄◄◄ +[role="language"] +* #LANGUAGE# link:cos{ext-relative}[cos()] + +* #LANGUAGE# link:tan{ext-relative}[tan()] + +* #LANGUAGE# link:float{ext-relative}[float] + +* #LANGUAGE# link:double{ext-relative}[double] +-- +// HOW TO USE SECTION ENDS diff --git a/Language/Functions/Trigonometry/tan.adoc b/Language/Functions/Trigonometry/tan.adoc new file mode 100644 index 000000000..c8b1286b3 --- /dev/null +++ b/Language/Functions/Trigonometry/tan.adoc @@ -0,0 +1,53 @@ +:source-highlighter: pygments +:pygments-style: arduino +:ext-relative: adoc + + += tan(rad) + + +// OVERVIEW SECTION STARTS +[#overview] +-- + +[float] +=== Description +Calculates the tangent of an angle (in radians). The result will be between negative infinity and infinity. +[%hardbreaks] + + +[float] +=== Syntax +`tan(rad)` + + +[float] +=== Parameters +`rad`: The angle in Radians (`float`). + +[float] +=== Returns +The tangent of the angle (`double`). + +-- +// OVERVIEW SECTION ENDS + + + + +// HOW TO USE SECTION STARTS +[#howtouse] +-- + +[float] +=== See also +// Link relevant content by category, such as other Reference terms (please add the tag #LANGUAGE#), +// definitions (please add the tag #DEFINITION#), and examples of Projects and Tutorials +// (please add the tag #EXAMPLE#) ►►►►► THIS SECTION IS MANDATORY ◄◄◄◄◄ +[role="language"] +* #LANGUAGE# link:sin{ext-relative}[sin()] + +* #LANGUAGE# link:cos{ext-relative}[cos()] + +* #LANGUAGE# link:float{ext-relative}[float] + +* #LANGUAGE# link:double{ext-relative}[double] +-- +// HOW TO USE SECTION ENDS diff --git a/Language/Functions/USB (Leonardo and DUE only)/Keyboard/keyboardBegin.adoc b/Language/Functions/USB (Leonardo and DUE only)/Keyboard/keyboardBegin.adoc new file mode 100644 index 000000000..4bfae2deb --- /dev/null +++ b/Language/Functions/USB (Leonardo and DUE only)/Keyboard/keyboardBegin.adoc @@ -0,0 +1,84 @@ +:source-highlighter: pygments +:pygments-style: arduino +:ext-relative: adoc + + += Keyboard.begin() + + +// OVERVIEW SECTION STARTS +[#overview] +-- + +[float] +=== Description +When used with a Leonardo or Due board, `Keyboard.begin()` starts emulating a keyboard connected to a computer. To end control, use link:keyboardEnd{ext-relative}[Keyboard.end()]. +[%hardbreaks] + + +[float] +=== Syntax +`Keyboard.begin()` + + +[float] +=== Parameters +Nothing + +[float] +=== Returns +Nothing + +-- +// OVERVIEW SECTION ENDS + + + + +// HOW TO USE SECTION STARTS +[#howtouse] +-- + +[float] +=== Example Code +// Describe what the example code is all about and add relevant code ►►►►► THIS SECTION IS MANDATORY ◄◄◄◄◄ + + +[source,arduino] +---- +void setup() { + // make pin 2 an input and turn on the + // pullup resistor so it goes high unless + // connected to ground: + pinMode(2, INPUT_PULLUP); + Keyboard.begin(); +} + +void loop() { + //if the button is pressed + if(digitalRead(2)==LOW){ + //Send the message + Keyboard.print("Hello!"); + } +} +---- +[%hardbreaks] + + + +[float] +=== See also +// Link relevant content by category, such as other Reference terms (please add the tag #LANGUAGE#), +// definitions (please add the tag #DEFINITION#), and examples of Projects and Tutorials +// (please add the tag #EXAMPLE#) ►►►►► THIS SECTION IS MANDATORY ◄◄◄◄◄ + +[role="language"] +* #LANGUAGE# link:keyboardEnd{ext-relative}[keyboard.end] + +* #LANGUAGE# link:keyboardPress{ext-relative}[keyboard.press] + +* #LANGUAGE# link:keyboardPrint{ext-relative}[keyboard.print] + +* #LANGUAGE# link:keyboardPrintln{ext-relative}[keyboard.println] + +* #LANGUAGE# link:keyboardRelease{ext-relative}[keyboard.release] + +* #LANGUAGE# link:keyboardReleaseAll{ext-relative}[keyboard.releaseAll] + +* #LANGUAGE# link:keyboardWrite{ext-relative}[keyboard.write] + +-- +// HOW TO USE SECTION ENDS diff --git a/Language/Functions/USB (Leonardo and DUE only)/Keyboard/keyboardEnd.adoc b/Language/Functions/USB (Leonardo and DUE only)/Keyboard/keyboardEnd.adoc new file mode 100644 index 000000000..a36b92a71 --- /dev/null +++ b/Language/Functions/USB (Leonardo and DUE only)/Keyboard/keyboardEnd.adoc @@ -0,0 +1,81 @@ +:source-highlighter: pygments +:pygments-style: arduino +:ext-relative: adoc + + += Keyboard.end() + + +// OVERVIEW SECTION STARTS +[#overview] +-- + +[float] +=== Description +Stops the keyboard emulation to a connected computer. To start keyboard emulation, use link:keyboardBegin{ext-relative}[Keyboard.begin()]. +[%hardbreaks] + + +[float] +=== Syntax +`Keyboard.end()` + + +[float] +=== Parameters +Nothing + +[float] +=== Returns +Nothing + +-- +// OVERVIEW SECTION ENDS + + + + +// HOW TO USE SECTION STARTS +[#howtouse] +-- + +[float] +=== Example Code +// Describe what the example code is all about and add relevant code ►►►►► THIS SECTION IS MANDATORY ◄◄◄◄◄ + + +[source,arduino] +---- +void setup() { + //start keyboard communication + Keyboard.begin(); + //send a keystroke + Keyboard.print("Hello!"); + //end keyboard communication + Keyboard.end(); +} + +void loop() { + //do nothing +} +---- +[%hardbreaks] + + + +[float] +=== See also +// Link relevant content by category, such as other Reference terms (please add the tag #LANGUAGE#), +// definitions (please add the tag #DEFINITION#), and examples of Projects and Tutorials +// (please add the tag #EXAMPLE#) ►►►►► THIS SECTION IS MANDATORY ◄◄◄◄◄ + +[role="language"] +* #LANGUAGE# link:keyboardEnd{ext-relative}[keyboard.end] + +* #LANGUAGE# link:keyboardPress{ext-relative}[keyboard.press] + +* #LANGUAGE# link:keyboardPrint{ext-relative}[keyboard.print] + +* #LANGUAGE# link:keyboardPrintln{ext-relative}[keyboard.println] + +* #LANGUAGE# link:keyboardRelease{ext-relative}[keyboard.release] + +* #LANGUAGE# link:keyboardReleaseAll{ext-relative}[keyboard.releaseAll] + +* #LANGUAGE# link:keyboardWrite{ext-relative}[keyboard.write] + +-- +// HOW TO USE SECTION ENDS diff --git a/Language/Functions/USB (Leonardo and DUE only)/Keyboard/keyboardPress.adoc b/Language/Functions/USB (Leonardo and DUE only)/Keyboard/keyboardPress.adoc new file mode 100644 index 000000000..c1183f52f --- /dev/null +++ b/Language/Functions/USB (Leonardo and DUE only)/Keyboard/keyboardPress.adoc @@ -0,0 +1,98 @@ +:source-highlighter: pygments +:pygments-style: arduino +:ext-relative: adoc + + += Keyboard.press() + + +// OVERVIEW SECTION STARTS +[#overview] +-- + +[float] +=== Description +When called, `Keyboard.press()` functions as if a key were pressed and held on your keyboard. Useful when using link:keyboardModifier{ext-relative}[modifier keys]. To end the key press, use link:keyboardRelease{ext-relative}[Keyboard.release()] or link:keyboardReleaseAll{ext-relative}[Keyboard.releaseAll()]. + +It is necessary to call link:keyboardBegin{ext-relative}[Keyboard.begin()] before using `press()`. +[%hardbreaks] + + +[float] +=== Syntax +`Keyboard.press()` + + +[float] +=== Parameters +`char` : the key to press + +[float] +=== Returns +Nothing + +-- +// OVERVIEW SECTION ENDS + + + + +// HOW TO USE SECTION STARTS +[#howtouse] +-- + +[float] +=== Example Code +// Describe what the example code is all about and add relevant code ►►►►► THIS SECTION IS MANDATORY ◄◄◄◄◄ + + +[source,arduino] +---- +// use this option for OSX: +char ctrlKey = KEY_LEFT_GUI; +// use this option for Windows and Linux: +// char ctrlKey = KEY_LEFT_CTRL; + +void setup() { + // make pin 2 an input and turn on the + // pullup resistor so it goes high unless + // connected to ground: + pinMode(2, INPUT_PULLUP); + // initialize control over the keyboard: + Keyboard.begin(); +} + +void loop() { + while (digitalRead(2) == HIGH) { + // do nothing until pin 2 goes low + delay(500); + } + delay(1000); + // new document: + Keyboard.press(ctrlKey); + Keyboard.press('n'); + delay(100); + Keyboard.releaseAll(); + // wait for new window to open: + delay(1000); +---- +[%hardbreaks] + + + +[float] +=== See also +// Link relevant content by category, such as other Reference terms (please add the tag #LANGUAGE#), +// definitions (please add the tag #DEFINITION#), and examples of Projects and Tutorials +// (please add the tag #EXAMPLE#) ►►►►► THIS SECTION IS MANDATORY ◄◄◄◄◄ + +[role="language"] +* #LANGUAGE# link:keyboardEnd{ext-relative}[keyboard.end] + +* #LANGUAGE# link:keyboardPress{ext-relative}[keyboard.press] + +* #LANGUAGE# link:keyboardPrint{ext-relative}[keyboard.print] + +* #LANGUAGE# link:keyboardPrintln{ext-relative}[keyboard.println] + +* #LANGUAGE# link:keyboardRelease{ext-relative}[keyboard.release] + +* #LANGUAGE# link:keyboardReleaseAll{ext-relative}[keyboard.releaseAll] + +* #LANGUAGE# link:keyboardWrite{ext-relative}[keyboard.write] + +-- +// HOW TO USE SECTION ENDS diff --git a/Language/Functions/USB (Leonardo and DUE only)/Keyboard/keyboardPrint.adoc b/Language/Functions/USB (Leonardo and DUE only)/Keyboard/keyboardPrint.adoc new file mode 100644 index 000000000..afc562a3c --- /dev/null +++ b/Language/Functions/USB (Leonardo and DUE only)/Keyboard/keyboardPrint.adoc @@ -0,0 +1,90 @@ +:source-highlighter: pygments +:pygments-style: arduino +:ext-relative: adoc + + += Keyboard.print() + + +// OVERVIEW SECTION STARTS +[#overview] +-- + +[float] +=== Description +Sends a keystroke to a connected computer. + +`Keyboard.print()` must be called after initiating link:keyboardBegin{ext-relative}[Keyboard.begin()]. +[%hardbreaks] + + +[float] +=== Syntax +`Keyboard.print(character)` + +`Keyboard.print(characters)` + +[float] +=== Parameters +`character` : a char or int to be sent to the computer as a keystroke characters : a string to be sent to the computer as a keystroke. + +[float] +=== Returns +`int` : number of bytes sent. + +-- +// OVERVIEW SECTION ENDS + + + + +// HOW TO USE SECTION STARTS +[#howtouse] +-- + +[float] +=== Example Code +// Describe what the example code is all about and add relevant code ►►►►► THIS SECTION IS MANDATORY ◄◄◄◄◄ + + +[source,arduino] +---- +void setup() { + // make pin 2 an input and turn on the + // pullup resistor so it goes high unless + // connected to ground: + pinMode(2, INPUT_PULLUP); + Keyboard.begin(); +} + +void loop() { + //if the button is pressed + if(digitalRead(2)==LOW){ + //Send the message + Keyboard.print("Hello!"); + } +} +---- +[%hardbreaks] + +[float] +=== Notes and Warnings +When you use the `Keyboard.print()` command, the Arduino takes over your keyboard! Make sure you have control before you use the command. A pushbutton to toggle the keyboard control state is effective. +[%hardbreaks] + + +[float] +=== See also +// Link relevant content by category, such as other Reference terms (please add the tag #LANGUAGE#), +// definitions (please add the tag #DEFINITION#), and examples of Projects and Tutorials +// (please add the tag #EXAMPLE#) ►►►►► THIS SECTION IS MANDATORY ◄◄◄◄◄ + +[role="language"] +* #LANGUAGE# link:keyboardEnd{ext-relative}[keyboard.end] + +* #LANGUAGE# link:keyboardPress{ext-relative}[keyboard.press] + +* #LANGUAGE# link:keyboardPrint{ext-relative}[keyboard.print] + +* #LANGUAGE# link:keyboardPrintln{ext-relative}[keyboard.println] + +* #LANGUAGE# link:keyboardRelease{ext-relative}[keyboard.release] + +* #LANGUAGE# link:keyboardReleaseAll{ext-relative}[keyboard.releaseAll] + +* #LANGUAGE# link:keyboardWrite{ext-relative}[keyboard.write] + +-- +// HOW TO USE SECTION ENDS diff --git a/Language/Functions/USB (Leonardo and DUE only)/Keyboard/keyboardPrintln.adoc b/Language/Functions/USB (Leonardo and DUE only)/Keyboard/keyboardPrintln.adoc new file mode 100644 index 000000000..64c893240 --- /dev/null +++ b/Language/Functions/USB (Leonardo and DUE only)/Keyboard/keyboardPrintln.adoc @@ -0,0 +1,90 @@ +:source-highlighter: pygments +:pygments-style: arduino +:ext-relative: adoc + + += Keyboard.println() + + +// OVERVIEW SECTION STARTS +[#overview] +-- + +[float] +=== Description +Sends a keystroke to a connected computer, followed by a newline and carriage return. + +`Keyboard.println()` must be called after initiating link:keyboardBegin{ext-relative}[Keyboard.begin()]. +[%hardbreaks] + + +[float] +=== Syntax +`Keyboard.println()` + +`Keyboard.println(character)`+ +`Keyboard.println(characters)` + +[float] +=== Parameters +`character` : a char or int to be sent to the computer as a keystroke, followed by newline and carriage return. + +`characters` : a string to be sent to the computer as a keystroke, followed by a newline and carriage return. + +[float] +=== Returns +`int` : number of bytes sent + +-- +// OVERVIEW SECTION ENDS + + +// HOW TO USE SECTION STARTS +[#howtouse] +-- + +[float] +=== Example Code +// Describe what the example code is all about and add relevant code ►►►►► THIS SECTION IS MANDATORY ◄◄◄◄◄ + + +[source,arduino] +---- +void setup() { + // make pin 2 an input and turn on the + // pullup resistor so it goes high unless + // connected to ground: + pinMode(2, INPUT_PULLUP); + Keyboard.begin(); +} + +void loop() { + //if the button is pressed + if(digitalRead(2)==LOW){ + //Send the message + Keyboard.println("Hello!"); + } +} +---- +[%hardbreaks] + +[float] +=== Notes and Warnings +When you use the Keyboard.println() command, the Arduino takes over your keyboard! Make sure you have control before you use the command. A pushbutton to toggle the keyboard control state is effective. +[%hardbreaks] + +[float] +=== See also +// Link relevant content by category, such as other Reference terms (please add the tag #LANGUAGE#), +// definitions (please add the tag #DEFINITION#), and examples of Projects and Tutorials +// (please add the tag #EXAMPLE#) ►►►►► THIS SECTION IS MANDATORY ◄◄◄◄◄ + +[role="language"] +* #LANGUAGE# link:keyboardEnd{ext-relative}[keyboard.end] + +* #LANGUAGE# link:keyboardPress{ext-relative}[keyboard.press] + +* #LANGUAGE# link:keyboardPrint{ext-relative}[keyboard.print] + +* #LANGUAGE# link:keyboardPrintln{ext-relative}[keyboard.println] + +* #LANGUAGE# link:keyboardRelease{ext-relative}[keyboard.release] + +* #LANGUAGE# link:keyboardReleaseAll{ext-relative}[keyboard.releaseAll] + +* #LANGUAGE# link:keyboardWrite{ext-relative}[keyboard.write] + +-- +// HOW TO USE SECTION ENDS diff --git a/Language/Functions/USB (Leonardo and DUE only)/Keyboard/keyboardRelease.adoc b/Language/Functions/USB (Leonardo and DUE only)/Keyboard/keyboardRelease.adoc new file mode 100644 index 000000000..dd5253184 --- /dev/null +++ b/Language/Functions/USB (Leonardo and DUE only)/Keyboard/keyboardRelease.adoc @@ -0,0 +1,98 @@ +:source-highlighter: pygments +:pygments-style: arduino +:ext-relative: adoc + + += Keyboard.release() + + +// OVERVIEW SECTION STARTS +[#overview] +-- + +[float] +=== Description +Lets go of the specified key. See link:keyboardPress{ext-relative}[Keyboard.press()] for more information. +[%hardbreaks] + + +[float] +=== Syntax +`Keyboard.release(key)` + + +[float] +=== Parameters +`key` : the key to release. `char` + +[float] +=== Returns +`int` : the number of keys released + +-- +// OVERVIEW SECTION ENDS + + + + +// HOW TO USE SECTION STARTS +[#howtouse] +-- + +[float] +=== Example Code +// Describe what the example code is all about and add relevant code ►►►►► THIS SECTION IS MANDATORY ◄◄◄◄◄ + + +[source,arduino] +---- +// use this option for OSX: +char ctrlKey = KEY_LEFT_GUI; +// use this option for Windows and Linux: +// char ctrlKey = KEY_LEFT_CTRL; + +void setup() { + // make pin 2 an input and turn on the + // pullup resistor so it goes high unless + // connected to ground: + pinMode(2, INPUT_PULLUP); + // initialize control over the keyboard: + Keyboard.begin(); +} + +void loop() { + while (digitalRead(2) == HIGH) { + // do nothing until pin 2 goes low + delay(500); + } + delay(1000); + // new document: + Keyboard.press(ctrlKey); + Keyboard.press('n'); + delay(100); + Keyboard.release(ctrlKey); + Keyboard.release('n'); + // wait for new window to open: + delay(1000); +} +---- +[%hardbreaks] + + + +[float] +=== See also +// Link relevant content by category, such as other Reference terms (please add the tag #LANGUAGE#), +// definitions (please add the tag #DEFINITION#), and examples of Projects and Tutorials +// (please add the tag #EXAMPLE#) ►►►►► THIS SECTION IS MANDATORY ◄◄◄◄◄ + +[role="language"] +* #LANGUAGE# link:keyboardEnd{ext-relative}[keyboard.end] + +* #LANGUAGE# link:keyboardPress{ext-relative}[keyboard.press] + +* #LANGUAGE# link:keyboardPrint{ext-relative}[keyboard.print] + +* #LANGUAGE# link:keyboardPrintln{ext-relative}[keyboard.println] + +* #LANGUAGE# link:keyboardRelease{ext-relative}[keyboard.release] + +* #LANGUAGE# link:keyboardReleaseAll{ext-relative}[keyboard.releaseAll] + +* #LANGUAGE# link:keyboardWrite{ext-relative}[keyboard.write] + +-- +// HOW TO USE SECTION ENDS diff --git a/Language/Functions/USB (Leonardo and DUE only)/Keyboard/keyboardReleaseAll.adoc b/Language/Functions/USB (Leonardo and DUE only)/Keyboard/keyboardReleaseAll.adoc new file mode 100644 index 000000000..b868dfd23 --- /dev/null +++ b/Language/Functions/USB (Leonardo and DUE only)/Keyboard/keyboardReleaseAll.adoc @@ -0,0 +1,97 @@ +:source-highlighter: pygments +:pygments-style: arduino +:ext-relative: adoc + + += Keyboard.releaseAll() + + +// OVERVIEW SECTION STARTS +[#overview] +-- + +[float] +=== Description +Lets go of all keys currently pressed. See link:keyboardPress{ext-relative}[Keyboard.press()] for additional information. +[%hardbreaks] + + +[float] +=== Syntax +`Keyboard.releaseAll()` + + +[float] +=== Parameters +Nothing + +[float] +=== Returns +`int` : the number of keys released + +-- +// OVERVIEW SECTION ENDS + + + + +// HOW TO USE SECTION STARTS +[#howtouse] +-- + +[float] +=== Example Code +// Describe what the example code is all about and add relevant code ►►►►► THIS SECTION IS MANDATORY ◄◄◄◄◄ + + +[source,arduino] +---- +// use this option for OSX: +char ctrlKey = KEY_LEFT_GUI; +// use this option for Windows and Linux: +// char ctrlKey = KEY_LEFT_CTRL; + +void setup() { + // make pin 2 an input and turn on the + // pullup resistor so it goes high unless + // connected to ground: + pinMode(2, INPUT_PULLUP); + // initialize control over the keyboard: + Keyboard.begin(); +} + +void loop() { + while (digitalRead(2) == HIGH) { + // do nothing until pin 2 goes low + delay(500); + } + delay(1000); + // new document: + Keyboard.press(ctrlKey); + Keyboard.press('n'); + delay(100); + Keyboard.releaseAll(); + // wait for new window to open: + delay(1000); +} +---- +[%hardbreaks] + + + +[float] +=== See also +// Link relevant content by category, such as other Reference terms (please add the tag #LANGUAGE#), +// definitions (please add the tag #DEFINITION#), and examples of Projects and Tutorials +// (please add the tag #EXAMPLE#) ►►►►► THIS SECTION IS MANDATORY ◄◄◄◄◄ + +[role="language"] +* #LANGUAGE# link:keyboardEnd{ext-relative}[keyboard.end] + +* #LANGUAGE# link:keyboardPress{ext-relative}[keyboard.press] + +* #LANGUAGE# link:keyboardPrint{ext-relative}[keyboard.print] + +* #LANGUAGE# link:keyboardPrintln{ext-relative}[keyboard.println] + +* #LANGUAGE# link:keyboardRelease{ext-relative}[keyboard.release] + +* #LANGUAGE# link:keyboardReleaseAll{ext-relative}[keyboard.releaseAll] + +* #LANGUAGE# link:keyboardWrite{ext-relative}[keyboard.write] + +-- +// HOW TO USE SECTION ENDS diff --git a/Language/Functions/USB (Leonardo and DUE only)/Keyboard/keyboardWrite.adoc b/Language/Functions/USB (Leonardo and DUE only)/Keyboard/keyboardWrite.adoc new file mode 100644 index 000000000..05648b30c --- /dev/null +++ b/Language/Functions/USB (Leonardo and DUE only)/Keyboard/keyboardWrite.adoc @@ -0,0 +1,98 @@ +:source-highlighter: pygments +:pygments-style: arduino +:ext-relative: adoc + + += Keyboard.write() + + +// OVERVIEW SECTION STARTS +[#overview] +-- + +[float] +=== Description +Sends a keystroke to a connected computer. This is similar to pressing and releasing a key on your keyboard. You can send some ASCII characters or the additional link:keyboardModifiers{ext-relative}[keyboard modifiers and special keys]. + +Only ASCII characters that are on the keyboard are supported. For example, ASCII 8 (backspace) would work, but ASCII 25 (Substitution) would not. When sending capital letters, Keyboard.write() sends a shift command plus the desired character, just as if typing on a keyboard. If sending a numeric type, it sends it as an ASCII character (ex. Keyboard.write(97) will send 'a'). + +For a complete list of ASCII characters, see http://www.asciitable.com/[ASCIITable.com]. +[%hardbreaks] + + +[float] +=== Syntax +`Keyboard.write(character)` + + +[float] +=== Parameters +`character` : a char or int to be sent to the computer. Can be sent in any notation that's acceptable for a char. For example, all of the below are acceptable and send the same value, 65 or ASCII A: +[source,arduino] +---- +Keyboard.write(65); // sends ASCII value 65, or A +Keyboard.write('A'); // same thing as a quoted character +Keyboard.write(0x41); // same thing in hexadecimal +Keyboard.write(0b01000001); // same thing in binary (weird choice, but it works) +---- + +[float] +=== Returns +`int` : number of bytes sent. + +-- +// OVERVIEW SECTION ENDS + + + + +// HOW TO USE SECTION STARTS +[#howtouse] +-- + +[float] +=== Example Code +// Describe what the example code is all about and add relevant code ►►►►► THIS SECTION IS MANDATORY ◄◄◄◄◄ + + +[source,arduino] +---- +void setup() { + // make pin 2 an input and turn on the + // pullup resistor so it goes high unless + // connected to ground: + pinMode(2, INPUT_PULLUP); + Keyboard.begin(); +} + +void loop() { + //if the button is pressed + if(digitalRead(2)==LOW){ + //Send an ASCII 'A', + Keyboard.write(65); + } +} +---- +[%hardbreaks] + +[float] +=== Notes and Warnings +When you use the Keyboard.write() command, the Arduino takes over your keyboard! Make sure you have control before you use the command. A pushbutton to toggle the keyboard control state is effective. +[%hardbreaks] + +[float] +=== See also +// Link relevant content by category, such as other Reference terms (please add the tag #LANGUAGE#), +// definitions (please add the tag #DEFINITION#), and examples of Projects and Tutorials +// (please add the tag #EXAMPLE#) ►►►►► THIS SECTION IS MANDATORY ◄◄◄◄◄ + +[role="language"] +* #LANGUAGE# link:keyboardEnd{ext-relative}[keyboard.end] + +* #LANGUAGE# link:keyboardPress{ext-relative}[keyboard.press] + +* #LANGUAGE# link:keyboardPrint{ext-relative}[keyboard.print] + +* #LANGUAGE# link:keyboardPrintln{ext-relative}[keyboard.println] + +* #LANGUAGE# link:keyboardRelease{ext-relative}[keyboard.release] + +* #LANGUAGE# link:keyboardReleaseAll{ext-relative}[keyboard.releaseAll] + +* #LANGUAGE# link:keyboardWrite{ext-relative}[keyboard.write] + +-- +// HOW TO USE SECTION ENDS diff --git a/Language/Functions/USB (Leonardo and DUE only)/Mouse/mouseBegin.adoc b/Language/Functions/USB (Leonardo and DUE only)/Mouse/mouseBegin.adoc new file mode 100644 index 000000000..644bf18c4 --- /dev/null +++ b/Language/Functions/USB (Leonardo and DUE only)/Mouse/mouseBegin.adoc @@ -0,0 +1,78 @@ +:source-highlighter: pygments +:pygments-style: arduino +:ext-relative: adoc + + += Mouse.begin() + + +// OVERVIEW SECTION STARTS +[#overview] +-- + +[float] +=== Description +Begins emulating the mouse connected to a computer. `begin()` must be called before controlling the computer. To end control, use link:mouseEnd{ext-relative}[Mouse.end()]. +[%hardbreaks] + + +[float] +=== Syntax +`Mouse.begin()` + + +[float] +=== Parameters +Nothing + +[float] +=== Returns +Nothing + +-- +// OVERVIEW SECTION ENDS + + + + +// HOW TO USE SECTION STARTS +[#howtouse] +-- + +[float] +=== Example Code +// Describe what the example code is all about and add relevant code ►►►►► THIS SECTION IS MANDATORY ◄◄◄◄◄ + + +[source,arduino] +---- +void setup(){ + pinMode(2, INPUT); +} + +void loop(){ + + //initiate the Mouse library when button is pressed + if(digitalRead(2) == HIGH){ + Mouse.begin(); + } + +} +---- +[%hardbreaks] + +[float] +=== See also +// Link relevant content by category, such as other Reference terms (please add the tag #LANGUAGE#), +// definitions (please add the tag #DEFINITION#), and examples of Projects and Tutorials +// (please add the tag #EXAMPLE#) ►►►►► THIS SECTION IS MANDATORY ◄◄◄◄◄ +[role="language"] +* #LANGUAGE# link:mouseClick{ext-relative}[Mouse.click] + +* #LANGUAGE# link:mouseEnd{ext-relative}[Mouse.end] + +* #LANGUAGE# link:mouseMove{ext-relative}[Mouse.move] + +* #LANGUAGE# link:mousePress{ext-relative}[Mouse.press] + +* #LANGUAGE# link:mouseRelease{ext-relative}[Mouse.release] + +* #LANGUAGE# link:mouseIsPressed{ext-relative}[Mouse.releaseAll] + +-- +// HOW TO USE SECTION ENDS diff --git a/Language/Functions/USB (Leonardo and DUE only)/Mouse/mouseClick.adoc b/Language/Functions/USB (Leonardo and DUE only)/Mouse/mouseClick.adoc new file mode 100644 index 000000000..5cc9fdb38 --- /dev/null +++ b/Language/Functions/USB (Leonardo and DUE only)/Mouse/mouseClick.adoc @@ -0,0 +1,90 @@ +:source-highlighter: pygments +:pygments-style: arduino +:ext-relative: adoc + + += Mouse.click() + + +// OVERVIEW SECTION STARTS +[#overview] +-- + +[float] +=== Description +Sends a momentary click to the computer at the location of the cursor. This is the same as pressing and immediately releasing the mouse button. + +`Mouse.click()` defaults to the left mouse button. +[%hardbreaks] + + +[float] +=== Syntax +`Mouse.click();` + +`Mouse.click(button);` + + +[float] +=== Parameters +`button`: which mouse button to press - `char` + +* `MOUSE_LEFT` (default) +* `MOUSE_RIGHT` +* `MOUSE_MIDDLE` + +[float] +=== Returns +Nothing + +-- +// OVERVIEW SECTION ENDS + + + + +// HOW TO USE SECTION STARTS +[#howtouse] +-- + +[float] +=== Example Code +// Describe what the example code is all about and add relevant code ►►►►► THIS SECTION IS MANDATORY ◄◄◄◄◄ + + +[source,arduino] +---- +void setup(){ + pinMode(2,INPUT); + //initiate the Mouse library + Mouse.begin(); +} + +void loop(){ + //if the button is pressed, send a Right mouse click + if(digitalRead(2) == HIGH){ + Mouse.click(); + } +} +---- +[%hardbreaks] + +[float] +=== Notes and Warnings +When you use the `Mouse.click()` command, the Arduino takes over your mouse! Make sure you have control before you use the command. A pushbutton to toggle the mouse control state is effective. +[%hardbreaks] + +[float] +=== See also +// Link relevant content by category, such as other Reference terms (please add the tag #LANGUAGE#), +// definitions (please add the tag #DEFINITION#), and examples of Projects and Tutorials +// (please add the tag #EXAMPLE#) ►►►►► THIS SECTION IS MANDATORY ◄◄◄◄◄ +[role="language"] +* #LANGUAGE# link:mouseClick{ext-relative}[Mouse.click] + +* #LANGUAGE# link:mouseEnd{ext-relative}[Mouse.end] + +* #LANGUAGE# link:mouseMove{ext-relative}[Mouse.move] + +* #LANGUAGE# link:mousePress{ext-relative}[Mouse.press] + +* #LANGUAGE# link:mouseRelease{ext-relative}[Mouse.release] + +* #LANGUAGE# link:mouseIsPressed{ext-relative}[Mouse.releaseAll] + +-- +// HOW TO USE SECTION ENDS diff --git a/Language/Functions/USB (Leonardo and DUE only)/Mouse/mouseEnd.adoc b/Language/Functions/USB (Leonardo and DUE only)/Mouse/mouseEnd.adoc new file mode 100644 index 000000000..64cf91b44 --- /dev/null +++ b/Language/Functions/USB (Leonardo and DUE only)/Mouse/mouseEnd.adoc @@ -0,0 +1,82 @@ +:source-highlighter: pygments +:pygments-style: arduino +:ext-relative: adoc + + += Mouse.end() + + +// OVERVIEW SECTION STARTS +[#overview] +-- + +[float] +=== Description +Stops emulating the mouse connected to a computer. To start control, use link:mouseBegin{ext-relative}[Mouse.begin()]. +[%hardbreaks] + + +[float] +=== Syntax +`Mouse.end()` + + +[float] +=== Parameters +Nothing + +[float] +=== Returns +Nothing + +-- +// OVERVIEW SECTION ENDS + + + + +// HOW TO USE SECTION STARTS +[#howtouse] +-- + +[float] +=== Example Code +// Describe what the example code is all about and add relevant code ►►►►► THIS SECTION IS MANDATORY ◄◄◄◄◄ + + +[source,arduino] +---- +void setup(){ + pinMode(2,INPUT); + //initiate the Mouse library + Mouse.begin(); +} + +void loop(){ + //if the button is pressed, send a Right mouse click + //then end the Mouse emulation + if(digitalRead(2) == HIGH){ + Mouse.click(); + Mouse.end(); + } +} + +---- +[%hardbreaks] + + +[float] +=== See also +// Link relevant content by category, such as other Reference terms (please add the tag #LANGUAGE#), +// definitions (please add the tag #DEFINITION#), and examples of Projects and Tutorials +// (please add the tag #EXAMPLE#) ►►►►► THIS SECTION IS MANDATORY ◄◄◄◄◄ +[role="language"] +* #LANGUAGE# link:mouseClick{ext-relative}[Mouse.click] + +* #LANGUAGE# link:mouseEnd{ext-relative}[Mouse.end] + +* #LANGUAGE# link:mouseMove{ext-relative}[Mouse.move] + +* #LANGUAGE# link:mousePress{ext-relative}[Mouse.press] + +* #LANGUAGE# link:mouseRelease{ext-relative}[Mouse.release] + +* #LANGUAGE# link:mouseIsPressed{ext-relative}[Mouse.releaseAll] + +-- +// HOW TO USE SECTION ENDS diff --git a/Language/Functions/USB (Leonardo and DUE only)/Mouse/mouseIsPressed.adoc b/Language/Functions/USB (Leonardo and DUE only)/Mouse/mouseIsPressed.adoc new file mode 100644 index 000000000..c90f41aa6 --- /dev/null +++ b/Language/Functions/USB (Leonardo and DUE only)/Mouse/mouseIsPressed.adoc @@ -0,0 +1,102 @@ +:source-highlighter: pygments +:pygments-style: arduino +:ext-relative: adoc + + += Mouse.isPressed() + + +// OVERVIEW SECTION STARTS +[#overview] +-- + +[float] +=== Description +Checks the current status of all mouse buttons, and reports if any are pressed or not. +[%hardbreaks] + + +[float] +=== Syntax +`Mouse.isPressed();` + +`Mouse.isPressed(button);` + +[float] +=== Parameters +When there is no value passed, it checks the status of the left mouse button. + +`button`: which mouse button to check - `char` + +* `MOUSE_LEFT (default)` + +* `MOUSE_RIGHT` + +* `MOUSE_MIDDLE` + +[float] +=== Returns +`boolean` : reports wether a button is pressed or not. + +-- +// OVERVIEW SECTION ENDS + + + + +// HOW TO USE SECTION STARTS +[#howtouse] +-- + +[float] +=== Example Code +// Describe what the example code is all about and add relevant code ►►►►► THIS SECTION IS MANDATORY ◄◄◄◄◄ + + +[source,arduino] +---- +void setup(){ + //The switch that will initiate the Mouse press + pinMode(2,INPUT); + //The switch that will terminate the Mouse press + pinMode(3,INPUT); + //Start serial communication with the computer + Serial1.begin(9600); + //initiate the Mouse library + Mouse.begin(); +} + +void loop(){ + //a variable for checking the button's state + int mouseState=0; + //if the switch attached to pin 2 is closed, press and hold the right mouse button and save the state ina variable + if(digitalRead(2) == HIGH){ + Mouse.press(); + mouseState=Mouse.isPressed(); + } + //if the switch attached to pin 3 is closed, release the right mouse button and save the state in a variable + if(digitalRead(3) == HIGH){ + Mouse.release(); + mouseState=Mouse.isPressed(); + } + //print out the current mouse button state + Serial1.println(mouseState); + delay(10); +} +---- +[%hardbreaks] + +[float] +=== See also +// Link relevant content by category, such as other Reference terms (please add the tag #LANGUAGE#), +// definitions (please add the tag #DEFINITION#), and examples of Projects and Tutorials +// (please add the tag #EXAMPLE#) ►►►►► THIS SECTION IS MANDATORY ◄◄◄◄◄ +[role="language"] +* #LANGUAGE# link:mouseClick{ext-relative}[Mouse.click] + +* #LANGUAGE# link:mouseEnd{ext-relative}[Mouse.end] + +* #LANGUAGE# link:mouseMove{ext-relative}[Mouse.move] + +* #LANGUAGE# link:mousePress{ext-relative}[Mouse.press] + +* #LANGUAGE# link:mouseRelease{ext-relative}[Mouse.release] + +* #LANGUAGE# link:mouseIsPressed{ext-relative}[Mouse.releaseAll] + +-- +// HOW TO USE SECTION ENDS diff --git a/Language/Functions/USB (Leonardo and DUE only)/Mouse/mouseMove.adoc b/Language/Functions/USB (Leonardo and DUE only)/Mouse/mouseMove.adoc new file mode 100644 index 000000000..bc77f1c5c --- /dev/null +++ b/Language/Functions/USB (Leonardo and DUE only)/Mouse/mouseMove.adoc @@ -0,0 +1,143 @@ +:source-highlighter: pygments +:pygments-style: arduino +:ext-relative: adoc + + += Mouse.move() + + +// OVERVIEW SECTION STARTS +[#overview] +-- + +[float] +=== Description +Moves the cursor on a connected computer. The motion onscreen is always relative to the cursor's current location. Before using `Mouse.move()` you must call link:mouseBegin{ext-relative}[Mouse.begin()] +[%hardbreaks] + + +[float] +=== Syntax +`Mouse.move(xVal, yPos, wheel);` + + +[float] +=== Parameters +`xVal`: amount to move along the x-axis - `signed char` + +`yVal`: amount to move along the y-axis - `signed char` + +`wheel`: amount to move scroll wheel - `signed char` +[float] +=== Returns +Nothing + +-- +// OVERVIEW SECTION ENDS + + + + +// HOW TO USE SECTION STARTS +[#howtouse] +-- + +[float] +=== Example Code +// Describe what the example code is all about and add relevant code ►►►►► THIS SECTION IS MANDATORY ◄◄◄◄◄ + + +[source,arduino] +---- +const int xAxis = A1; //analog sensor for X axis +const int yAxis = A2; // analog sensor for Y axis + +int range = 12; // output range of X or Y movement +int responseDelay = 2; // response delay of the mouse, in ms +int threshold = range/4; // resting threshold +int center = range/2; // resting position value +int minima[] = { + 1023, 1023}; // actual analogRead minima for {x, y} +int maxima[] = { + 0,0}; // actual analogRead maxima for {x, y} +int axis[] = { + xAxis, yAxis}; // pin numbers for {x, y} +int mouseReading[2]; // final mouse readings for {x, y} + + +void setup() { + Mouse.begin(); +} + +void loop() { + +// read and scale the two axes: + int xReading = readAxis(0); + int yReading = readAxis(1); + +// move the mouse: + Mouse.move(xReading, yReading, 0); + delay(responseDelay); +} + +/* + reads an axis (0 or 1 for x or y) and scales the + analog input range to a range from 0 to +*/ + +int readAxis(int axisNumber) { + int distance = 0; // distance from center of the output range + + // read the analog input: + int reading = analogRead(axis[axisNumber]); + +// of the current reading exceeds the max or min for this axis, +// reset the max or min: + if (reading < minima[axisNumber]) { + minima[axisNumber] = reading; + } + if (reading > maxima[axisNumber]) { + maxima[axisNumber] = reading; + } + + // map the reading from the analog input range to the output range: + reading = map(reading, minima[axisNumber], maxima[axisNumber], 0, range); + + // if the output reading is outside from the + // rest position threshold, use it: + if (abs(reading - center) > threshold) { + distance = (reading - center); + } + + // the Y axis needs to be inverted in order to + // map the movemment correctly: + if (axisNumber == 1) { + distance = -distance; + } + + // return the distance for this axis: + return distance; +} +---- +[%hardbreaks] + +[float] +=== Notes and Warnings +When you use the `Mouse.move()` command, the Arduino takes over your mouse! Make sure you have control before you use the command. A pushbutton to toggle the mouse control state is effective. +[%hardbreaks] + +[float] +=== See also +// Link relevant content by category, such as other Reference terms (please add the tag #LANGUAGE#), +// definitions (please add the tag #DEFINITION#), and examples of Projects and Tutorials +// (please add the tag #EXAMPLE#) ►►►►► THIS SECTION IS MANDATORY ◄◄◄◄◄ +[role="language"] +* #LANGUAGE# link:mouseClick{ext-relative}[Mouse.click] + +* #LANGUAGE# link:mouseEnd{ext-relative}[Mouse.end] + +* #LANGUAGE# link:mouseMove{ext-relative}[Mouse.move] + +* #LANGUAGE# link:mousePress{ext-relative}[Mouse.press] + +* #LANGUAGE# link:mouseRelease{ext-relative}[Mouse.release] + +* #LANGUAGE# link:mouseIsPressed{ext-relative}[Mouse.releaseAll] + +-- +// HOW TO USE SECTION ENDS diff --git a/Language/Functions/USB (Leonardo and DUE only)/Mouse/mousePress.adoc b/Language/Functions/USB (Leonardo and DUE only)/Mouse/mousePress.adoc new file mode 100644 index 000000000..a73c958a4 --- /dev/null +++ b/Language/Functions/USB (Leonardo and DUE only)/Mouse/mousePress.adoc @@ -0,0 +1,101 @@ +:source-highlighter: pygments +:pygments-style: arduino +:ext-relative: adoc + + += Mouse.press() + + +// OVERVIEW SECTION STARTS +[#overview] +-- + +[float] +=== Description +Sends a button press to a connected computer. A press is the equivalent of clicking and continuously holding the mouse button. A press is cancelled with link:mouseRelease{ext-relative}[Mouse.release()]. + +Before using `Mouse.press()`, you need to start communication with link:mouseBegin{ext-relative}[Mouse.begin()]. + +`Mouse.press()` defaults to a left button press. +[%hardbreaks] + + +[float] +=== Syntax +`Mouse.press();` + +`Mouse.press(button)` + + +[float] +=== Parameters +`button`: which mouse button to press - `char` + +* `MOUSE_LEFT (default)` + +* `MOUSE_RIGHT` + +* `MOUSE_MIDDLE` + +[float] +=== Returns +Nothing + +-- +// OVERVIEW SECTION ENDS + + + + +// HOW TO USE SECTION STARTS +[#howtouse] +-- + +[float] +=== Example Code +// Describe what the example code is all about and add relevant code ►►►►► THIS SECTION IS MANDATORY ◄◄◄◄◄ + + +[source,arduino] +---- +void setup(){ + //The switch that will initiate the Mouse press + pinMode(2,INPUT); + //The switch that will terminate the Mouse press + pinMode(3,INPUT); + //initiate the Mouse library + Mouse.begin(); +} + +void loop(){ + //if the switch attached to pin 2 is closed, press and hold the right mouse button + if(digitalRead(2) == HIGH){ + Mouse.press(); + } + //if the switch attached to pin 3 is closed, release the right mouse button + if(digitalRead(3) == HIGH){ + Mouse.release(); + } +} +---- +[%hardbreaks] + +[float] +=== Notes and Warnings +When you use the `Mouse.press()` command, the Arduino takes over your mouse! Make sure you have control before you use the command. A pushbutton to toggle the mouse control state is effective. +[%hardbreaks] + +[float] +=== See also +// Link relevant content by category, such as other Reference terms (please add the tag #LANGUAGE#), +// definitions (please add the tag #DEFINITION#), and examples of Projects and Tutorials +// (please add the tag #EXAMPLE#) ►►►►► THIS SECTION IS MANDATORY ◄◄◄◄◄ +[role="language"] +* #LANGUAGE# link:mouseClick{ext-relative}[Mouse.click] + +* #LANGUAGE# link:mouseEnd{ext-relative}[Mouse.end] + +* #LANGUAGE# link:mouseMove{ext-relative}[Mouse.move] + +* #LANGUAGE# link:mousePress{ext-relative}[Mouse.press] + +* #LANGUAGE# link:mouseRelease{ext-relative}[Mouse.release] + +* #LANGUAGE# link:mouseIsPressed{ext-relative}[Mouse.releaseAll] + +-- +// HOW TO USE SECTION ENDS diff --git a/Language/Functions/USB (Leonardo and DUE only)/Mouse/mouseRelease.adoc b/Language/Functions/USB (Leonardo and DUE only)/Mouse/mouseRelease.adoc new file mode 100644 index 000000000..9e30d543d --- /dev/null +++ b/Language/Functions/USB (Leonardo and DUE only)/Mouse/mouseRelease.adoc @@ -0,0 +1,96 @@ +:source-highlighter: pygments +:pygments-style: arduino +:ext-relative: adoc + + += Mouse.release() + + +// OVERVIEW SECTION STARTS +[#overview] +-- + +[float] +=== Description +Sends a message that a previously pressed button (invoked through link:mousePress{ext-relative}[Mouse.press()]) is released. Mouse.release() defaults to the left button. +[%hardbreaks] + + +[float] +=== Syntax +`Mouse.release();` + +`Mouse.release(button);` + +[float] +=== Parameters +`button`: which mouse button to press - char + +* `MOUSE_LEFT` (default) + +* `MOUSE_RIGHT` + +* `MOUSE_MIDDLE` + +[float] +=== Returns +Nothing + +-- +// OVERVIEW SECTION ENDS + + + + +// HOW TO USE SECTION STARTS +[#howtouse] +-- + +[float] +=== Example Code +// Describe what the example code is all about and add relevant code ►►►►► THIS SECTION IS MANDATORY ◄◄◄◄◄ + + +[source,arduino] +---- +void setup(){ + //The switch that will initiate the Mouse press + pinMode(2,INPUT); + //The switch that will terminate the Mouse press + pinMode(3,INPUT); + //initiate the Mouse library + Mouse.begin(); +} + +void loop(){ + //if the switch attached to pin 2 is closed, press and hold the right mouse button + if(digitalRead(2) == HIGH){ + Mouse.press(); + } + //if the switch attached to pin 3 is closed, release the right mouse button + if(digitalRead(3) == HIGH){ + Mouse.release(); + } +} +---- +[%hardbreaks] + +[float] +=== Notes and Warnings +When you use the `Mouse.release()` command, the Arduino takes over your mouse! Make sure you have control before you use the command. A pushbutton to toggle the mouse control state is effective. +[%hardbreaks] + +[float] +=== See also +// Link relevant content by category, such as other Reference terms (please add the tag #LANGUAGE#), +// definitions (please add the tag #DEFINITION#), and examples of Projects and Tutorials +// (please add the tag #EXAMPLE#) ►►►►► THIS SECTION IS MANDATORY ◄◄◄◄◄ +[role="language"] +* #LANGUAGE# link:mouseClick{ext-relative}[Mouse.click] + +* #LANGUAGE# link:mouseEnd{ext-relative}[Mouse.end] + +* #LANGUAGE# link:mouseMove{ext-relative}[Mouse.move] + +* #LANGUAGE# link:mousePress{ext-relative}[Mouse.press] + +* #LANGUAGE# link:mouseRelease{ext-relative}[Mouse.release] + +* #LANGUAGE# link:mouseIsPressed{ext-relative}[Mouse.releaseAll] + +-- +// HOW TO USE SECTION ENDS From d129ab428bb19f88cba42ad999e13350dc2d5a5c Mon Sep 17 00:00:00 2001 From: Akshay Sharma Date: Tue, 17 Feb 2015 17:28:32 +0530 Subject: [PATCH 08/13] Add content Language/Variables --- Language/Variables/Conversion/byteCast.adoc | 52 +++++++++ Language/Variables/Conversion/charCast.adoc | 52 +++++++++ Language/Variables/Conversion/floatCast.adoc | 56 ++++++++++ Language/Variables/Conversion/intCast.adoc | 52 +++++++++ Language/Variables/Conversion/longCast.adoc | 52 +++++++++ Language/Variables/Conversion/wordcast.adoc | 55 ++++++++++ Language/Variables/Data Types/array.adoc | 100 ++++++++++++++++++ Language/Variables/Data Types/boolean.adoc | 73 +++++++++++++ Language/Variables/Data Types/byte.adoc | 53 ++++++++++ Language/Variables/Data Types/char.adoc | 60 +++++++++++ Language/Variables/Data Types/double.adoc | 45 ++++++++ Language/Variables/Data Types/float.adoc | 77 ++++++++++++++ Language/Variables/Data Types/int.adoc | 82 ++++++++++++++ Language/Variables/Data Types/long.adoc | 64 +++++++++++ Language/Variables/Data Types/short.adoc | 63 +++++++++++ Language/Variables/Data Types/string.adoc | 1 + .../Variables/Data Types/stringObject.adoc | 60 +++++++++++ .../Variables/Data Types/unsignedChar.adoc | 58 ++++++++++ .../Variables/Data Types/unsignedInt.adoc | 75 +++++++++++++ .../Variables/Data Types/unsignedLong.adoc | 77 ++++++++++++++ Language/Variables/Data Types/void.adoc | 61 +++++++++++ Language/Variables/Data Types/word.adoc | 49 +++++++++ Language/Variables/Utilities/PROGMEM.adoc | 1 + Language/Variables/Utilities/sizeof.adoc | 1 + .../Variable Scope & Qualifiers/const.adoc | 69 ++++++++++++ .../Variable Scope & Qualifiers/scope.adoc | 64 +++++++++++ .../Variable Scope & Qualifiers/static.adoc | 86 +++++++++++++++ .../Variable Scope & Qualifiers/voletile.adoc | 76 +++++++++++++ 28 files changed, 1614 insertions(+) create mode 100644 Language/Variables/Conversion/byteCast.adoc create mode 100644 Language/Variables/Conversion/charCast.adoc create mode 100644 Language/Variables/Conversion/floatCast.adoc create mode 100644 Language/Variables/Conversion/intCast.adoc create mode 100644 Language/Variables/Conversion/longCast.adoc create mode 100644 Language/Variables/Conversion/wordcast.adoc create mode 100644 Language/Variables/Data Types/array.adoc create mode 100644 Language/Variables/Data Types/boolean.adoc create mode 100644 Language/Variables/Data Types/byte.adoc create mode 100644 Language/Variables/Data Types/char.adoc create mode 100644 Language/Variables/Data Types/double.adoc create mode 100644 Language/Variables/Data Types/float.adoc create mode 100644 Language/Variables/Data Types/int.adoc create mode 100644 Language/Variables/Data Types/long.adoc create mode 100644 Language/Variables/Data Types/short.adoc create mode 100644 Language/Variables/Data Types/string.adoc create mode 100644 Language/Variables/Data Types/stringObject.adoc create mode 100644 Language/Variables/Data Types/unsignedChar.adoc create mode 100644 Language/Variables/Data Types/unsignedInt.adoc create mode 100644 Language/Variables/Data Types/unsignedLong.adoc create mode 100644 Language/Variables/Data Types/void.adoc create mode 100644 Language/Variables/Data Types/word.adoc create mode 100644 Language/Variables/Utilities/PROGMEM.adoc create mode 100644 Language/Variables/Utilities/sizeof.adoc create mode 100644 Language/Variables/Variable Scope & Qualifiers/const.adoc create mode 100644 Language/Variables/Variable Scope & Qualifiers/scope.adoc create mode 100644 Language/Variables/Variable Scope & Qualifiers/static.adoc create mode 100644 Language/Variables/Variable Scope & Qualifiers/voletile.adoc diff --git a/Language/Variables/Conversion/byteCast.adoc b/Language/Variables/Conversion/byteCast.adoc new file mode 100644 index 000000000..66c5236e6 --- /dev/null +++ b/Language/Variables/Conversion/byteCast.adoc @@ -0,0 +1,52 @@ +:source-highlighter: pygments +:pygments-style: arduino +:ext-relative: adoc + + += byte() + + +// OVERVIEW SECTION STARTS +[#overview] +-- + +[float] +=== Description +Converts a value to the link:byte{ext-relative}[byte] data type. +[%hardbreaks] + + +[float] +=== Syntax +`byte(x)` + + +[float] +=== Parameters +`x`: a value of any type + +[float] +=== Returns +`byte` + +-- +// OVERVIEW SECTION ENDS + + + + +// HOW TO USE SECTION STARTS +[#howtouse] +-- + +[float] +=== See also +// Link relevant content by category, such as other Reference terms (please add the tag #LANGUAGE#), +// definitions (please add the tag #DEFINITION#), and examples of Projects and Tutorials +// (please add the tag #EXAMPLE#) ►►►►► THIS SECTION IS MANDATORY ◄◄◄◄◄ +[role="language"] +* #LANGUAGE# link:byte{ext-relative}[byte] + + +-- +// HOW TO USE SECTION ENDS diff --git a/Language/Variables/Conversion/charCast.adoc b/Language/Variables/Conversion/charCast.adoc new file mode 100644 index 000000000..2762a5519 --- /dev/null +++ b/Language/Variables/Conversion/charCast.adoc @@ -0,0 +1,52 @@ +:source-highlighter: pygments +:pygments-style: arduino +:ext-relative: adoc + + += char() + + +// OVERVIEW SECTION STARTS +[#overview] +-- + +[float] +=== Description +Converts a value to the link:char{ext-relative}[char] data type. +[%hardbreaks] + + +[float] +=== Syntax +`char(x)` + + +[float] +=== Parameters +`x`: a value of any type + +[float] +=== Returns +`char` + +-- +// OVERVIEW SECTION ENDS + + + + +// HOW TO USE SECTION STARTS +[#howtouse] +-- + +[float] +=== See also +// Link relevant content by category, such as other Reference terms (please add the tag #LANGUAGE#), +// definitions (please add the tag #DEFINITION#), and examples of Projects and Tutorials +// (please add the tag #EXAMPLE#) ►►►►► THIS SECTION IS MANDATORY ◄◄◄◄◄ +[role="language"] +* #LANGUAGE# link:char{ext-relative}[char] + + +-- +// HOW TO USE SECTION ENDS diff --git a/Language/Variables/Conversion/floatCast.adoc b/Language/Variables/Conversion/floatCast.adoc new file mode 100644 index 000000000..858910265 --- /dev/null +++ b/Language/Variables/Conversion/floatCast.adoc @@ -0,0 +1,56 @@ +:source-highlighter: pygments +:pygments-style: arduino +:ext-relative: adoc + + += float() + + +// OVERVIEW SECTION STARTS +[#overview] +-- + +[float] +=== Description +Converts a value to the link:float{ext-relative}[float] data type. +[%hardbreaks] + + +[float] +=== Syntax +`float(x)` + + +[float] +=== Parameters +`x`: a value of any type + +[float] +=== Returns +`float` + +-- +// OVERVIEW SECTION ENDS + + + + +// HOW TO USE SECTION STARTS +[#howtouse] +-- +[float] +=== Notes and Warnings +See the reference for link:float{ext-relative}[float] for details about the precision and limitations of floating point numbers on Arduino. +[%hardbreaks] + +[float] +=== See also +// Link relevant content by category, such as other Reference terms (please add the tag #LANGUAGE#), +// definitions (please add the tag #DEFINITION#), and examples of Projects and Tutorials +// (please add the tag #EXAMPLE#) ►►►►► THIS SECTION IS MANDATORY ◄◄◄◄◄ + +* #LANGUAGE# link:float{ext-relative}[float] + + +-- +// HOW TO USE SECTION ENDS diff --git a/Language/Variables/Conversion/intCast.adoc b/Language/Variables/Conversion/intCast.adoc new file mode 100644 index 000000000..4d6f749d4 --- /dev/null +++ b/Language/Variables/Conversion/intCast.adoc @@ -0,0 +1,52 @@ +:source-highlighter: pygments +:pygments-style: arduino +:ext-relative: adoc + + += int() + + +// OVERVIEW SECTION STARTS +[#overview] +-- + +[float] +=== Description +Converts a value to the link:int{ext-relative}[int] data type. +[%hardbreaks] + + +[float] +=== Syntax +`int(x)` + + +[float] +=== Parameters +`x`: a value of any type + +[float] +=== Returns +`int` + +-- +// OVERVIEW SECTION ENDS + + + + +// HOW TO USE SECTION STARTS +[#howtouse] +-- + +[float] +=== See also +// Link relevant content by category, such as other Reference terms (please add the tag #LANGUAGE#), +// definitions (please add the tag #DEFINITION#), and examples of Projects and Tutorials +// (please add the tag #EXAMPLE#) ►►►►► THIS SECTION IS MANDATORY ◄◄◄◄◄ +[role="language"] +* #LANGUAGE# link:int{ext-relative}[int] + + +-- +// HOW TO USE SECTION ENDS diff --git a/Language/Variables/Conversion/longCast.adoc b/Language/Variables/Conversion/longCast.adoc new file mode 100644 index 000000000..7fce1a5e6 --- /dev/null +++ b/Language/Variables/Conversion/longCast.adoc @@ -0,0 +1,52 @@ +:source-highlighter: pygments +:pygments-style: arduino +:ext-relative: adoc + + += long() + + +// OVERVIEW SECTION STARTS +[#overview] +-- + +[float] +=== Description +Converts a value to the link:long{ext-relative}[long] data type. +[%hardbreaks] + + +[float] +=== Syntax +`long(x)` + + +[float] +=== Parameters +`x`: a value of any type + +[float] +=== Returns +`long` + +-- +// OVERVIEW SECTION ENDS + + + + +// HOW TO USE SECTION STARTS +[#howtouse] +-- + +[float] +=== See also +// Link relevant content by category, such as other Reference terms (please add the tag #LANGUAGE#), +// definitions (please add the tag #DEFINITION#), and examples of Projects and Tutorials +// (please add the tag #EXAMPLE#) ►►►►► THIS SECTION IS MANDATORY ◄◄◄◄◄ +[role="language"] +* #LANGUAGE# link:long{ext-relative}[long] + + +-- +// HOW TO USE SECTION ENDS diff --git a/Language/Variables/Conversion/wordcast.adoc b/Language/Variables/Conversion/wordcast.adoc new file mode 100644 index 000000000..74f3b4a67 --- /dev/null +++ b/Language/Variables/Conversion/wordcast.adoc @@ -0,0 +1,55 @@ +:source-highlighter: pygments +:pygments-style: arduino +:ext-relative: adoc + + += word() + + +// OVERVIEW SECTION STARTS +[#overview] +-- + +[float] +=== Description +Converts a value to the link:word{ext-relative}[word] data type. +[%hardbreaks] + + +[float] +=== Syntax +`word(x)` + +`word(h, l)` + +[float] +=== Parameters +`x`: a value of any type + +`h`: the high-order (leftmost) byte of the word + +`l`: the low-order (rightmost) byte of the word +[float] +=== Returns +`word` + +-- +// OVERVIEW SECTION ENDS + + + + +// HOW TO USE SECTION STARTS +[#howtouse] +-- + +[float] +=== See also +// Link relevant content by category, such as other Reference terms (please add the tag #LANGUAGE#), +// definitions (please add the tag #DEFINITION#), and examples of Projects and Tutorials +// (please add the tag #EXAMPLE#) ►►►►► THIS SECTION IS MANDATORY ◄◄◄◄◄ +[role="language"] +* #LANGUAGE# link:word{ext-relative}[word] + + +-- +// HOW TO USE SECTION ENDS diff --git a/Language/Variables/Data Types/array.adoc b/Language/Variables/Data Types/array.adoc new file mode 100644 index 000000000..b06c948d7 --- /dev/null +++ b/Language/Variables/Data Types/array.adoc @@ -0,0 +1,100 @@ +:source-highlighter: pygments +:pygments-style: arduino +:ext-relative: adoc + + += Arrays + + +// OVERVIEW SECTION STARTS +[#overview] +-- + +[float] +=== Description +An array is a collection of variables that are accessed with an index number. Arrays in the C programming language, on which Arduino is based, can be complicated, but using simple arrays is relatively straightforward. +=== Creating (Declaring) an Array + +All of the methods below are valid ways to create (declare) an array. +[source,arduino] +---- + int myInts[6]; + int myPins[] = {2, 4, 8, 3, 6}; + int mySensVals[6] = {2, 4, -8, 3, 2}; + char message[6] = "hello"; +---- +You can declare an array without initializing it as in myInts. +{empty} + +In myPins we declare an array without explicitly choosing a size. The compiler counts the elements and creates an array of the appropriate size. +{empty} + +Finally you can both initialize and size your array, as in mySensVals. Note that when declaring an array of type char, one more element than your initialization is required, to hold the required null character. +[%hardbreaks] + +[float] +=== Accessing an Array +Arrays are zero indexed, that is, referring to the array initialization above, the first element of the array is at index 0, hence + +`mySensVals[0] == 2, mySensVals[1] == 4,` and so forth. + +It also means that in an array with ten elements, index nine is the last element. Hence: + +[source,arduino] +---- +int myArray[10]={9,3,2,4,3,2,7,8,9,11}; + // myArray[9] contains 11 + // myArray[10] is invalid and contains random information (other memory address) +---- +For this reason you should be careful in accessing arrays. Accessing past the end of an array (using an index number greater than your declared array size - 1) is reading from memory that is in use for other purposes. Reading from these locations is probably not going to do much except yield invalid data. Writing to random memory locations is definitely a bad idea and can often lead to unhappy results such as crashes or program malfunction. This can also be a difficult bug to track down. +[%hardbreaks] + +Unlike BASIC or JAVA, the C compiler does no checking to see if array access is within legal bounds of the array size that you have declared. +[%hardbreaks] + +[float] +=== To assign a value to an array: +`mySensVals[0] = 10;` +[%hardbreaks] + +[float] +=== To retrieve a value from an array: +`x = mySensVals[4];` +[%hardbreaks] + +[float] +=== Arrays and FOR Loops +Arrays are often manipulated inside for loops, where the loop counter is used as the index for each array element. For example, to print the elements of an array over the serial port, you could do something like this: + +[source,arduino] +---- +int i; +for (i = 0; i < 5; i = i + 1) { + Serial.println(myPins[i]); +} +---- +[%hardbreaks] + +-- +// OVERVIEW SECTION ENDS + + +// HOW TO USE SECTION STARTS +[#howtouse] +-- + +[float] +=== Example Code +// Describe what the example code is all about and add relevant code ►►►►► THIS SECTION IS MANDATORY ◄◄◄◄◄ +For a complete program that demonstrates the use of arrays, see the (http://www.arduino.cc/en/Tutorial/KnightRider[Knight Rider example]) from the (http://www.arduino.cc/en/Main/LearnArduino[Tutorials]). +[%hardbreaks] + +[float] +=== See also +// Link relevant content by category, such as other Reference terms (please add the tag #LANGUAGE#), +// definitions (please add the tag #DEFINITION#), and examples of Projects and Tutorials +// (please add the tag #EXAMPLE#) ►►►►► THIS SECTION IS MANDATORY ◄◄◄◄◄ +[role="definition"] +* #DEFINITION# link:variableDeclaration{ext-relative}[Variable Declaration] + +* #DEFINITION# link:PROGMEM{ext-relative}[PROGMEM] + +-- +// HOW TO USE SECTION ENDS diff --git a/Language/Variables/Data Types/boolean.adoc b/Language/Variables/Data Types/boolean.adoc new file mode 100644 index 000000000..0baccff01 --- /dev/null +++ b/Language/Variables/Data Types/boolean.adoc @@ -0,0 +1,73 @@ +:source-highlighter: pygments +:pygments-style: arduino +:ext-relative: adoc + + += boolean + + +// OVERVIEW SECTION STARTS +[#overview] +-- + +[float] +=== Description +A `boolean` holds one of two values, link:true{ext-relative}[true] or link:false{ext-relative}[false]. (Each boolean variable occupies one byte of memory.) + + +[%hardbreaks] + +-- +// OVERVIEW SECTION ENDS + + + + +// HOW TO USE SECTION STARTS +[#howtouse] +-- + +[float] +=== Example Code +// Describe what the example code is all about and add relevant code ►►►►► THIS SECTION IS MANDATORY ◄◄◄◄◄ +The code shows how to use `boolean` datatype. + +[source,arduino] +---- +int LEDpin = 5; // LED on pin 5 +int switchPin = 13; // momentary switch on 13, other side connected to ground + +boolean running = false; + +void setup() +{ + pinMode(LEDpin, OUTPUT); + pinMode(switchPin, INPUT); + digitalWrite(switchPin, HIGH); // turn on pullup resistor +} + +void loop() +{ + if (digitalRead(switchPin) == LOW) + { // switch is pressed - pullup keeps pin high normally + delay(100); // delay to debounce switch + running = !running; // toggle running variable + digitalWrite(LEDpin, running) // indicate via LED + } +} +---- +[%hardbreaks] + +[float] +=== See also +// Link relevant content by category, such as other Reference terms (please add the tag #LANGUAGE#), +// definitions (please add the tag #DEFINITION#), and examples of Projects and Tutorials +// (please add the tag #EXAMPLE#) ►►►►► THIS SECTION IS MANDATORY ◄◄◄◄◄ + +[role="definition"] +* #DEFINITION# link:constants{ext-relative}[constants] + +* #DEFINITION# link:boolean{ext-relative}[boolean operators] + +* #DEFINITION# link:variableDeclaration{ext-relative}[Variable Declaration] + +-- +// HOW TO USE SECTION ENDS diff --git a/Language/Variables/Data Types/byte.adoc b/Language/Variables/Data Types/byte.adoc new file mode 100644 index 000000000..eb5706722 --- /dev/null +++ b/Language/Variables/Data Types/byte.adoc @@ -0,0 +1,53 @@ +:source-highlighter: pygments +:pygments-style: arduino +:ext-relative: adoc + + += byte + + +// OVERVIEW SECTION STARTS +[#overview] +-- + +[float] +=== Description +A byte stores an 8-bit unsigned number, from 0 to 255. +[%hardbreaks] + +-- +// OVERVIEW SECTION ENDS + + + + +// HOW TO USE SECTION STARTS +[#howtouse] +-- + +[float] +=== Example Code +// Describe what the example code is all about and add relevant code ►►►►► THIS SECTION IS MANDATORY ◄◄◄◄◄ + + +[source,arduino] +---- + +---- +[%hardbreaks] + +[float] +=== Notes and Warnings +[%hardbreaks] + +[float] +=== See also +// Link relevant content by category, such as other Reference terms (please add the tag #LANGUAGE#), +// definitions (please add the tag #DEFINITION#), and examples of Projects and Tutorials +// (please add the tag #EXAMPLE#) ►►►►► THIS SECTION IS MANDATORY ◄◄◄◄◄ +[role="definition"] +* #DEFINITION# link:word{ext-relative}[word] + +* #DEFINITION# link:byteCast{ext-relative}[byte()] + +* #DEFINITION# link:variableDeclaration{ext-relative}[Variable Declaration] +-- +// HOW TO USE SECTION ENDS diff --git a/Language/Variables/Data Types/char.adoc b/Language/Variables/Data Types/char.adoc new file mode 100644 index 000000000..add0e3f84 --- /dev/null +++ b/Language/Variables/Data Types/char.adoc @@ -0,0 +1,60 @@ +:source-highlighter: pygments +:pygments-style: arduino +:ext-relative: adoc + + += char + + +// OVERVIEW SECTION STARTS +[#overview] +-- + +[float] +=== Description +A data type that takes up 1 byte of memory that stores a character value. Character literals are written in single quotes, like this: 'A' (for multiple characters - strings - use double quotes: "ABC"). + +Characters are stored as numbers however. You can see the specific encoding in the link:ASCIIchart{ext-relative}[ASCII chart]. This means that it is possible to do arithmetic on characters, in which the ASCII value of the character is used (e.g. 'A' + 1 has the value 66, since the ASCII value of the capital letter A is 65). See link:println{ext-relative}[`Serial.println`] reference for more on how characters are translated to numbers. + +The char datatype is a signed type, meaning that it encodes numbers from -128 to 127. For an unsigned, one-byte (8 bit) data type, use the _byte_ data type. +[%hardbreaks] + +-- +// OVERVIEW SECTION ENDS + + + + +// HOW TO USE SECTION STARTS +[#howtouse] +-- + +[float] +=== Example Code +// Describe what the example code is all about and add relevant code ►►►►► THIS SECTION IS MANDATORY ◄◄◄◄◄ + + +[source,arduino] +---- + char myChar = 'A'; + char myChar = 65; // both are equivalent +---- +[%hardbreaks] + + + +[float] +=== See also +// Link relevant content by category, such as other Reference terms (please add the tag #LANGUAGE#), +// definitions (please add the tag #DEFINITION#), and examples of Projects and Tutorials +// (please add the tag #EXAMPLE#) ►►►►► THIS SECTION IS MANDATORY ◄◄◄◄◄ +[role="definition"] +* #DEFINITION# link:byte{ext-relative}[byte] + +* #DEFINITION# link:int{ext-relative}[int] + +* #DEFINITION# link:array{ext-relative}[array] + +[role="language"] +* #LANGUAGE# link:println{ext-relative}[Serial.println] + +-- +// HOW TO USE SECTION ENDS diff --git a/Language/Variables/Data Types/double.adoc b/Language/Variables/Data Types/double.adoc new file mode 100644 index 000000000..df116e4f7 --- /dev/null +++ b/Language/Variables/Data Types/double.adoc @@ -0,0 +1,45 @@ +:source-highlighter: pygments +:pygments-style: arduino +:ext-relative: adoc + + += double + + +// OVERVIEW SECTION STARTS +[#overview] +-- + +[float] +=== Description +Double precision floating point number. On the Uno and other ATMEGA based boards, this occupies 4 bytes. That is, the double implementation is exactly the same as the float, with no gain in precision. + +On the Arduino Due, doubles have 8-byte (64 bit) precision. +[%hardbreaks] + +-- +// OVERVIEW SECTION ENDS + + + + +// HOW TO USE SECTION STARTS +[#howtouse] +-- + + +[float] +=== Notes and Warnings +Users who borrow code from other sources that includes double variables may wish to examine the code to see if the implied precision is different from that actually achieved on ATMEGA based Arduinos. +[%hardbreaks] + +[float] +=== See also +// Link relevant content by category, such as other Reference terms (please add the tag #LANGUAGE#), +// definitions (please add the tag #DEFINITION#), and examples of Projects and Tutorials +// (please add the tag #EXAMPLE#) ►►►►► THIS SECTION IS MANDATORY ◄◄◄◄◄ +[role="definition"] +* #DEFINITION# link:float{ext-relative}[float] + +-- +// HOW TO USE SECTION ENDS diff --git a/Language/Variables/Data Types/float.adoc b/Language/Variables/Data Types/float.adoc new file mode 100644 index 000000000..acd9486a3 --- /dev/null +++ b/Language/Variables/Data Types/float.adoc @@ -0,0 +1,77 @@ +:source-highlighter: pygments +:pygments-style: arduino +:ext-relative: adoc + + += float + + +// OVERVIEW SECTION STARTS +[#overview] +-- + +[float] +=== Description +Datatype for floating-point numbers, a number that has a decimal point. Floating-point numbers are often used to approximate analog and continuous values because they have greater resolution than integers. Floating-point numbers can be as large as 3.4028235E+38 and as low as -3.4028235E+38. They are stored as 32 bits (4 bytes) of information. + +Floats have only 6-7 decimal digits of precision. That means the total number of digits, not the number to the right of the decimal point. Unlike other platforms, where you can get more precision by using a double (e.g. up to 15 digits), on the Arduino, double is the same size as float. + +Floating point numbers are not exact, and may yield strange results when compared. For example 6.0 / 3.0 may not equal 2.0. You should instead check that the absolute value of the difference between the numbers is less than some small number. + +Floating point math is also much slower than integer math in performing calculations, so should be avoided if, for example, a loop has to run at top speed for a critical timing function. Programmers often go to some lengths to convert floating point calculations to integer math to increase speed. + +If doing math with floats, you need to add a decimal point, otherwise it will be treated as an int. See the link:fpConstant{extrelative}[Floating point] constants page for details. +[%hardbreaks] + +[float] +=== Syntax +`float var=val;` + +`var` - your float variable name +`val` - the value you assign to that variable +[%hardbreaks] + +-- +// OVERVIEW SECTION ENDS + + + + +// HOW TO USE SECTION STARTS +[#howtouse] +-- + +[float] +=== Example Code +// Describe what the example code is all about and add relevant code ►►►►► THIS SECTION IS MANDATORY ◄◄◄◄◄ + + +[source,arduino] +---- + float myfloat; + float sensorCalbrate = 1.117; + + int x; + int y; + float z; + + x = 1; + y = x / 2; // y now contains 0, ints can't hold fractions + z = (float)x / 2.0; // z now contains .5 (you have to use 2.0, not 2) +---- +[%hardbreaks] + + +[float] +=== See also +// Link relevant content by category, such as other Reference terms (please add the tag #LANGUAGE#), +// definitions (please add the tag #DEFINITION#), and examples of Projects and Tutorials +// (please add the tag #EXAMPLE#) ►►►►► THIS SECTION IS MANDATORY ◄◄◄◄◄ + +[role="definition"] +* #DEFINITION# link:int{ext-relative}[int] + +* #DEFINITION# link:double{ext-relative}[double] + +* #DEFINITION# link:variableDeclaration{ext-relative}[Variable Declaration] + +-- +// HOW TO USE SECTION ENDS diff --git a/Language/Variables/Data Types/int.adoc b/Language/Variables/Data Types/int.adoc new file mode 100644 index 000000000..5b6bbe5d7 --- /dev/null +++ b/Language/Variables/Data Types/int.adoc @@ -0,0 +1,82 @@ +:source-highlighter: pygments +:pygments-style: arduino +:ext-relative: adoc + + += int + + +// OVERVIEW SECTION STARTS +[#overview] +-- + +[float] +=== Description +Integers are your primary data-type for number storage. + +On the Arduino Uno (and other ATMega based boards) an int stores a 16-bit (2-byte) value. This yields a range of -32,768 to 32,767 (minimum value of -2^15 and a maximum value of (2^15) - 1). +On the Arduino Due, an int stores a 32-bit (4-byte) value. This yields a range of -2,147,483,648 to 2,147,483,647 (minimum value of -2^31 and a maximum value of (2^31) - 1). + +int's store negative numbers with a technique called (http://en.wikipedia.org/wiki/2%27s_complement[2's complement math]). The highest bit, sometimes referred to as the "sign" bit, flags the number as a negative number. The rest of the bits are inverted and 1 is added. + +The Arduino takes care of dealing with negative numbers for you, so that arithmetic operations work transparently in the expected manner. There can be an unexpected complication in dealing with the link:bitshift{ext-relative}[bitshift right operator] (>>) however. +[%hardbreaks] + + +[float] +=== Syntax +`int var = val;` + +`var` - your int variable name + +`val` - the value you assign to that variable + +-- +// OVERVIEW SECTION ENDS + + + + +// HOW TO USE SECTION STARTS +[#howtouse] +-- + +[float] +=== Example Code +// Describe what the example code is all about and add relevant code ►►►►► THIS SECTION IS MANDATORY ◄◄◄◄◄ + + +[source,arduino] +---- + int ledPin = 13; +---- +[%hardbreaks] + +[float] +=== Notes and Warnings +When variables are made to exceed their maximum capacity they "roll over" back to their minimum capacity, note that this happens in both directions. +[source,arduino] +---- +int x; + x = -32768; + x = x - 1; // x now contains 32,767 - rolls over in neg. direction + + x = 32767; + x = x + 1; // x now contains -32,768 - rolls over + +---- +[%hardbreaks] + +[float] +=== See also +// Link relevant content by category, such as other Reference terms (please add the tag #LANGUAGE#), +// definitions (please add the tag #DEFINITION#), and examples of Projects and Tutorials +// (please add the tag #EXAMPLE#) ►►►►► THIS SECTION IS MANDATORY ◄◄◄◄◄ +[role="definition"] +* #DEFINITION# link:byte{ext-relative}[byte] + +* #DEFINITION# link:unsignedInt{ext-relative}[unsigned int] + +* #DEFINITION# link:Long{ext-relative}[long] + +* #DEFINITION# link:unsignedLong{ext-relative}[unsigned long] + +* #DEFINITION# link:integerConstant{ext-relative}[Integer Constants] + +* #DEFINITION# link:variableDeclaration{ext-relative}[Variable Declaration] +-- +// HOW TO USE SECTION ENDS diff --git a/Language/Variables/Data Types/long.adoc b/Language/Variables/Data Types/long.adoc new file mode 100644 index 000000000..af6e9386b --- /dev/null +++ b/Language/Variables/Data Types/long.adoc @@ -0,0 +1,64 @@ +:source-highlighter: pygments +:pygments-style: arduino +:ext-relative: adoc + + += long + + +// OVERVIEW SECTION STARTS +[#overview] +-- + +[float] +=== Description +Long variables are extended size variables for number storage, and store 32 bits (4 bytes), from -2,147,483,648 to 2,147,483,647. + +If doing math with integers, at least one of the numbers must be followed by an L, forcing it to be a long. See the link:integerConstant{ext-relative}[Integer Constants] page for details. +[%hardbreaks] + +[float] +=== Syntax + +`long var = val;` + +`var` - the long variable name +`val` - the value assigned to the variable +[%hardbreaks] +-- +// OVERVIEW SECTION ENDS + + + + +// HOW TO USE SECTION STARTS +[#howtouse] +-- + +[float] +=== Example Code +// Describe what the example code is all about and add relevant code ►►►►► THIS SECTION IS MANDATORY ◄◄◄◄◄ + + +[source,arduino] +---- + long speedOfLight = 186000L; // see the Integer Constants page for explanation of the 'L' +---- +[%hardbreaks] + + +[float] +=== See also +// Link relevant content by category, such as other Reference terms (please add the tag #LANGUAGE#), +// definitions (please add the tag #DEFINITION#), and examples of Projects and Tutorials +// (please add the tag #EXAMPLE#) ►►►►► THIS SECTION IS MANDATORY ◄◄◄◄◄ +[role="definition"] +* #DEFINITION# link:byte{ext-relative}[byte] + +* #DEFINITION# link:int{ext-relative}[int] + +* #DEFINITION# link:unsignedInt{ext-relative}[unsigned int] + +* #DEFINITION# link:unsignedLong{ext-relative}[unsigned long] + +* #DEFINITION# link:integerConstant{ext-relative}[Integer Constants] + +* #DEFINITION# link:variableDeclaration{ext-relative}[Variable Declaration] + +-- +// HOW TO USE SECTION ENDS diff --git a/Language/Variables/Data Types/short.adoc b/Language/Variables/Data Types/short.adoc new file mode 100644 index 000000000..ae5b84a99 --- /dev/null +++ b/Language/Variables/Data Types/short.adoc @@ -0,0 +1,63 @@ +:source-highlighter: pygments +:pygments-style: arduino +:ext-relative: adoc + + += Entity title() + + +// OVERVIEW SECTION STARTS +[#overview] +-- + +[float] +=== Description +A short is a 16-bit data-type. + +On all Arduinos (ATMega and ARM based) a short stores a 16-bit (2-byte) value. This yields a range of -32,768 to 32,767 (minimum value of -2^15 and a maximum value of (2^15) - 1). +[%hardbreaks] + +[float] +=== Syntax +`short var = val;` + +`var` - your short variable name +`val` - the value you assign to that variable +-- +// OVERVIEW SECTION ENDS + + + + +// HOW TO USE SECTION STARTS +[#howtouse] +-- + +[float] +=== Example Code +// Describe what the example code is all about and add relevant code ►►►►► THIS SECTION IS MANDATORY ◄◄◄◄◄ + + +[source,arduino] +---- + short ledPin = 13 +---- +[%hardbreaks] + + +[float] +=== See also +// Link relevant content by category, such as other Reference terms (please add the tag #LANGUAGE#), +// definitions (please add the tag #DEFINITION#), and examples of Projects and Tutorials +// (please add the tag #EXAMPLE#) ►►►►► THIS SECTION IS MANDATORY ◄◄◄◄◄ +[role="definition"] +* #DEFINITION# link:byte{ext-relative}[byte] + +* #DEFINITION# link:int{ext-relative}[int] + +* #DEFINITION# link:unsignedInt{ext-relative}[unsigned int] + +* #DEFINITION# link:long{ext-relative}[long] + +* #DEFINITION# link:unsignedLong{ext-relative}[unsigned long] + +* #DEFINITION# link:integerConstant{ext-relative}[Integer Constants] + +* #DEFINITION# link:unsignedInt{ext-relative}[unsigned int] + +* #DEFINITION# link:variableDeclaration{ext-relative}[Variable Declaration] +-- +// HOW TO USE SECTION ENDS diff --git a/Language/Variables/Data Types/string.adoc b/Language/Variables/Data Types/string.adoc new file mode 100644 index 000000000..07e74a1cb --- /dev/null +++ b/Language/Variables/Data Types/string.adoc @@ -0,0 +1 @@ +// still to write diff --git a/Language/Variables/Data Types/stringObject.adoc b/Language/Variables/Data Types/stringObject.adoc new file mode 100644 index 000000000..1ec831695 --- /dev/null +++ b/Language/Variables/Data Types/stringObject.adoc @@ -0,0 +1,60 @@ +:source-highlighter: pygments +:pygments-style: arduino +:ext-relative: adoc + + += Entity title() + + +// OVERVIEW SECTION STARTS +[#overview] +-- + +[float] +=== Description +The String class, part of the core as of version 0019, allows you to use and manipulate strings of text in more complex ways than character arrays do. You can concatenate Strings, append to them, search for and replace substrings, and more. It takes more memory than a simple character array, but it is also more useful. + +For reference, character arrays are referred to as strings with a small s, and instances of the String class are referred to as Strings with a capital S. Note that constant strings, specified in "double quotes" are treated as char arrays, not instances of the String class. +[%hardbreaks] + +-- +// OVERVIEW SECTION ENDS + + + + +// HOW TO USE SECTION STARTS +[#howtouse] +-- + +[float] +=== Example Code +// Describe what the example code is all about and add relevant code ►►►►► THIS SECTION IS MANDATORY ◄◄◄◄◄ + +[role="example"] +* #EXAMPLE# (http://arduino.cc/en/Tutorial/StringConstructors[StringConstructors^]) +* #EXAMPLE# (http://arduino.cc/en/Tutorial/StringAdditionOperator[StringAdditionOperator^]) +* #EXAMPLE# (http://arduino.cc/en/Tutorial/StringIndexOf[StringIndexOf^]) +* #EXAMPLE# (http://arduino.cc/en/Tutorial/StringAppendOperator[StringAppendOperator^]) +* #EXAMPLE# (http://arduino.cc/en/Tutorial/StringLengthTrim[StringLengthTrim^]) +* #EXAMPLE# (http://arduino.cc/en/Tutorial/StringCaseChanges[StringCaseChanges^]) +* #EXAMPLE# (http://arduino.cc/en/Tutorial/StringReplace[StringReplace^]) +* #EXAMPLE# (http://arduino.cc/en/Tutorial/StringRemove[StringRemove^]) +* #EXAMPLE# (http://arduino.cc/en/Tutorial/StringCharacters[StringCharacters^]) +* #EXAMPLE# (http://arduino.cc/en/Tutorial/StringComparisonOperators[StringStartsWithEndsWith^]) +* #EXAMPLE# (http://arduino.cc/en/Tutorial/StringComparisonOperators[StringComparisonOperators^]) +* #EXAMPLE# (http://arduino.cc/en/Tutorial/StringSubstring[StringSubstring^]) + + + +[float] +=== See also +// Link relevant content by category, such as other Reference terms (please add the tag #LANGUAGE#), +// definitions (please add the tag #DEFINITION#), and examples of Projects and Tutorials +// (please add the tag #EXAMPLE#) ►►►►► THIS SECTION IS MANDATORY ◄◄◄◄◄ +[role="definition"] +* #DEFINITION# link:string{ext-relative}[string] :character arrays + +* #DEFINITION# link:variableDeclaration{ext-relative}[Variable Declaration] + +-- +// HOW TO USE SECTION ENDS diff --git a/Language/Variables/Data Types/unsignedChar.adoc b/Language/Variables/Data Types/unsignedChar.adoc new file mode 100644 index 000000000..475c0bd63 --- /dev/null +++ b/Language/Variables/Data Types/unsignedChar.adoc @@ -0,0 +1,58 @@ +:source-highlighter: pygments +:pygments-style: arduino +:ext-relative: adoc + + += Entity title() + + +// OVERVIEW SECTION STARTS +[#overview] +-- + +[float] +=== Description +An unsigned data type that occupies 1 byte of memory. Same as the link:byte{ext-relative}[byte] datatype. + +The unsigned char datatype encodes numbers from 0 to 255. + +For consistency of Arduino programming style, the byte data type is to be preferred. +[%hardbreaks] + +-- +// OVERVIEW SECTION ENDS + + + + +// HOW TO USE SECTION STARTS +[#howtouse] +-- + +[float] +=== Example Code +// Describe what the example code is all about and add relevant code ►►►►► THIS SECTION IS MANDATORY ◄◄◄◄◄ + + +[source,arduino] +---- +unsigned char myChar = 240; +---- +[%hardbreaks] + + +[float] +=== See also +// Link relevant content by category, such as other Reference terms (please add the tag #LANGUAGE#), +// definitions (please add the tag #DEFINITION#), and examples of Projects and Tutorials +// (please add the tag #EXAMPLE#) ►►►►► THIS SECTION IS MANDATORY ◄◄◄◄◄ +[role="definition"] +* #DEFINITION# link:byte{ext-relative}[byte] + +* #DEFINITION# link:int{ext-relative}[int] + +* #DEFINITION# link:array{ext-relative}[array] + +[role="language"] +* #LANGUAGE# link:println{ext-relative}[Serial.println] + +-- +// HOW TO USE SECTION ENDS diff --git a/Language/Variables/Data Types/unsignedInt.adoc b/Language/Variables/Data Types/unsignedInt.adoc new file mode 100644 index 000000000..1857ae5a2 --- /dev/null +++ b/Language/Variables/Data Types/unsignedInt.adoc @@ -0,0 +1,75 @@ +:source-highlighter: pygments +:pygments-style: arduino +:ext-relative: adoc + + += unsigned int + + +// OVERVIEW SECTION STARTS +[#overview] +-- + +[float] +=== Description +On the Uno and other ATMEGA based boards, unsigned ints (unsigned integers) are the same as ints in that they store a 2 byte value. Instead of storing negative numbers however they only store positive values, yielding a useful range of 0 to 65,535 (2^16) - 1). + +The Due stores a 4 byte (32-bit) value, ranging from 0 to 4,294,967,295 (2^32 - 1). + +The difference between unsigned ints and (signed) ints, lies in the way the highest bit, sometimes refered to as the "sign" bit, is interpreted. In the Arduino int type (which is signed), if the high bit is a "1", the number is interpreted as a negative number, and the other 15 bits are interpreted with (http://en.wikipedia.org/wiki/2%27s_complement[2's complement math]). +[%hardbreaks] + +-- +// OVERVIEW SECTION ENDS + +[float] +=== Syntax +`unsigned int var = val;` +`var` - your unsigned int variable name +`val` - the value you assign to that variable + + +// HOW TO USE SECTION STARTS +[#howtouse] +-- + +[float] +=== Example Code +// Describe what the example code is all about and add relevant code ►►►►► THIS SECTION IS MANDATORY ◄◄◄◄◄ + + +[source,arduino] +---- + unsigned int ledPin = 13; +---- +[%hardbreaks] + +[float] +=== Notes and Warnings +When variables are made to exceed their maximum capacity they "roll over" back to their minimum capacitiy, note that this happens in both directions + +[source,arduino] +---- +unsigned int x + x = 0; + x = x - 1; // x now contains 65535 - rolls over in neg direction + x = x + 1; // x now contains 0 - rolls over +---- + +[%hardbreaks] + +[float] +=== See also +// Link relevant content by category, such as other Reference terms (please add the tag #LANGUAGE#), +// definitions (please add the tag #DEFINITION#), and examples of Projects and Tutorials +// (please add the tag #EXAMPLE#) ►►►►► THIS SECTION IS MANDATORY ◄◄◄◄◄ +[role="definition"] +* #DEFINITION# link:byte{ext-relative}[byte] + +* #DEFINITION# link:int{ext-relative}[int] + +* #DEFINITION# link:Long{ext-relative}[long] + +* #DEFINITION# link:unsignedLong{ext-relative}[unsigned long] + +* #DEFINITION# link:integerConstant{ext-relative}[Integer Constants] + +* #DEFINITION# link:variableDeclaration{ext-relative}[Variable Declaration] + +-- +// HOW TO USE SECTION ENDS diff --git a/Language/Variables/Data Types/unsignedLong.adoc b/Language/Variables/Data Types/unsignedLong.adoc new file mode 100644 index 000000000..4f535eb79 --- /dev/null +++ b/Language/Variables/Data Types/unsignedLong.adoc @@ -0,0 +1,77 @@ +:source-highlighter: pygments +:pygments-style: arduino +:ext-relative: adoc + + += unsigned long + + +// OVERVIEW SECTION STARTS +[#overview] +-- + +[float] +=== Description +Unsigned long variables are extended size variables for number storage, and store 32 bits (4 bytes). Unlike standard longs unsigned longs won't store negative numbers, making their range from 0 to 4,294,967,295 (2^32 - 1). +[%hardbreaks] + +[float] +=== Syntax + +`unsigned long var = val;` + +`var` - your long variable name +`val` - the value you assign to that variable +[%hardbreaks] + +-- +// OVERVIEW SECTION ENDS + + + + +// HOW TO USE SECTION STARTS +[#howtouse] +-- + +[float] +=== Example Code +// Describe what the example code is all about and add relevant code ►►►►► THIS SECTION IS MANDATORY ◄◄◄◄◄ + + +[source,arduino] +---- +unsigned long time; + +void setup() +{ + Serial.begin(9600); +} + +void loop() +{ + Serial.print("Time: "); + time = millis(); + //prints time since program started + Serial.println(time); + // wait a second so as not to send massive amounts of data + delay(1000); +} +---- +[%hardbreaks] + +[float] +=== See also +// Link relevant content by category, such as other Reference terms (please add the tag #LANGUAGE#), +// definitions (please add the tag #DEFINITION#), and examples of Projects and Tutorials +// (please add the tag #EXAMPLE#) ►►►►► THIS SECTION IS MANDATORY ◄◄◄◄◄ + +* #DEFINITION# link:byte{ext-relative}[byte] + +* #DEFINITION# link:int{ext-relative}[int] + +* #DEFINITION# link:unsignedInt{ext-relative}[unsigned int] + +* #DEFINITION# link:long{ext-relative}[long] + +* #DEFINITION# link:integerConstant{ext-relative}[Integer Constants] + +* #DEFINITION# link:variableDeclaration{ext-relative}[Variable Declaration] + +-- +// HOW TO USE SECTION ENDS diff --git a/Language/Variables/Data Types/void.adoc b/Language/Variables/Data Types/void.adoc new file mode 100644 index 000000000..49a459811 --- /dev/null +++ b/Language/Variables/Data Types/void.adoc @@ -0,0 +1,61 @@ +:source-highlighter: pygments +:pygments-style: arduino +:ext-relative: adoc + + += void + + +// OVERVIEW SECTION STARTS +[#overview] +-- + +[float] +=== Description +The `void` keyword is used only in function declarations. It indicates that the function is expected to return no information to the function from which it was called. +[%hardbreaks] + +-- +// OVERVIEW SECTION ENDS + + + + +// HOW TO USE SECTION STARTS +[#howtouse] +-- + +[float] +=== Example Code +// Describe what the example code is all about and add relevant code ►►►►► THIS SECTION IS MANDATORY ◄◄◄◄◄ +The code shows how to use `void`. + +[source,arduino] +---- +// actions are performed in the functions "setup" and "loop" +// but no information is reported to the larger program + +void setup() +{ + // ... +} + +void loop() +{ + // ... +} +---- +[%hardbreaks] + + +[float] +=== See also +// Link relevant content by category, such as other Reference terms (please add the tag #LANGUAGE#), +// definitions (please add the tag #DEFINITION#), and examples of Projects and Tutorials +// (please add the tag #EXAMPLE#) ►►►►► THIS SECTION IS MANDATORY ◄◄◄◄◄ +[role="definition"] +* #DEFINITION# link:functionDeclaration{ext-relative}[function declaration] + + +-- +// HOW TO USE SECTION ENDS diff --git a/Language/Variables/Data Types/word.adoc b/Language/Variables/Data Types/word.adoc new file mode 100644 index 000000000..454bbe1b4 --- /dev/null +++ b/Language/Variables/Data Types/word.adoc @@ -0,0 +1,49 @@ +:source-highlighter: pygments +:pygments-style: arduino +:ext-relative: adoc + + += word + + +// OVERVIEW SECTION STARTS +[#overview] +-- + +[float] +=== Description +A word stores a 16-bit unsigned number, from 0 to 65535. Same as an unsigned int. +[%hardbreaks] + +-- +// OVERVIEW SECTION ENDS + + + + +// HOW TO USE SECTION STARTS +[#howtouse] +-- + +[float] +=== Example Code +// Describe what the example code is all about and add relevant code ►►►►► THIS SECTION IS MANDATORY ◄◄◄◄◄ + + +[source,arduino] +---- + word w = 10000; +---- +[%hardbreaks] + +[float] +=== See also +// Link relevant content by category, such as other Reference terms (please add the tag #LANGUAGE#), +// definitions (please add the tag #DEFINITION#), and examples of Projects and Tutorials +// (please add the tag #EXAMPLE#) ►►►►► THIS SECTION IS MANDATORY ◄◄◄◄◄ +[role="definition"] +* #DEFINITION# link:byte{ext-relative}[byte] + +* #DEFINITION# link:word{ext-relative}[word] + +-- +// HOW TO USE SECTION ENDS diff --git a/Language/Variables/Utilities/PROGMEM.adoc b/Language/Variables/Utilities/PROGMEM.adoc new file mode 100644 index 000000000..979a2ddde --- /dev/null +++ b/Language/Variables/Utilities/PROGMEM.adoc @@ -0,0 +1 @@ +//still to write diff --git a/Language/Variables/Utilities/sizeof.adoc b/Language/Variables/Utilities/sizeof.adoc new file mode 100644 index 000000000..07e74a1cb --- /dev/null +++ b/Language/Variables/Utilities/sizeof.adoc @@ -0,0 +1 @@ +// still to write diff --git a/Language/Variables/Variable Scope & Qualifiers/const.adoc b/Language/Variables/Variable Scope & Qualifiers/const.adoc new file mode 100644 index 000000000..076d197b4 --- /dev/null +++ b/Language/Variables/Variable Scope & Qualifiers/const.adoc @@ -0,0 +1,69 @@ +:source-highlighter: pygments +:pygments-style: arduino +:ext-relative: adoc + + += const keyword + + +// OVERVIEW SECTION STARTS +[#overview] +-- + +[float] +=== Description +The `const` keyword stands for constant. It is a variable _qualifier_ that modifies the behavior of the variable, making a variable "_read-only_". This means that the variable can be used just as any other variable of its type, but its value cannot be changed. You will get a compiler error if you try to assign a value to a `const` variable. + +Constants defined with the const keyword obey the rules of link:scope{ext-relative}[variable scoping] that govern other variables. This, and the pitfalls of using#define, makes the const keyword a superior method for defining constants and is preferred over using link:define{ext-relative}[[#define]. +[%hardbreaks] + +-- +// OVERVIEW SECTION ENDS + + + + +// HOW TO USE SECTION STARTS +[#howtouse] +-- + +[float] +=== Example Code +// Describe what the example code is all about and add relevant code ►►►►► THIS SECTION IS MANDATORY ◄◄◄◄◄ + + +[source,arduino] +---- +const float pi = 3.14; +float x; + +// .... + +x = pi * 2; // it's fine to use const's in math + +pi = 7; // illegal - you can't write to (modify) a constant + + +---- +[%hardbreaks] + +[float] +=== Notes and Warnings +*`#define` or `const`* + +You can use either `const` or `#define` for creating numeric or string constants. For link:array{ext-relative}[arrays], you will need to use `const`. In general `const` is preferred over `#define` for defining constants. +[%hardbreaks] + + +[float] +=== See also +// Link relevant content by category, such as other Reference terms (please add the tag #LANGUAGE#), +// definitions (please add the tag #DEFINITION#), and examples of Projects and Tutorials +// (please add the tag #EXAMPLE#) ►►►►► THIS SECTION IS MANDATORY ◄◄◄◄◄ +[role="language"] +* #LANGUAGE# link:define{ext-relative}[[#define] + +* #LANGUAGE# link:voletile{ext-relative}[voletile] + + +-- +// HOW TO USE SECTION ENDS diff --git a/Language/Variables/Variable Scope & Qualifiers/scope.adoc b/Language/Variables/Variable Scope & Qualifiers/scope.adoc new file mode 100644 index 000000000..3aaabb1fd --- /dev/null +++ b/Language/Variables/Variable Scope & Qualifiers/scope.adoc @@ -0,0 +1,64 @@ +:source-highlighter: pygments +:pygments-style: arduino +:ext-relative: adoc + + += Variable Scope + + +// OVERVIEW SECTION STARTS +[#overview] +-- + +[float] +=== Description +Variables in the C programming language, which Arduino uses, have a property called scope. This is in contrast to early versions of languages such as BASIC where every variable is a _global_ variable. + +A global variable is one that can be seen by every function in a program. Local variables are only visible to the function in which they are declared. In the Arduino environment, any variable declared outside of a function (e.g. setup(), loop(), etc. ), is a _global_ variable. + +When programs start to get larger and more complex, local variables are a useful way to insure that only one function has access to its own variables. This prevents programming errors when one function inadvertently modifies variables used by another function. + +It is also sometimes handy to declare and initialize a variable inside a `for` loop. This creates a variable that can only be accessed from inside the for-loop brackets. +[%hardbreaks] + +-- +// OVERVIEW SECTION ENDS + + + + +// HOW TO USE SECTION STARTS +[#howtouse] +-- + +[float] +=== Example Code +// Describe what the example code is all about and add relevant code ►►►►► THIS SECTION IS MANDATORY ◄◄◄◄◄ + + +[source,arduino] +---- +int gPWMval; // any function will see this variable + +void setup() +{ + // ... +} + +void loop() +{ + int i; // "i" is only "visible" inside of "loop" + float f; // "f" is only "visible" inside of "loop" + // ... + + for (int j = 0; j <100; j++){ + // variable j can only be accessed inside the for-loop brackets + } + +} +---- +[%hardbreaks] + + +-- +// HOW TO USE SECTION ENDS diff --git a/Language/Variables/Variable Scope & Qualifiers/static.adoc b/Language/Variables/Variable Scope & Qualifiers/static.adoc new file mode 100644 index 000000000..4fe2da9a6 --- /dev/null +++ b/Language/Variables/Variable Scope & Qualifiers/static.adoc @@ -0,0 +1,86 @@ +:source-highlighter: pygments +:pygments-style: arduino +:ext-relative: adoc + + += Static + + +// OVERVIEW SECTION STARTS +[#overview] +-- + +[float] +=== Description +The `static` keyword is used to create variables that are visible to only one function. However unlike local variables that get created and destroyed every time a function is called, static variables persist beyond the function call, preserving their data between function calls. + +Variables declared as static will only be created and initialized the first time a function is called. +[%hardbreaks] + +-- +// OVERVIEW SECTION ENDS + + + + +// HOW TO USE SECTION STARTS +[#howtouse] +-- + +[float] +=== Example Code +// Describe what the example code is all about and add relevant code ►►►►► THIS SECTION IS MANDATORY ◄◄◄◄◄ + + +[source,arduino] +---- +/* RandomWalk +* Paul Badger 2007 +* RandomWalk wanders up and down randomly between two +* endpoints. The maximum move in one loop is governed by +* the parameter "stepsize". +* A static variable is moved up and down a random amount. +* This technique is also known as "pink noise" and "drunken walk". +*/ + +#define randomWalkLowRange -20 +#define randomWalkHighRange 20 +int stepsize; + +int thisTime; +int total; + +void setup() +{ + Serial.begin(9600); +} + +void loop() +{ // tetst randomWalk function + stepsize = 5; + thisTime = randomWalk(stepsize); + Serial.println(thisTime); + delay(10); +} + +int randomWalk(int moveSize){ + static int place; // variable to store value in random walk - declared static so that it stores + // values in between function calls, but no other functions can change its value + + place = place + (random(-moveSize, moveSize + 1)); + + if (place < randomWalkLowRange){ // check lower and upper limits + place = place + (randomWalkLowRange - place); // reflect number back in positive direction + } + else if(place > randomWalkHighRange){ + place = place - (place - randomWalkHighRange); // reflect number back in negative direction + } + + return place; +} +---- +[%hardbreaks] + + +-- +// HOW TO USE SECTION ENDS diff --git a/Language/Variables/Variable Scope & Qualifiers/voletile.adoc b/Language/Variables/Variable Scope & Qualifiers/voletile.adoc new file mode 100644 index 000000000..6a8abe6c1 --- /dev/null +++ b/Language/Variables/Variable Scope & Qualifiers/voletile.adoc @@ -0,0 +1,76 @@ +:source-highlighter: pygments +:pygments-style: arduino +:ext-relative: adoc + + += volatile keyword + + +// OVERVIEW SECTION STARTS +[#overview] +-- + +[float] +=== Description +`volatile` is a keyword known as a variable _qualifier_, it is usually used before the datatype of a variable, to modify the way in which the compiler and subsequent program treats the variable. + +Declaring a variable volatile is a directive to the compiler. The compiler is software which translates your C/C++ code into the machine code, which are the real instructions for the Atmega chip in the Arduino. + +Specifically, it directs the compiler to load the variable from RAM and not from a storage register, which is a temporary memory location where program variables are stored and manipulated. Under certain conditions, the value for a variable stored in registers can be inaccurate. + +A variable should be declared volatile whenever its value can be changed by something beyond the control of the code section in which it appears, such as a concurrently executing thread. In the Arduino, the only place that this is likely to occur is in sections of code associated with interrupts, called an interrupt service routine. +[%hardbreaks] + +-- +// OVERVIEW SECTION ENDS + + + + +// HOW TO USE SECTION STARTS +[#howtouse] +-- + +[float] +=== Example Code +// Describe what the example code is all about and add relevant code ►►►►► THIS SECTION IS MANDATORY ◄◄◄◄◄ + + +[source,arduino] +---- +// toggles LED when interrupt pin changes state + +int pin = 13; +volatile int state = LOW; + +void setup() +{ + pinMode(pin, OUTPUT); + attachInterrupt(0, blink, CHANGE); +} + +void loop() +{ + digitalWrite(pin, state); +} + +void blink() +{ + state = !state; +} + +---- +[%hardbreaks] + + +[float] +=== See also +// Link relevant content by category, such as other Reference terms (please add the tag #LANGUAGE#), +// definitions (please add the tag #DEFINITION#), and examples of Projects and Tutorials +// (please add the tag #EXAMPLE#) ►►►►► THIS SECTION IS MANDATORY ◄◄◄◄◄ +[role="language"] +* #LANGUAGE# link:attachInterrupt{ext-relative}[attachInterrupt] + + +-- +// HOW TO USE SECTION ENDS From 0e60ec38df878c6c2140b5ed9874d01671cfb818 Mon Sep 17 00:00:00 2001 From: Akshay Sharma Date: Thu, 19 Feb 2015 18:26:56 +0530 Subject: [PATCH 09/13] FIX Title noTone() --- Language/Functions/Advanced IO/noTone.adoc | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Language/Functions/Advanced IO/noTone.adoc b/Language/Functions/Advanced IO/noTone.adoc index 2b8fba057..4b7b3f9d5 100644 --- a/Language/Functions/Advanced IO/noTone.adoc +++ b/Language/Functions/Advanced IO/noTone.adoc @@ -3,7 +3,7 @@ :ext-relative: adoc -= Entity title() += noTone() // OVERVIEW SECTION STARTS From 4bc572c45ad6bbc000081365fcdd035255b4359d Mon Sep 17 00:00:00 2001 From: Akshay Sharma Date: Thu, 19 Feb 2015 22:58:37 +0530 Subject: [PATCH 10/13] Fix Bugs in various files --- Language/Functions/Analog IO/analogRead.adoc | 2 +- .../Communication/Serial/findUntil.adoc | 4 +- .../Functions/Communication/Serial/print.adoc | 76 +- .../Communication/Stream/streamFindUntil.adoc | 2 +- .../Functions/Digital IO/digitalRead.html | 867 ------------------ .../External Interrupts/attachInterrupt.adoc | 1 + Language/Functions/Math/abs.adoc | 6 +- Language/Functions/Math/map.adoc | 24 +- 8 files changed, 103 insertions(+), 879 deletions(-) delete mode 100644 Language/Functions/Digital IO/digitalRead.html diff --git a/Language/Functions/Analog IO/analogRead.adoc b/Language/Functions/Analog IO/analogRead.adoc index befd7ffb3..07408ec88 100644 --- a/Language/Functions/Analog IO/analogRead.adoc +++ b/Language/Functions/Analog IO/analogRead.adoc @@ -79,7 +79,7 @@ If the analog input pin is not connected to anything, the value returned by anal [role="language"] * #LANGUAGE# link:analogReference{ext-relative}[analogreference()] + * #LANGUAGE# link:analogReadResolution{ext-relative}[analogReadResolution()] + -* #LANGUAGE# (http://arduino.cc/en/Tutorial/AnalogInputPins[Tutorial: Analog Input Pins]) +* #LANGUAGE# http://arduino.cc/en/Tutorial/AnalogInputPins[Tutorial: Analog Input Pins] -- diff --git a/Language/Functions/Communication/Serial/findUntil.adoc b/Language/Functions/Communication/Serial/findUntil.adoc index d9a8890a0..09c10f067 100644 --- a/Language/Functions/Communication/Serial/findUntil.adoc +++ b/Language/Functions/Communication/Serial/findUntil.adoc @@ -12,11 +12,11 @@ [float] === Description -Serial.findUntil() reads data from the serial buffer until a target string of given length or terminator string is found. +`Serial.findUntil()` reads data from the serial buffer until a target string of given length or terminator string is found. The function returns true if the target string is found, false if it times out. -Serial.findUntil() inherits from the link:stream{ext-relative}[Stream] utility class. +`Serial.findUntil()` inherits from the link:stream{ext-relative}[Stream] utility class. [%hardbreaks] diff --git a/Language/Functions/Communication/Serial/print.adoc b/Language/Functions/Communication/Serial/print.adoc index 47824f2eb..00f93ad63 100644 --- a/Language/Functions/Communication/Serial/print.adoc +++ b/Language/Functions/Communication/Serial/print.adoc @@ -12,21 +12,44 @@ [float] === Description +Prints data to the serial port as human-readable ASCII text. This command can take many forms. Numbers are printed using an ASCII character for each digit. Floats are similarly printed as ASCII digits, defaulting to two decimal places. Bytes are sent as a single character. Characters and strings are sent as is. For example- + +* `Serial.print(78) gives "78"` + +* `Serial.print(1.23456) gives "1.23"` + +* `Serial.print('N') gives "N"` + +* `Serial.print("Hello world.") gives "Hello world." ` + +An optional second parameter specifies the base (format) to use; permitted values are `BIN(binary, or base 2)`, `OCT(octal, or base 8)`, `DEC(decimal, or base 10)`, `HEX(hexadecimal, or base 16)`. For floating point numbers, this parameter specifies the number of decimal places to use. For example- + +* `Serial.print(78, BIN) gives "1001110"` + +* `Serial.print(78, OCT) gives "116"` + +* `Serial.print(78, DEC) gives "78"` + +* `Serial.print(78, HEX) gives "4E"` + +* `Serial.println(1.23456, 0) gives "1"` + +* `Serial.println(1.23456, 2) gives "1.23"` + +* `Serial.println(1.23456, 4) gives "1.2346"` + +You can pass flash-memory based strings to Serial.print() by wrapping them with F(). For example : + +`Serial.print(F(“Hello World”))` + +To send a single byte, use link:serialWrite{ext-relative}[Serial.write()]. [%hardbreaks] [float] === Syntax - +`Serial.print(val)` + +`Serial.print(val, format)` [float] === Parameters - +`val`: the value to print - any data type [float] === Returns -Nothing +`size_t (long)`: `print()` returns the number of bytes written, though reading that number is optional. -- // OVERVIEW SECTION ENDS @@ -45,12 +68,59 @@ Nothing [source,arduino] ---- +/* +Uses a FOR loop for data and prints a number in various formats. +*/ +int x = 0; // variable + +void setup() { + Serial.begin(9600); // open the serial port at 9600 bps: +} + +void loop() { + // print labels + Serial.print("NO FORMAT"); // prints a label + Serial.print("\t"); // prints a tab + + Serial.print("DEC"); + Serial.print("\t"); + + Serial.print("HEX"); + Serial.print("\t"); + + Serial.print("OCT"); + Serial.print("\t"); + + Serial.print("BIN"); + Serial.print("\t"); + + for(x=0; x< 64; x++){ // only part of the ASCII chart, change to suit + + // print it out in many formats: + Serial.print(x); // print as an ASCII-encoded decimal - same as "DEC" + Serial.print("\t"); // prints a tab + + Serial.print(x, DEC); // print as an ASCII-encoded decimal + Serial.print("\t"); // prints a tab + + Serial.print(x, HEX); // print as an ASCII-encoded hexadecimal + Serial.print("\t"); // prints a tab + + Serial.print(x, OCT); // print as an ASCII-encoded octal + Serial.print("\t"); // prints a tab + Serial.println(x, BIN); // print as an ASCII-encoded binary + // then adds the carriage return with "println" + delay(200); // delay 200 milliseconds + } + Serial.println(""); // prints another carriage return +} ---- [%hardbreaks] [float] === Notes and Warnings +As of version 1.0, serial transmission is asynchronous; `Serial.print()` will return before any characters are transmitted. [%hardbreaks] [float] diff --git a/Language/Functions/Communication/Stream/streamFindUntil.adoc b/Language/Functions/Communication/Stream/streamFindUntil.adoc index 4044b080e..eb480d84c 100644 --- a/Language/Functions/Communication/Stream/streamFindUntil.adoc +++ b/Language/Functions/Communication/Stream/streamFindUntil.adoc @@ -3,7 +3,7 @@ :ext-relative: adoc -= Entity title() += `findUntil()` // OVERVIEW SECTION STARTS diff --git a/Language/Functions/Digital IO/digitalRead.html b/Language/Functions/Digital IO/digitalRead.html deleted file mode 100644 index b58127b29..000000000 --- a/Language/Functions/Digital IO/digitalRead.html +++ /dev/null @@ -1,867 +0,0 @@ - - - - - -digitalRead() - - - - - -
-
-
-
-
-

Description

-

Reads the value from a specified digital pin, either HIGH or LOW.

-

Syntax

-

digitalRead(pin)

-

Parameters

-

Returns

-

HIGH or LOW

-
-
-
-

Example Code

-

Sets pin 13 to the same value as pin 7, declared as an input.

-
-
-
int ledPin = 13;   // LED connected to digital pin 13
-int inPin = 7;     // pushbutton connected to digital pin 7
-int val = 0;       // variable to store the read value
-
-void setup()
-{
-  pinMode(ledPin, OUTPUT);      // sets the digital pin 13 as output
-  pinMode(inPin, INPUT);        // sets the digital pin 7 as input
-}
-
-void loop()
-{
-  val = digitalRead(inPin);     // read the input pin
-  digitalWrite(ledPin, val);    // sets the LED to the button's value
-}
-
-

Notes and Warnings

-

If the pin isn’t connected to anything, digitalRead() can return either HIGH or LOW (and this can change randomly).

-

The analog input pins can be used as digital pins, referred to as A0, A1, etc.

-

See also

-
-
-
-
-
-

- - - diff --git a/Language/Functions/External Interrupts/attachInterrupt.adoc b/Language/Functions/External Interrupts/attachInterrupt.adoc index e69de29bb..2a2650c1c 100644 --- a/Language/Functions/External Interrupts/attachInterrupt.adoc +++ b/Language/Functions/External Interrupts/attachInterrupt.adoc @@ -0,0 +1 @@ +// still working on this file diff --git a/Language/Functions/Math/abs.adoc b/Language/Functions/Math/abs.adoc index 3c06fa830..d9683f1e3 100644 --- a/Language/Functions/Math/abs.adoc +++ b/Language/Functions/Math/abs.adoc @@ -12,7 +12,7 @@ [float] === Description -Calculates the maximum of two numbers. +Calculates the absolute of two numbers. [%hardbreaks] @@ -22,13 +22,13 @@ Calculates the maximum of two numbers. [float] === Parameters -`x`: the number +`x`: the number [float] === Returns `x`: if x is greater than or equal to 0. -`-x`: if x is less than 0. +`-x`: if x is less than 0. -- // OVERVIEW SECTION ENDS diff --git a/Language/Functions/Math/map.adoc b/Language/Functions/Math/map.adoc index bc75c0cf8..b7212f502 100644 --- a/Language/Functions/Math/map.adoc +++ b/Language/Functions/Math/map.adoc @@ -12,6 +12,10 @@ [float] === Description +Re-maps a number from one range to another. That is, a value of *fromLow* would get mapped to *toLow*, a value of *fromHigh* to *toHigh*, values in-between to values in-between, etc. + +Does not constrain values to within the range, because out-of-range values are sometimes intended and useful. The `constrain()` function may be used either before or after this function, if limits to the ranges are desired. + [%hardbreaks] @@ -22,11 +26,19 @@ [float] === Parameters +`value`: the number to map + +`fromLow`: the lower bound of the value's current range +`fromHigh`: the upper bound of the value's current range + +`toLow`: the lower bound of the value's target range + +`toHigh`: the upper bound of the value's target range [float] === Returns -Nothing +The mapped value. -- // OVERVIEW SECTION ENDS @@ -45,7 +57,15 @@ Nothing [source,arduino] ---- - +/* Map an analog value to 8 bits (0 to 255) */ +void setup() {} + +void loop() +{ + int val = analogRead(0); + val = map(val, 0, 1023, 0, 255); + analogWrite(9, val); +} ---- [%hardbreaks] From 0a4a610ee8406b0dedd8433c42e71f01804b2b8e Mon Sep 17 00:00:00 2001 From: Akshay Sharma Date: Thu, 19 Feb 2015 23:09:28 +0530 Subject: [PATCH 11/13] Fix spelling in millis.adoc --- Language/Functions/Time/millis.adoc | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Language/Functions/Time/millis.adoc b/Language/Functions/Time/millis.adoc index 72e98eed7..3d3fcf4fc 100644 --- a/Language/Functions/Time/millis.adoc +++ b/Language/Functions/Time/millis.adoc @@ -42,7 +42,7 @@ Number of milliseconds since the program started (unsigned long) [float] === Example Code // Describe what the example code is all about and add relevant code ►►►►► THIS SECTION IS MANDATORY ◄◄◄◄◄ -The code reads the milllisecond since the Arduino board bagan. +The code reads the milllisecond since the Arduino board began. [source,arduino] ---- From 0e6fbd96eb2c57c44dba77fe1b209417e8bd2726 Mon Sep 17 00:00:00 2001 From: Akshay Sharma Date: Thu, 19 Feb 2015 23:12:26 +0530 Subject: [PATCH 12/13] Fix spelling cos to cosine --- Language/Functions/Trigonometry/cos.adoc | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Language/Functions/Trigonometry/cos.adoc b/Language/Functions/Trigonometry/cos.adoc index 898e48801..a40e869f8 100644 --- a/Language/Functions/Trigonometry/cos.adoc +++ b/Language/Functions/Trigonometry/cos.adoc @@ -12,7 +12,7 @@ [float] === Description -Calculates the cos of an angle (in radians). The result will be between -1 and 1. +Calculates the cosine of an angle (in radians). The result will be between -1 and 1. [%hardbreaks] From e6356d3e168d3bf88ab2091c940405ee962ba0ff Mon Sep 17 00:00:00 2001 From: Akshay Sharma Date: Thu, 19 Feb 2015 23:34:32 +0530 Subject: [PATCH 13/13] fix title errors in Data Types --- Language/Variables/Data Types/short.adoc | 2 +- Language/Variables/Data Types/stringObject.adoc | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/Language/Variables/Data Types/short.adoc b/Language/Variables/Data Types/short.adoc index ae5b84a99..70d0ef245 100644 --- a/Language/Variables/Data Types/short.adoc +++ b/Language/Variables/Data Types/short.adoc @@ -3,7 +3,7 @@ :ext-relative: adoc -= Entity title() += short // OVERVIEW SECTION STARTS diff --git a/Language/Variables/Data Types/stringObject.adoc b/Language/Variables/Data Types/stringObject.adoc index 1ec831695..897cf85dc 100644 --- a/Language/Variables/Data Types/stringObject.adoc +++ b/Language/Variables/Data Types/stringObject.adoc @@ -3,7 +3,7 @@ :ext-relative: adoc -= Entity title() += String // OVERVIEW SECTION STARTS