Created
July 5, 2024 10:53
-
-
Save qbalsdon/0e88509ecf5c79d788f27df8ce081393 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# PicoBricks read value from potentiometer and output to serial | |
# Thonny IDE | |
# Helpful reference: https://www.halvorsen.blog/documents/technology/iot/pico/pico_potentiometer.php | |
from machine import ADC | |
import utime | |
VOLTAGE = 3.3 # from the power source | |
INT_MAX = 65535.0 # 2^16 is the max value for integers | |
adcpin = 26 | |
pot = ADC(adcpin) | |
def pot2Percent(rawPotValue): | |
return rawPotValue / INT_MAX * 100.0 | |
while True: | |
adc_value = pot.read_u16() | |
# volt = (VOLTAGE / INT_MAX) * adc_value # original method | |
print(pot2Percent(adc_value)) | |
utime.sleep(1) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment