tone(), pulseIn(), shiftOut(), shiftIn().
More...
|
| void | tone (uint8_t _pin, unsigned int frequency, unsigned long duration=0) |
| | Plays a square wave (50 % duty) on a pin, for a buzzer or speaker.
|
| void | noTone (uint8_t _pin) |
| | Stops the tone, if one is playing on this pin.
|
| unsigned long | pulseIn (pin_size_t pin, uint8_t state, unsigned long timeout) |
| | Measures how long a pulse on a pin lasts.
|
| unsigned long | pulseInLong (pin_size_t pin, uint8_t state, unsigned long timeout) |
| | Same as pulseIn(); kept for Arduino compatibility.
|
| void | shiftOut (pin_size_t dataPin, pin_size_t clockPin, BitOrder bitOrder, uint8_t val) |
| | Sends a byte one bit at a time, pulsing the clock pin after each bit.
|
| uint8_t | shiftIn (pin_size_t dataPin, pin_size_t clockPin, BitOrder bitOrder) |
| | Reads a byte one bit at a time, pulsing the clock pin for each bit.
|
◆ noTone()
| void noTone |
( |
uint8_t | _pin | ) |
|
Stops the tone, if one is playing on this pin.
- Parameters
-
◆ pulseIn()
| unsigned long pulseIn |
( |
pin_size_t | pin, |
|
|
uint8_t | state, |
|
|
unsigned long | timeout = 1000000L ) |
Measures how long a pulse on a pin lasts.
If the pin is already at state, waits for that pulse to end first, then times the next one. Timing uses the microsecond timer, so it is accurate even with interrupts running. Blocks until the pulse ends or the timeout.
- Parameters
-
| pin | Arduino pin (an input). |
| state | HIGH to time a high pulse, LOW for a low pulse. |
| timeout | Longest time to wait for the whole measurement, in µs; 1000000 (1 s) by default. |
- Returns
- Pulse length in µs, or 0 on timeout or for A3-A5.
◆ pulseInLong()
| unsigned long pulseInLong |
( |
pin_size_t | pin, |
|
|
uint8_t | state, |
|
|
unsigned long | timeout = 1000000L ) |
Same as pulseIn(); kept for Arduino compatibility.
- Parameters
-
| pin | Arduino pin (an input). |
| state | HIGH or LOW. |
| timeout | Longest time to wait, in µs; 1000000 (1 s) by default. |
- Returns
- Pulse length in µs, or 0 on timeout.
◆ shiftIn()
Reads a byte one bit at a time, pulsing the clock pin for each bit.
For shift registers such as the 74HC165. Set the clock pin to OUTPUT and the data pin to INPUT first. Each bit is read while the clock is high.
- Parameters
-
| dataPin | Arduino pin for data. |
| clockPin | Arduino pin for the clock. |
| bitOrder | MSBFIRST or LSBFIRST. |
- Returns
- Byte received.
◆ shiftOut()
Sends a byte one bit at a time, pulsing the clock pin after each bit.
For shift registers such as the 74HC595. Set both pins to OUTPUT first. The data bit is set while the clock is low and read by the chip on the rising edge.
- Parameters
-
| dataPin | Arduino pin for data. |
| clockPin | Arduino pin for the clock. |
| bitOrder | MSBFIRST or LSBFIRST. |
| val | Byte to send. |
◆ tone()
| void tone |
( |
uint8_t | _pin, |
|
|
unsigned int | frequency, |
|
|
unsigned long | duration = 0 ) |
Plays a square wave (50 % duty) on a pin, for a buzzer or speaker.
Returns at once; the tone plays in the background. Only one tone plays at a time: starting a tone stops the previous one, on any pin. When it stops, the pin becomes an input.
The tone uses the pin's PWM slice, so it also changes the frequency of analogWrite() on the other pins of that slice (see analogWrite()).
- Parameters
-
| _pin | Arduino pin. A3-A5 and numbers out of range are ignored. |
| frequency | Frequency in Hz; 0 is ignored. The lowest is about 8 Hz at the default 133 MHz CPU speed. |
| duration | Length in ms; 0 (the default) plays until noTone(). |
- Examples
- AnalogBurst.ino.