from machine import Pin
from time import sleep_ms
def init_led():
global led
global key
led8 = Pin(13,Pin.OUT)
led7 = Pin(12,Pin.OUT)
led6 = Pin(14,Pin.OUT)
led5 = Pin(27,Pin.OUT)
led4 = Pin(26,Pin.OUT)
led3 = Pin(25,Pin.OUT)
led2 = Pin(33,Pin.OUT)
led1 = Pin(32,Pin.OUT)
led = [led1,led2,led3,led4,led5,led6,led7,led8]
key1 = Pin(21,Pin.IN,Pin.PULL_UP)
key2 = Pin(19,Pin.IN,Pin.PULL_UP)
key3 = Pin(18,Pin.IN,Pin.PULL_UP)
key4 = Pin(5 ,Pin.IN,Pin.PULL_UP)
key = [key1,key2,key3,key4]
def show(dat):
for i in range(1,len(led)):
temp = dat >> i
print("模式4")
if (temp & 0x01) == 0:
led[i].value(0)
else:
led[i].value(1)
def show1():
print(key[0].value())
while key[0].value() == 0:
for i in led:
i.value(1)
sleep_ms(300)
print("模式1")
for i in led:
i.value(0)
sleep_ms(300)
def show2():
print(key[1].value())
while key[1].value() == 0:
for i in reversed(led):
i.value(1)
sleep_ms(300)
print("模式2")
for i in reversed(led):
i.value(0)
sleep_ms(300)
def show3():
print(key[2].value())
while key[2].value() == 0:
for i in range(1,len(led),2):
led[i].value(1)
sleep_ms(300)
print("模式3")
def show4():
print(key[3].value())
while key[3].value() == 0:
show(0x55);sleep_ms(300)
show(0xaa);sleep_ms(300)
show(0x33);sleep_ms(300)
show(0xcc);sleep_ms(300)
def main():
init_led()
while True:
for i in led:
show1()
show2()
show3()
show4()
i.value(0)
if __name__ == "__main__":
main()