from machine import Pin, ADC, PWM
import time
time.sleep(0.1) # Wait for USB to become ready
print("Hello, Pi Pico!")
# Defining the connections to the board
# Add your connections & pin values
buttonPin = 18
redPin = 0
dialPin = 28
# setup the red LED as a PWM pin
# The brightness of the LED will be determined by the value of the dial
red_led = PWM(Pin(redPin))
red_led.freq(1000)
# setup the dial as an analogue input
dial = ADC(Pin(dialPin))
# setup the button as a digital input
button = Pin(buttonPin, Pin.IN, Pin.PULL_UP)
# How to get the value of the dial
# Delete or comment out (#) these 3 lines once you have the circuit working.
# You need the max value of the dial to complete line 50
while True:
dial_value = dial.read_u16()
print(dial_value)
# Dim the LED based on the value of the dial
# Uncomment these lines once you've got the above code working
# Create a variable to tell us if the led should be on or not
led_on = False
#while True:
# if (button.value() == 0):
# print("Toggled LED")
# # If the LED was on, turn it off
# # If it was off, turn it on
# led_on = not led_on
# time.sleep(0.1)
#
# # If the LED should be on, set it's brightness based on the dial
# if led_on:
# dial_value = dial.read_u16()
# red_led.duty_u16(dial_value)
# # Complete the calculation below to find the brightness percentage
# percentage = dial_value / {Insert Max Value of Dial Here} * 100
#Print the percentage value when the button is pressed
# print(f"LED is at {percentage:.0f}% brightness")
# otherwise turn it off
# else:
# red_led.duty_u16(0)