RUI3 (RAK Unified Interface 3) - RAK4631
AdvancedIO

Functions

void tone (uint8_t pin, uint32_t frequency, uint64_t duration=0)
 
void noTone (uint8_t pin)
 
void shiftOut (uint8_t dataPin, uint8_t clockPin, uint8_t bitOrder, uint8_t val)
 
uint32_t shiftIn (uint8_t dataPin, uint8_t clockPin, uint8_t bitOrder)
 
unsigned long pulseIn (uint8_t pin, uint8_t state, unsigned long timeout=1000000L)
 
unsigned long pulseInLong (uint8_t pin, uint8_t state, unsigned long timeout=1000000L)
 

Detailed Description

Function Documentation

◆ tone()

void tone ( uint8_t  pin,
uint32_t  frequency,
uint64_t  duration = 0 
)
Description
Generates a square wave of the specified frequency (and 50% duty cycle) on a pin. A duration can be specified, otherwise the wave continues until a call to noTone().

Only one tone can be generated at a time. If a tone is already playing on a different pin, the call to tone() will have no effect. If the tone is playing on the same pin, the call will set its frequency.

Syntax
tone(pin, frequency);
tone(pin, frequency, duration);
Parameters
pinThe device pin on which to generate the tone
frequencyThe frequency of the tone in hertz
duration(optional)The duration of the tone in milliseconds(default = no timeout)
Returns
void
Example
uint8_t ledPin = 36; 
uint8_t pulsePin = 13;
unsigned long duration;

void setup() {
  Serial.begin(115200);
  pinMode(pulsePin, INPUT_PULLUP);
  pinMode(ledPin, OUTPUT);
}

void loop() {
  duration = pulseIn(pulsePin, LOW);
  Serial.print("Pulse duration = ");
  Serial.print((float)duration/1000000);
  Serial.println(" sec");

  if(duration >= 15000000)
    noTone(ledPin);
  else if(duration >= 10000000)
    tone(ledPin, 494, 5000);
  else if(duration >= 5000000)
    tone(ledPin, 494);
}

◆ noTone()

void noTone ( uint8_t  pin)
Description
Stops the generation of a square wave triggered by tone()
Syntax
noTone(pin);
Parameters
pinThe device pin on which to stop generating the tone
Returns
void
Example
uint8_t ledPin = 36;
uint8_t pulsePin = 13;
unsigned long duration;

void setup() {
  Serial.begin(115200);
  pinMode(pulsePin, INPUT_PULLUP);
  pinMode(ledPin, OUTPUT);
}

void loop() {
  duration = pulseIn(pulsePin, LOW);
  Serial.print("Pulse duration = ");
  Serial.print((float)duration/1000000);
  Serial.println(" sec");

  if(duration >= 15000000)
    noTone(ledPin);
  else if(duration >= 10000000)
    tone(ledPin, 494, 5000);
  else if(duration >= 5000000)
    tone(ledPin, 494);
}

◆ shiftOut()

void shiftOut ( uint8_t  dataPin,
uint8_t  clockPin,
uint8_t  bitOrder,
uint8_t  val 
)
Description
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.
Syntax
shiftOut(dataPin, clockPin, bitOrder, val);
Parameters
dataPinthe pin on which to output each bit
clockPinthe pin to toggle once the dataPin has been set to the correct value
bitOrderwhich order to shift out the bits; either MSBFIRST or LSBFIRST
valthe data to shift out
Returns
void

◆ shiftIn()

uint32_t shiftIn ( uint8_t  dataPin,
uint8_t  clockPin,
uint8_t  bitOrder 
)
Description
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.
Syntax
byte incoming = shiftIn(dataPin, clockPin, bitOrder);
Parameters
dataPinthe pin on which to output each bit
cloackPinthe pin to toggle once the dataPin has been set to the correct value
bitOrderwhich order to shift out the bits; either MSBFIRST or LSBFIRST
Returns
The value read(Type: byte);

◆ pulseIn()

unsigned long pulseIn ( uint8_t  pin,
uint8_t  state,
unsigned long  timeout = 1000000L 
)
Description
Reads a pulse (either HIGH or LOW) on a pin. For example, if value is HIGH, pulseIn() waits for the pin to go from LOW to HIGH, starts timing, then waits for the pin to go LOW and stops timing. Returns the length of the pulse in microseconds or gives up and returns 0 if no complete pulse was received within the timeout.
Syntax
pulseIn(pin, state);
pulseIn(pin, state, timeout);
Parameters
pinthe pin on which you want to read a pulse
statetype of pulse to read: either HIGH or LOW
timeout(optional)the number of microseconds to wait for the pulse to start; default is one second
Returns
The length of the pulse (in microseconds) or 0 if no pulse started before the timeout(Type: unsgined long)
Example
uint8_t ledPin = 36;
uint8_t pulsePin = 13;
unsigned long duration;

void setup() {
  Serial.begin(115200);
  pinMode(pulsePin, INPUT_PULLUP);
  pinMode(ledPin, OUTPUT);
}

void loop() {
  duration = pulseIn(pulsePin, LOW);
  Serial.print("Pulse duration = ");
  Serial.print((float)duration/1000000);
  Serial.println(" sec");

  if(duration >= 15000000)
    noTone(ledPin);
  else if(duration >= 10000000)
    tone(ledPin, 494, 5000);
  else if(duration >= 5000000)
    tone(ledPin, 494);
}

◆ pulseInLong()

unsigned long pulseInLong ( uint8_t  pin,
uint8_t  state,
unsigned long  timeout = 1000000L 
)
Description
pulseInLong() is an alternative to pulseIn() which is better at handling long pulse and interrupt affected scenarios
Syntax
pulseInLong(pin, state);
pulseInLong(pin, state, timeout);
Parameters
pinthe pin on which you want to read a pulse
statetype of pulse to read: either HIGH or LOW
timeout(optional)the number of microseconds to wait for the pulse to start; default is one second
Returns
The length of the pulse (in microseconds) or 0 if no pulse started before the timeout(Type: unsigned long)