This blog is a record of what I do, what I think and what I read. If you are interested to know about my professional experience, you can refer to the other blog of mine. http://admi2camac.blogspot.com/
Saturday, 4 March 2023
TTB05: Reading Analog Voltages Using a Potentiometer
import machine
from time import sleep
potPin = 28
myPot = machine.ADC(potPin)
while True:
potVal=myPot.read_u16()
#print('PotVal =',potVal)
#max=65535, min=1024, middle=65535-1024=64511
voltage = (3.3/64511)*potVal - (1024*3.3/64511)
#print('Voltage =',voltage)
percentage = (100/64511)*potVal-(1024*100/64511)
#print('Percentage = ',int(percentage))
print('PotVal =',potVal, 'Voltage =',voltage, 'Percentage = ',int(percentage))
sleep(1)
#https://www.youtube.com/watch?v=ODWwErH_iGA&list=PLGs0VKk2DiYz8js1SJog21cDhkBqyAhC5&index=5
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment