Skip to content

Commit 2232e7c

Browse files
author
Akshay Sharma
committed
Add content Functions/Advanced IO
1 parent cedaeb7 commit 2232e7c

File tree

5 files changed

+400
-0
lines changed

5 files changed

+400
-0
lines changed
Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
:source-highlighter: pygments
2+
:pygments-style: arduino
3+
:ext-relative: adoc
4+
5+
6+
= Entity title()
7+
8+
9+
// OVERVIEW SECTION STARTS
10+
[#overview]
11+
--
12+
13+
[float]
14+
=== Description
15+
Stops the generation of a square wave triggered by `tone()`. Has no effect if no tone is being generated.
16+
[%hardbreaks]
17+
18+
19+
[float]
20+
=== Syntax
21+
`noTone(pin)`
22+
23+
24+
[float]
25+
=== Parameters
26+
`pin`: the pin on which to stop generating the tone
27+
28+
[float]
29+
=== Returns
30+
Nothing
31+
32+
--
33+
// OVERVIEW SECTION ENDS
34+
35+
36+
37+
38+
// HOW TO USE SECTION STARTS
39+
[#howtouse]
40+
--
41+
42+
[float]
43+
=== Notes and Warnings
44+
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.
45+
[%hardbreaks]
46+
47+
[float]
48+
=== See also
49+
// Link relevant content by category, such as other Reference terms (please add the tag #LANGUAGE#),
50+
// definitions (please add the tag #DEFINITION#), and examples of Projects and Tutorials
51+
// (please add the tag #EXAMPLE#) ►►►►► THIS SECTION IS MANDATORY ◄◄◄◄◄
52+
53+
[role="language"]
54+
* #LANGUAGE# link:tone{ext-relative}[tone()]
55+
56+
--
57+
// HOW TO USE SECTION ENDS
Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
1+
:source-highlighter: pygments
2+
:pygments-style: arduino
3+
:ext-relative: adoc
4+
5+
6+
= pulseIn()
7+
8+
9+
// OVERVIEW SECTION STARTS
10+
[#overview]
11+
--
12+
13+
[float]
14+
=== Description
15+
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.
16+
17+
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.
18+
[%hardbreaks]
19+
20+
21+
[float]
22+
=== Syntax
23+
`pulseIn(pin, value)`
24+
25+
`pulseIn(pin, value, timeout)`
26+
27+
[float]
28+
=== Parameters
29+
`pin`: the number of the pin on which you want to read the pulse. (int)
30+
31+
`value`: type of pulse to read: either link:HIGH{ext-relative}[HIGH] or link:LOW{ext-relative}[LOW]. (int)
32+
33+
`timeout` (optional): the number of microseconds to wait for the pulse to start; default is one second (unsigned long)
34+
[float]
35+
=== Returns
36+
the length of the pulse (in microseconds) or 0 if no pulse started before the timeout (unsigned long)
37+
38+
--
39+
// OVERVIEW SECTION ENDS
40+
41+
42+
43+
44+
// HOW TO USE SECTION STARTS
45+
[#howtouse]
46+
--
47+
48+
[float]
49+
=== Example Code
50+
// Describe what the example code is all about and add relevant code ►►►►► THIS SECTION IS MANDATORY ◄◄◄◄◄
51+
The example calculated the time duration of a pulse on pin 7.
52+
53+
[source,arduino]
54+
----
55+
int pin = 7;
56+
unsigned long duration;
57+
58+
void setup()
59+
{
60+
pinMode(pin, INPUT);
61+
}
62+
63+
void loop()
64+
{
65+
duration = pulseIn(pin, HIGH);
66+
}
67+
----
68+
[%hardbreaks]
69+
70+
--
71+
// HOW TO USE SECTION ENDS
Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
:source-highlighter: pygments
2+
:pygments-style: arduino
3+
:ext-relative: adoc
4+
5+
6+
= shiftIn()
7+
8+
9+
// OVERVIEW SECTION STARTS
10+
[#overview]
11+
--
12+
13+
[float]
14+
=== Description
15+
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.
16+
17+
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)`.
18+
19+
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.
20+
[%hardbreaks]
21+
22+
23+
[float]
24+
=== Syntax
25+
`byte incoming = shiftIn(dataPin, clockPin, bitOrder)`
26+
27+
28+
[float]
29+
=== Parameters
30+
`dataPin`: the pin on which to input each bit (int)
31+
32+
`clockPin`: the pin to toggle to signal a read from *dataPin*
33+
34+
`bitOrder`: which order to shift in the bits; either *MSBFIRST* or *LSBFIRST*.
35+
(Most Significant Bit First, or, Least Significant Bit First)
36+
37+
[float]
38+
=== Returns
39+
the value read (byte)
40+
41+
--
42+
// OVERVIEW SECTION ENDS
43+
44+
45+
46+
47+
// HOW TO USE SECTION STARTS
48+
[#howtouse]
49+
--
50+
51+
[float]
52+
=== See also
53+
// Link relevant content by category, such as other Reference terms (please add the tag #LANGUAGE#),
54+
// definitions (please add the tag #DEFINITION#), and examples of Projects and Tutorials
55+
// (please add the tag #EXAMPLE#) ►►►►► THIS SECTION IS MANDATORY ◄◄◄◄◄
56+
57+
[role="language"]
58+
* #LANGUAGE# link:shiftOut{ext-relative}[shiftOut()] +
59+
* #LANGUAGE# link:SPI{ext-relative}[SPI]
60+
61+
--
62+
// HOW TO USE SECTION ENDS
Lines changed: 132 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,132 @@
1+
:source-highlighter: pygments
2+
:pygments-style: arduino
3+
:ext-relative: adoc
4+
5+
6+
= shiftOut()
7+
8+
9+
// OVERVIEW SECTION STARTS
10+
[#overview]
11+
--
12+
13+
[float]
14+
=== Description
15+
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.
16+
17+
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)`.
18+
19+
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.
20+
[%hardbreaks]
21+
22+
23+
[float]
24+
=== Syntax
25+
`shiftOut(dataPin, clockPin, bitOrder, value)`
26+
27+
28+
[float]
29+
=== Parameters
30+
`dataPin`: the pin on which to output each bit (int)
31+
32+
`clockPin`: the pin to toggle once the dataPin has been set to the correct value (int)
33+
34+
`bitOrder`: which order to shift out the bits; either MSBFIRST or LSBFIRST.
35+
(Most Significant Bit First, or, Least Significant Bit First)
36+
37+
`value`: the data to shift out. (byte)
38+
39+
[float]
40+
=== Returns
41+
Nothing
42+
43+
--
44+
// OVERVIEW SECTION ENDS
45+
46+
47+
48+
49+
// HOW TO USE SECTION STARTS
50+
[#howtouse]
51+
--
52+
53+
[float]
54+
=== Example Code
55+
// Describe what the example code is all about and add relevant code ►►►►► THIS SECTION IS MANDATORY ◄◄◄◄◄
56+
For accompanying circuit, see the http://arduino.cc/en/Tutorial/ShiftOut[tutorial on controlling a 74HC595 shift register].
57+
58+
[source,arduino]
59+
----
60+
//**************************************************************//
61+
// Name : shiftOutCode, Hello World //
62+
// Author : Carlyn Maw,Tom Igoe //
63+
// Date : 25 Oct, 2006 //
64+
// Version : 1.0 //
65+
// Notes : Code for using a 74HC595 Shift Register //
66+
// : to count from 0 to 255 //
67+
//****************************************************************
68+
69+
//Pin connected to ST_CP of 74HC595
70+
int latchPin = 8;
71+
//Pin connected to SH_CP of 74HC595
72+
int clockPin = 12;
73+
////Pin connected to DS of 74HC595
74+
int dataPin = 11;
75+
76+
void setup() {
77+
//set pins to output because they are addressed in the main loop
78+
pinMode(latchPin, OUTPUT);
79+
pinMode(clockPin, OUTPUT);
80+
pinMode(dataPin, OUTPUT);
81+
}
82+
83+
void loop() {
84+
//count up routine
85+
for (int j = 0; j < 256; j++) {
86+
//ground latchPin and hold low for as long as you are transmitting
87+
digitalWrite(latchPin, LOW);
88+
shiftOut(dataPin, clockPin, LSBFIRST, j);
89+
//return the latch pin high to signal chip that it
90+
//no longer needs to listen for information
91+
digitalWrite(latchPin, HIGH);
92+
delay(1000);
93+
}
94+
}
95+
----
96+
[%hardbreaks]
97+
98+
[float]
99+
=== Notes and Warnings
100+
The dataPin and clockPin must already be configured as outputs by a call to link:pinMode{ext-relative}[pinMode()].
101+
102+
shiftOut is currently written to output 1 byte (8 bits) so it requires a two step operation to output values larger than 255.
103+
[source,arduino]
104+
----
105+
// Do this for MSBFIRST serial
106+
int data = 500;
107+
// shift out highbyte
108+
shiftOut(dataPin, clock, MSBFIRST, (data >> 8));
109+
// shift out lowbyte
110+
shiftOut(dataPin, clock, MSBFIRST, data);
111+
112+
// Or do this for LSBFIRST serial
113+
data = 500;
114+
// shift out lowbyte
115+
shiftOut(dataPin, clock, LSBFIRST, data);
116+
// shift out highbyte
117+
shiftOut(dataPin, clock, LSBFIRST, (data >> 8));
118+
----
119+
[%hardbreaks]
120+
121+
[float]
122+
=== See also
123+
// Link relevant content by category, such as other Reference terms (please add the tag #LANGUAGE#),
124+
// definitions (please add the tag #DEFINITION#), and examples of Projects and Tutorials
125+
// (please add the tag #EXAMPLE#) ►►►►► THIS SECTION IS MANDATORY ◄◄◄◄◄
126+
127+
[role="language"]
128+
* #LANGUAGE# link:shiftIn{ext-relative}[shiftIn()] +
129+
* #LANGUAGE# link:SPI{ext-relative}[SPI]
130+
131+
--
132+
// HOW TO USE SECTION ENDS

0 commit comments

Comments
 (0)