class ADC
¶
Example
# Import ADC class
from robot_hat import ADC
# Create ADC object with numeric pin numbering
a0 = ADC(0)
# Create ADC object with named pin numbering
a1 = ADC('A1')
# Read ADC value
value0 = a0.read()
value1 = a1.read()
voltage0 = a0.read_voltage()
voltage1 = a1.read_voltage()
print(f"ADC 0 value: {value0}")
print(f"ADC 1 value: {value1}")
print(f"ADC 0 voltage: {voltage0}")
print(f"ADC 1 voltage: {voltage1}")
API
- class robot_hat.ADC(chn, address=None, *args, **kwargs)¶
Bases:
I2C
Analog to digital converter
- __init__(chn, address=None, *args, **kwargs)¶
Analog to digital converter
- Parameters
chn (int/str) – channel number (0-7/A0-A7)
- read()¶
Read the ADC value
- Returns
ADC value(0-4095)
- Return type
int
- read_voltage()¶
Read the ADC value and convert to voltage
- Returns
Voltage value(0-3.3(V))
- Return type
float