Skip to content

Commit aaeb5d7

Browse files
committed
2.0.9-alpha-1
1 parent b786da6 commit aaeb5d7

File tree

292 files changed

+14252
-0
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

292 files changed

+14252
-0
lines changed
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
---
2+
title: noTone()
3+
categories: "Functions"
4+
subCategories: "Advanced I/O"
5+
---
6+
7+
# Description
8+
9+
Stops the generation of a square wave triggered by `tone()`. Has no
10+
effect if no tone is being generated.
11+
12+
# Syntax
13+
14+
`noTone(pin)`
15+
16+
# Parameters
17+
18+
`pin`: the Arduino pin on which to stop generating the tone
19+
20+
# Returns
21+
22+
Nothing
23+
24+
# Notes and Warnings
25+
26+
If you want to play different pitches on multiple pins, you need to call
27+
`noTone()` on one pin before calling `tone()` on the next pin.
28+
29+
# See also
30+
Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
---
2+
title: pulseIn()
3+
categories: "Functions"
4+
subCategories: "Advanced I/O"
5+
---
6+
7+
**Description**
8+
9+
Reads a pulse (either `HIGH` or `LOW`) on a pin. For example, if `value`
10+
is `HIGH`, `pulseIn()` waits for the pin to go from `LOW` to `HIGH`,
11+
starts timing, then waits for the pin to go `LOW` and stops timing.
12+
Returns the length of the pulse in microseconds or gives up and returns
13+
0 if no complete pulse was received within the timeout.
14+
15+
The timing of this function has been determined empirically and will
16+
probably show errors in longer pulses. Works on pulses from 10
17+
microseconds to 3 minutes in length.
18+
19+
if the optional timeout is used code will execute faster.
20+
21+
**Syntax**
22+
23+
`pulseIn(pin, value)`
24+
`pulseIn(pin, value, timeout)`
25+
26+
**Parameters**
27+
28+
`pin`: the number of the Arduino pin on which you want to read the
29+
pulse. Allowed data types: `int`.
30+
`value`: type of pulse to read: either
31+
[HIGH](../../../variables/constants/highlow/) or
32+
[LOW](../../../variables/constants/highlow/). Allowed data types:
33+
`int`.
34+
`timeout` (optional): the number of microseconds to wait for the pulse
35+
to start; default is one second. Allowed data types: `unsigned long`.
36+
37+
**Returns**
38+
39+
The length of the pulse (in microseconds) or 0 if no pulse started
40+
before the timeout. Data type: `unsigned long`.
41+
42+
**Example Code**
43+
44+
The example prints the time duration of a pulse on pin 7.
45+
46+
int pin = 7;
47+
unsigned long duration;
48+
49+
void setup() {
50+
Serial.begin(9600);
51+
pinMode(pin, INPUT);
52+
}
53+
54+
void loop() {
55+
duration = pulseIn(pin, HIGH);
56+
Serial.println(duration);
57+
}
58+
59+
**See also**
Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
---
2+
title: pulseInLong()
3+
categories: "Functions"
4+
subCategories: "Advanced I/O"
5+
---
6+
7+
**Description**
8+
9+
`pulseInLong()` is an alternative to [pulseIn()](../pulsein) which is
10+
better at handling long pulse and interrupt affected scenarios.
11+
12+
Reads a pulse (either `HIGH` or `LOW`) on a pin. For example, if `value`
13+
is `HIGH`, `pulseInLong()` waits for the pin to go from `LOW` to `HIGH`,
14+
starts timing, then waits for the pin to go `LOW` and stops timing.
15+
Returns the length of the pulse in microseconds or gives up and returns
16+
0 if no complete pulse was received within the timeout.
17+
18+
The timing of this function has been determined empirically and will
19+
probably show errors in shorter pulses. Works on pulses from 10
20+
microseconds to 3 minutes in length. This routine can be used only if
21+
interrupts are activated. Furthermore the highest resolution is obtained
22+
with large intervals.
23+
24+
**Syntax**
25+
26+
`pulseInLong(pin, value)`
27+
`pulseInLong(pin, value, timeout)`
28+
29+
**Parameters**
30+
31+
`pin`: the number of the Arduino pin on which you want to read the
32+
pulse. Allowed data types: `int`.
33+
`value`: type of pulse to read: either
34+
[HIGH](../../../variables/constants/highlow/) or
35+
[LOW](../../../variables/constants/highlow/). Allowed data types:
36+
`int`.
37+
`timeout` (optional): the number of microseconds to wait for the pulse
38+
to start; default is one second. Allowed data types: `unsigned long`.
39+
40+
**Returns**
41+
42+
The length of the pulse (in microseconds) or 0 if no pulse started
43+
before the timeout. Data type: `unsigned long`.
44+
45+
**Example Code**
46+
47+
The example prints the time duration of a pulse on pin 7.
48+
49+
int pin = 7;
50+
unsigned long duration;
51+
52+
void setup() {
53+
Serial.begin(9600);
54+
pinMode(pin, INPUT);
55+
}
56+
57+
void loop() {
58+
duration = pulseInLong(pin, HIGH);
59+
Serial.println(duration);
60+
}
61+
62+
**Notes and Warnings**
63+
64+
This function relies on `micros()` so cannot be used in
65+
[noInterrupts()](../../interrupts/nointerrupts) context.
66+
67+
**See also**
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
---
2+
title: shiftIn()
3+
categories: "Functions"
4+
subCategories: "Advanced I/O"
5+
---
6+
7+
**Description**
8+
9+
Shifts in a byte of data one bit at a time. Starts from either the most
10+
(i.e. the leftmost) or least (rightmost) significant bit. For each bit,
11+
the clock pin is pulled high, the next bit is read from the data line,
12+
and then the clock pin is taken low.
13+
14+
If you’re interfacing with a device that’s clocked by rising edges,
15+
you’ll need to make sure that the clock pin is low before the first call
16+
to `shiftIn()`, e.g. with a call to `digitalWrite(clockPin, LOW)`.
17+
18+
Note: this is a software implementation; Arduino also provides an [SPI
19+
library](https://www.arduino.cc/en/Reference/SPI) that uses the hardware
20+
implementation, which is faster but only works on specific pins.
21+
22+
**Syntax**
23+
24+
`byte incoming = shiftIn(dataPin, clockPin, bitOrder)`
25+
26+
**Parameters**
27+
28+
`dataPin`: the pin on which to input each bit. Allowed data types:
29+
`int`.
30+
`clockPin`: the pin to toggle to signal a read from **dataPin**.
31+
`bitOrder`: which order to shift in the bits; either **MSBFIRST** or
32+
**LSBFIRST**. (Most Significant Bit First, or, Least Significant Bit
33+
First).
34+
35+
**Returns**
36+
37+
The value read. Data type: `byte`.
38+
39+
**See also**
40+
Lines changed: 104 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,104 @@
1+
---
2+
title: shiftOut()
3+
categories: "Functions"
4+
subCategories: "Advanced I/O"
5+
---
6+
7+
**Description**
8+
9+
Shifts out a byte of data one bit at a time. Starts from either the most
10+
(i.e. the leftmost) or least (rightmost) significant bit. Each bit is
11+
written in turn to a data pin, after which a clock pin is pulsed (taken
12+
high, then low) to indicate that the bit is available.
13+
14+
Note- if you’re interfacing with a device that’s clocked by rising
15+
edges, you’ll need to make sure that the clock pin is low before the
16+
call to `shiftOut()`, e.g. with a call to `digitalWrite(clockPin, LOW)`.
17+
18+
This is a software implementation; see also the [SPI
19+
library](https://www.arduino.cc/en/Reference/SPI), which provides a
20+
hardware implementation that is faster but works only on specific pins.
21+
22+
**Syntax**
23+
24+
`shiftOut(dataPin, clockPin, bitOrder, value)`
25+
26+
**Parameters**
27+
28+
`dataPin`: the pin on which to output each bit. Allowed data types:
29+
`int`.
30+
`clockPin`: the pin to toggle once the dataPin has been set to the
31+
correct value. Allowed data types: `int`.
32+
`bitOrder`: which order to shift out the bits; either MSBFIRST or
33+
LSBFIRST. (Most Significant Bit First, or, Least Significant Bit
34+
First).
35+
`value`: the data to shift out. Allowed data types: `byte`.
36+
37+
**Returns**
38+
39+
Nothing
40+
41+
**Example Code**
42+
43+
For accompanying circuit, see the [tutorial on controlling a 74HC595
44+
shift register](https://arduino.cc/en/Tutorial/ShiftOut).
45+
46+
//**************************************************************//
47+
// Name : shiftOutCode, Hello World //
48+
// Author : Carlyn Maw,Tom Igoe //
49+
// Date : 25 Oct, 2006 //
50+
// Version : 1.0 //
51+
// Notes : Code for using a 74HC595 Shift Register //
52+
// : to count from 0 to 255 //
53+
//****************************************************************
54+
55+
//Pin connected to ST_CP of 74HC595
56+
int latchPin = 8;
57+
//Pin connected to SH_CP of 74HC595
58+
int clockPin = 12;
59+
////Pin connected to DS of 74HC595
60+
int dataPin = 11;
61+
62+
void setup() {
63+
//set pins to output because they are addressed in the main loop
64+
pinMode(latchPin, OUTPUT);
65+
pinMode(clockPin, OUTPUT);
66+
pinMode(dataPin, OUTPUT);
67+
}
68+
69+
void loop() {
70+
//count up routine
71+
for (int j = 0; j < 256; j++) {
72+
//ground latchPin and hold low for as long as you are transmitting
73+
digitalWrite(latchPin, LOW);
74+
shiftOut(dataPin, clockPin, LSBFIRST, j);
75+
//return the latch pin high to signal chip that it
76+
//no longer needs to listen for information
77+
digitalWrite(latchPin, HIGH);
78+
delay(1000);
79+
}
80+
}
81+
82+
**Notes and Warnings**
83+
84+
The dataPin and clockPin must already be configured as outputs by a call
85+
to [pinMode()](../../digital-io/pinmode).
86+
87+
shiftOut is currently written to output 1 byte (8 bits) so it requires a
88+
two step operation to output values larger than 255.
89+
90+
// Do this for MSBFIRST serial
91+
int data = 500;
92+
// shift out highbyte
93+
shiftOut(dataPin, clock, MSBFIRST, (data >> 8));
94+
// shift out lowbyte
95+
shiftOut(dataPin, clock, MSBFIRST, data);
96+
97+
// Or do this for LSBFIRST serial
98+
data = 500;
99+
// shift out lowbyte
100+
shiftOut(dataPin, clock, LSBFIRST, data);
101+
// shift out highbyte
102+
shiftOut(dataPin, clock, LSBFIRST, (data >> 8));
103+
104+
**See also**
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
---
2+
title: Advanced I/O
3+
---
Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
---
2+
title: tone()
3+
categories: "Functions"
4+
subCategories: "Advanced I/O"
5+
---
6+
7+
**Description**
8+
9+
Generates a square wave of the specified frequency (and 50% duty cycle)
10+
on a pin. A duration can be specified, otherwise the wave continues
11+
until a call to [noTone()](../notone). The pin can be connected to a
12+
piezo buzzer or other speaker to play tones.
13+
14+
Only one tone can be generated at a time. If a tone is already playing
15+
on a different pin, the call to `tone()` will have no effect. If the
16+
tone is playing on the same pin, the call will set its frequency.
17+
18+
Use of the `tone()` function will interfere with PWM output on pins 3
19+
and 11 (on boards other than the Mega).
20+
21+
It is not possible to generate tones lower than 31Hz. For technical
22+
details, see [Brett Hagman’s
23+
notes](https://github.com/bhagman/Tone#ugly-details).
24+
25+
**Syntax**
26+
27+
`tone(pin, frequency)`
28+
`tone(pin, frequency, duration)`
29+
30+
**Parameters**
31+
32+
`pin`: the Arduino pin on which to generate the tone.
33+
`frequency`: the frequency of the tone in hertz. Allowed data types:
34+
`unsigned int`.
35+
`duration`: the duration of the tone in milliseconds (optional). Allowed
36+
data types: `unsigned long`.
37+
38+
**Returns**
39+
40+
Nothing
41+
42+
**Notes and Warnings**
43+
44+
- If you want to play different pitches on multiple pins, you need to
45+
call `noTone()` on one pin before calling `tone()` on the next pin.
46+
47+
- This function is non-blocking, which means that even if you provide
48+
the `duration` parameter the sketch execution will continue
49+
immediately even if the tone hasn’t finished playing.
50+
51+
**See also**
52+
53+
- LANGUAGE [analogWrite()](../../analog-io/analogwrite)
54+
55+
- EXAMPLE [Tone
56+
Melody^](https://www.arduino.cc/en/Tutorial/BuiltInExamples/toneMelody)
57+
58+
- EXAMPLE [Pitch
59+
Follower^](https://www.arduino.cc/en/Tutorial/tonePitchFollower)
60+
61+
- EXAMPLE [Tone
62+
Keyboard^](https://www.arduino.cc/en/Tutorial/BuiltInExamples/toneKeyboard)
63+
64+
- EXAMPLE [Tone
65+
Multiple^](https://www.arduino.cc/en/Tutorial/BuiltInExamples/toneMultiple)
66+
67+
- EXAMPLE [PWM^](https://www.arduino.cc/en/Tutorial/PWM)

0 commit comments

Comments
 (0)