RUI3 (RAK Unified Interface 3) - RAK4631
AnalogIO

Functions

int analogRead (uint8_t pin)
 
void analogReference (eAnalogReference mode)
 
void analogOversampling (uint32_t ulOversampling)
 
void analogWrite (uint8_t pin, int value)
 
void analogReadResolution (uint8_t bits)
 
void analogWriteResolution (uint8_t bits)
 

Detailed Description

Function Documentation

◆ analogRead()

int analogRead ( uint8_t  pin)
Description
Reads the value from the specified analog pin
Syntax
analogRead(pin);
Parameters
pinthe name of the analog input pin to read from
Returns
The analog reading on the pin(Type: int)

◆ analogReference()

void analogReference ( eAnalogReference  mode)
Description
Configures the reference voltage used for analog input
Syntax
analogReference(type);
Parameters
typewhich type of reference to use
Type List:
RAK_ADC_MODE_DEFAULT
RAK_ADC_MODE_3_0
RAK_ADC_MODE_2_4
RAK_ADC_MODE_1_8
RAK_ADC_MODE_1_2
Returns
void

◆ analogOversampling()

void analogOversampling ( uint32_t  ulOversampling)

◆ analogWrite()

void analogWrite ( uint8_t  pin,
int  value 
)
Description
Writes an analog value (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 rectangular wave of the specified duty cycle until the next call to analogWrite()
Syntax
analogWrite(pin, value)
Parameters
pinthe pin which you want to read
valuethe duty cycle: between 0 (always off) and 255 (always on)
Returns
void
Example
int val = 0; // variable to write the LED pin
bool state = false;
bool ledSwitch = false;

void valChage()
{
  state = !state;
  if(val == 0)
    ledSwitch = !ledSwitch;
}

void setup() {
  // put your setup code here, to run once:
  pinMode(GREEN_LED, OUTPUT);
  pinMode(BLUE_LED, OUTPUT);
}

void loop() {
  // put your main code here, to run repeatedly:
  if(val == 0 || val == 255)
     valChage();

  // To determine to make the led lighter or darker
  if(state)
    val++;
  else
    val--;
  // To switch the lighting led
  if(ledSwitch)
    analogWrite(GREEN_LED ,val); // Light the green led
  else
    analogWrite(BLUE_LED, val); //Light the blue led

}

◆ analogReadResolution()

void analogReadResolution ( uint8_t  bits)
Description
analogReadResolution() is an extension of the Analog API for the Zero, Due, MKR family, Nano 33 (BLE and IoT) and Portenta.

Sets the size (in bits) of the value returned by analogRead(). It defaults to 10 bits (returns values between 0-1023) for backward compatibility with AVR based boards.

Syntax
analogReadResolution(bits);
Parameters
bitsdetermines the resolution (in bits) of the value returned by the analogRead() function. You can set this between 1 and 32. You can set resolutions higher than the supported 12 or 16 bits, but values returned by analogRead() will suffer approximation
Returns
void

◆ analogWriteResolution()

void analogWriteResolution ( uint8_t  bits)
Description
analogWriteResolution() is an extension of the Analog API for the Arduino Due.
analogWriteResolution() sets the resolution of the analogWrite() function. It defaults to 8 bits (values between 0-255) for backward compatibility with AVR based boards.
Syntax
analogWriteResolution(bits);
Parameters
bitsdetermines the resolution (in bits) of the values used in the analogWrite() function. The value can range from 1 to 32. If you choose a resolution higher or lower than your board’s hardware capabilities, the value used in analogWrite() will be either truncated if it’s too high or padded with zeros if it’s too low
Returns
void