Loading...
Searching...
No Matches
Advanced I/O

tone(), pulseIn(), shiftOut(), shiftIn(). More...

Functions

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.

Detailed Description

Function Documentation

◆ noTone()

void noTone ( uint8_t _pin)

Stops the tone, if one is playing on this pin.

Parameters
_pinArduino pin.

◆ 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
pinArduino pin (an input).
stateHIGH to time a high pulse, LOW for a low pulse.
timeoutLongest 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
pinArduino pin (an input).
stateHIGH or LOW.
timeoutLongest time to wait, in µs; 1000000 (1 s) by default.
Returns
Pulse length in µs, or 0 on timeout.

◆ shiftIn()

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.

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
dataPinArduino pin for data.
clockPinArduino pin for the clock.
bitOrderMSBFIRST or LSBFIRST.
Returns
Byte received.

◆ shiftOut()

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.

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
dataPinArduino pin for data.
clockPinArduino pin for the clock.
bitOrderMSBFIRST or LSBFIRST.
valByte 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
_pinArduino pin. A3-A5 and numbers out of range are ignored.
frequencyFrequency in Hz; 0 is ignored. The lowest is about 8 Hz at the default 133 MHz CPU speed.
durationLength in ms; 0 (the default) plays until noTone().
Examples
AnalogBurst.ino.