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/
Friday, 10 March 2023
TTB06a: Using 'IF' statements with a Potentiometer in RPi Pico
from machine import Pin
from time import sleep
potPin = 28
myPot = machine.ADC(potPin)
ledR = Pin(2,Pin.OUT)
ledY = Pin(4,Pin.OUT)
ledG = Pin(15,Pin.OUT)
try:
    while True:
        potVal = myPot.read_u16()
        percentage = (-100/65262)*potVal-(-100/65262*272)+100
        if percentage<80:
            ledG.value(1)
            ledY.value(0)
            ledR.value(0)
        if percentage>=80 and percentage <95:
            ledG.value(0)
            ledY.value(1)
            ledR.value(0)
        if percentage>=95:
            ledG.value(0)
            ledY.value(0)
            ledR.value(1)
        print(int(percentage))
        sleep(0.5)
    
except KeyboardInterrupt:
    ledR.value(0)
    ledY.value(0)
    ledG.value(0)
    print('LEDs are off, Goodbye')
          
          
Subscribe to:
Post Comments (Atom)

 
No comments:
Post a Comment