Skip to content

Language content #3

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 13 commits into from
Feb 19, 2015
57 changes: 57 additions & 0 deletions Language/Functions/Advanced IO/noTone.adoc
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
:source-highlighter: pygments
:pygments-style: arduino
:ext-relative: adoc


= noTone()


// 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
71 changes: 71 additions & 0 deletions Language/Functions/Advanced IO/pulseIn.adoc
Original file line number Diff line number Diff line change
@@ -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
62 changes: 62 additions & 0 deletions Language/Functions/Advanced IO/shiftIn.adoc
Original file line number Diff line number Diff line change
@@ -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
132 changes: 132 additions & 0 deletions Language/Functions/Advanced IO/shiftOut.adoc
Original file line number Diff line number Diff line change
@@ -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
Loading