from machine import Pin, ADC
from time import sleep
led1 = machine.Pin(14, machine.Pin.OUT)
led2 = machine.Pin(13, machine.Pin.OUT)
led3 = machine.Pin(15, machine.Pin.OUT)
led4 = machine.Pin(19, machine.Pin.OUT)
led5 = machine.Pin(16, machine.Pin.OUT)
led6 = machine.Pin(18, machine.Pin.OUT)
led7 = machine.Pin(17,machine.Pin.OUT)
ledZero = [led1, led2, led3, led5, led6, led7]
ledOne = [led3, led6]
ledTwo = [led1, led3, led4, led5, led7]
ledThree = [led1, led3, led4, led6, led7]
ledFour = [led2, led3, led4, led6]
ledFive = [led1, led2, led4, led6, led7]
ledSix = [led1, led2, led4, led5, led6, led7]
ledSeven = [led1, led3, led6]
ledEight = [led1, led2, led3, led4, led5, led6, led7]
ledNine = [led1, led2, led3, led4, led6, led7]
def zeroLed():
for i in range(len(ledZero)):
ledZero[i].value(True)
def oneLed():
for i in range(len(ledOne)):
ledOne[i].value(True)
def twoLed():
for i in range(len(ledTwo)):
ledTwo[i].value(True)
def threeLed():
for i in range(len(ledThree)):
ledThree[i].value(True)
def fourLed():
for i in range(len(ledFour)):
ledFour[i].value(True)
def fiveLed():
for i in range(len(ledFive)):
ledFive[i].value(True)
def sixLed():
for i in range(len(ledSix)):
ledSix[i].value(True)
def sevenLed():
for i in range(len(ledSeven)):
ledSeven[i].value(True)
def eightLed():
for i in range(len(ledEight)):
ledEight[i].value(True)
def nineLed():
for i in range(len(ledNine)):
ledNine[i].value(True)
def ledsOff():
for i in range(len(ledEight)):
ledEight[i].value(False)
button = machine.Pin(12, machine.Pin.IN, machine.Pin.PULL_DOWN)
potentiometer = ADC(Pin(28))
def ledsOn():
adc = potentiometer.read_u16()
adcVal = adc/16
ledsOff()
if adcVal >= 0 and adcVal < 409:
zeroLed()
elif adcVal >= 409 and adcVal < 818:
oneLed()
elif adcVal >= 818 and adcVal < 1227:
twoLed()
elif adcVal >= 1227 and adcVal < 1636:
threeLed()
elif adcVal >= 1636 and adcVal < 2045:
fourLed()
elif adcVal >= 2045 and adcVal < 2454:
fiveLed()
elif adcVal >= 2454 and adcVal < 2863:
sixLed()
elif adcVal >= 2863 and adcVal < 3272:
sevenLed()
elif adcVal >= 3272 and adcVal < 3681:
eightLed()
elif adcVal >= 3681:
nineLed()
while True:
if button.value() == 1:
ledsOff()
elif button.value() == 0:
ledsOn()
pico:GP0
pico:GP1
pico:GND.1
pico:GP2
pico:GP3
pico:GP4
pico:GP5
pico:GND.2
pico:GP6
pico:GP7
pico:GP8
pico:GP9
pico:GND.3
pico:GP10
pico:GP11
pico:GP12
pico:GP13
pico:GND.4
pico:GP14
pico:GP15
pico:GP16
pico:GP17
pico:GND.5
pico:GP18
pico:GP19
pico:GP20
pico:GP21
pico:GND.6
pico:GP22
pico:RUN
pico:GP26
pico:GP27
pico:GND.7
pico:GP28
pico:ADC_VREF
pico:3V3
pico:3V3_EN
pico:GND.8
pico:VSYS
pico:VBUS
led1:A
led1:C
led3:A
led3:C
led4:A
led4:C
led5:A
led5:C
led6:A
led6:C
led7:A
led7:C
r1:1
r1:2
r2:1
r2:2
r3:1
r3:2
r4:1
r4:2
r5:1
r5:2
r6:1
r6:2
r7:1
r7:2
led8:A
led8:C
btn1:1.l
btn1:2.l
btn1:1.r
btn1:2.r
pot1:GND
pot1:SIG
pot1:VCC