Analog I/O

This library is to input/output an analog signal.

analogReference

Description
Configures the reference voltage used for analog input (i.e. the value used as the top of the input range). When input is the same as the reference voltage, the analogRead function returns 1023. For example, the default is set to the Arduino compatible reference voltage 5.0V; therefore, when 3.3V is applied, 675 is returned. However, note that 5V cannot be applied. When RAW12BIT (for 12-bit A/D conversion) is set to the reference voltage, 4095 is returned.
Syntax
analogReference(uint8_t mode)
Parameters
mode:
   DEFAULT: 5.0V (Arduino compatible)
   INTERNAL: 1.1V (internal voltage)
   EXTERNAL: AVREF pin supply voltage
   RAW12BIT: 3.3V (for 12-bit A/D conversion)
Returns
None

analogRead

Description
Reads the value from the specified analog pin.
Syntax
int analogRead(uint8_t analog_pin)
Parameters
analog_pin: The number of the analog input pin to read from A0 (14) to A5 (19)
Returns
int 0 to 1023; for 12-bit A/D conversion, 0 to 4095

analogWrite

Description
Writes an analog value (PWM wave) to a pin. Can be used to light an LED at varying brightnesses or drive a motor at various speeds. The frequency of the PWM signal is approximately 490Hz.
Syntax
analogWrite(uint8_t pin, int value);
Parameters
pin: The number of the pin to write to (max 20 pins)
value: The duty cycle of the output PWM (0 - 255).
Returns
None

Example

The blue LED on the GR-LYCHEE board lights up smoothly.


#include <Arduino.h>
void setup(){
}
void loop(){
    for(int i = 0; i < 256; i++){
        analogWrite(PIN_LED_YELLOW, i);
        delay(3);
    }
    for(int i = 0; i < 256; i++){
        analogWrite(PIN_LED_YELLOW, 256 - i - 1);
        delay(3);
    }
        
}