You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Reads a pulse (either HIGH or LOW) on a pin. For example, if value is HIGH, `pulseInLong()` 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 or 0 if no complete pulse was received within the timeout.
21
+
22
+
The timing of this function has been determined empirically and will probably show errors in shorter pulses. Works on pulses from 10 microseconds to 3 minutes in length. Please also note that if the pin is already high when the function is called, it will wait for the pin to go LOW and then HIGH before it starts counting. This routine can be used only if interrupts are activated. Furthermore the highest resolution is obtained with large intervals.
23
+
[%hardbreaks]
24
+
25
+
26
+
[float]
27
+
=== Syntax
28
+
`pulseInLong(pin, value)`
29
+
30
+
`pulseInLong(pin, value, timeout)`
31
+
32
+
[float]
33
+
=== Parameters
34
+
`pin`: the number of the pin on which you want to read the pulse. (int)
35
+
36
+
`value`: type of pulse to read: either link:../../../variables/constants/constants/[HIGH] or link:../../../variables/constants/constants/[LOW]. (int)
37
+
38
+
`timeout` (optional): the number of microseconds to wait for the pulse to start; default is one second (unsigned long)
39
+
[float]
40
+
=== Returns
41
+
the length of the pulse (in microseconds) or 0 if no pulse started before the timeout (unsigned long)
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
+
The example calculated the time duration of a pulse on pin 7.
57
+
58
+
[source,arduino]
59
+
----
60
+
int pin = 7;
61
+
unsigned long duration;
62
+
63
+
void setup() {
64
+
pinMode(pin, INPUT);
65
+
}
66
+
67
+
void loop() {
68
+
duration = pulseInLong(pin, HIGH);
69
+
}
70
+
----
71
+
[%hardbreaks]
72
+
73
+
[float]
74
+
=== Notes and Warnings
75
+
This function relies on micros() so cannot be used in link:../../interrupts/nointerrupts[noInterrupts()] context.
Copy file name to clipboardExpand all lines: Language/Functions/Advanced IO/shiftIn.adoc
+2-3
Original file line number
Diff line number
Diff line change
@@ -4,8 +4,7 @@ categories: [ "Functions" ]
4
4
subCategories: [ "Advanced I/O" ]
5
5
---
6
6
7
-
:source-highlighter: pygments
8
-
:pygments-style: arduino
7
+
9
8
10
9
11
10
@@ -22,7 +21,7 @@ Shifts in a byte of data one bit at a time. Starts from either the most (i.e. th
22
21
23
22
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)`.
24
23
25
-
Note: this is a software implementation; Arduino also provides an link:../SPI[SPI library] that uses the hardware implementation, which is faster but only works on specific pins.
24
+
Note: this is a software implementation; Arduino also provides an link:https://www.arduino.cc/en/Reference/SPI[SPI library] that uses the hardware implementation, which is faster but only works on specific pins.
Copy file name to clipboardExpand all lines: Language/Functions/Advanced IO/shiftOut.adoc
+2-7
Original file line number
Diff line number
Diff line change
@@ -4,11 +4,6 @@ categories: [ "Functions" ]
4
4
subCategories: [ "Advanced I/O" ]
5
5
---
6
6
7
-
:source-highlighter: pygments
8
-
:pygments-style: arduino
9
-
10
-
11
-
12
7
= shiftOut()
13
8
14
9
@@ -22,7 +17,7 @@ Shifts out a byte of data one bit at a time. Starts from either the most (i.e. t
22
17
23
18
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)`.
24
19
25
-
This is a software implementation; see also the link:../SPI[SPI library], which provides a hardware implementation that is faster but works only on specific pins.
20
+
This is a software implementation; see also the linkhttps://www.arduino.cc/en/Reference/SPI[SPI library], which provides a hardware implementation that is faster but works only on specific pins.
26
21
[%hardbreaks]
27
22
28
23
@@ -103,7 +98,7 @@ void loop() {
103
98
104
99
[float]
105
100
=== Notes and Warnings
106
-
The dataPin and clockPin must already be configured as outputs by a call to link:../digital-io/pinMode[pinMode()].
101
+
The dataPin and clockPin must already be configured as outputs by a call to link:../../digital-io/pinmode[pinMode()].
107
102
108
103
shiftOut is currently written to output 1 byte (8 bits) so it requires a two step operation to output values larger than 255.
Copy file name to clipboardExpand all lines: Language/Functions/Analog IO/analogRead.adoc
+4-5
Original file line number
Diff line number
Diff line change
@@ -4,8 +4,7 @@ categories: [ "Functions" ]
4
4
subCategories: [ "Analog I/O" ]
5
5
---
6
6
7
-
:source-highlighter: pygments
8
-
:pygments-style: arduino
7
+
9
8
10
9
11
10
= analogRead()
@@ -17,7 +16,7 @@ subCategories: [ "Analog I/O" ]
17
16
18
17
[float]
19
18
=== Description
20
-
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[analogReference()]`.
19
+
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[analogReference()]`.
21
20
22
21
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.
23
22
[%hardbreaks]
@@ -86,7 +85,7 @@ If the analog input pin is not connected to anything, the value returned by anal
Copy file name to clipboardExpand all lines: Language/Functions/Analog IO/analogWrite.adoc
+4-5
Original file line number
Diff line number
Diff line change
@@ -4,8 +4,7 @@ categories: [ "Functions" ]
4
4
subCategories: [ "Analog I/O" ]
5
5
---
6
6
7
-
:source-highlighter: pygments
8
-
:pygments-style: arduino
7
+
9
8
10
9
11
10
@@ -18,9 +17,9 @@ subCategories: [ "Analog I/O" ]
18
17
19
18
[float]
20
19
=== Description
21
-
Writes an analog value (http://arduino.cc/en/Tutorial/PWM[PWM wave]) to a pin. Can be used to light a LED at varying brightnesses or drive a motor at various speeds. After a call to `analogWrite()`, the pin will generate a steady square wave of the specified duty cycle until the next call to `analogWrite()` (or a call to `digitalRead()` or `digitalWrite()` on the same pin). The frequency of the PWM signal on most pins is approximately 490 Hz. On the Uno and similar boards, pins 5 and 6 have a frequency of approximately 980 Hz.
20
+
Writes an analog value (http://arduino.cc/en/Tutorial/PWM[PWM wave]) to a pin. Can be used to light a LED at varying brightnesses or drive a motor at various speeds. After a call to `analogWrite()`, the pin will generate a steady square wave of the specified duty cycle until the next call to `analogWrite()` (or a call to `digitalRead()` or `digitalWrite()`) on the same pin. The frequency of the PWM signal on most pins is approximately 490 Hz. On the Uno and similar boards, pins 5 and 6 have a frequency of approximately 980 Hz.
22
21
[%hardbreaks]
23
-
On most Arduino boards (those with the ATmega168 or ATmega328), this function works on pins 3, 5, 6, 9, 10, and 11. On the Arduino Mega, it works on pins 2 - 13 and 44 - 46. Older Arduino boards with an ATmega8 only support `analogWrite()` on pins 9, 10, and 11.
22
+
On most Arduino boards (those with the ATmega168 or ATmega328P), this function works on pins 3, 5, 6, 9, 10, and 11. On the Arduino Mega, it works on pins 2 - 13 and 44 - 46. Older Arduino boards with an ATmega8 only support `analogWrite()` on pins 9, 10, and 11.
24
23
The Arduino DUE supports `analogWrite()` on pins 2 through 13, plus pins DAC0 and DAC1. Unlike the PWM pins, DAC0 and DAC1 are Digital to Analog converters, and act as true analog outputs.
25
24
You do not need to call `pinMode()` to set the pin as an output before calling `analogWrite()`.
26
25
The `analogWrite` function has nothing to do with the analog pins or the `analogRead` function.
@@ -93,7 +92,7 @@ The PWM outputs generated on pins 5 and 6 will have higher-than-expected duty cy
0 commit comments