QMK can leverage the Analog-to-Digital Converter (ADC) on supported MCUs to measure voltages on certain pins. This can be useful for implementing things such as battery level indicators for Bluetooth keyboards, or volume controls using a potentiometer, as opposed to a rotary encoder.
This driver is currently AVR-only. The values returned are 10-bit integers (0-1023) mapped between 0V and VCC (usually 5V or 3.3V).
To use this driver, add the following to your
SRC += analog.c
Then place this include at the top of your code:
* The ATmega328P possesses two extra ADC channels; however, they are not present on the DIP pinout, and are not shared with GPIO pins. You can use
adc_read() directly to gain access to these.
Sets the analog voltage reference source. Must be one of
Reads the value from the specified Arduino pin, eg.
Reads the value from the specified QMK pin, eg.
Translates a given QMK pin to a mux value. If an unsupported pin is given, returns the mux value for "0V (GND)".
Reads the value from the ADC according to the specified mux. See your MCU's datasheet for more information.