• sales

    +86-0755-88291180

Case of use #4

2025-04-10 09:17:15 Ask

Just an example of use:


# +------------------------------------------------------------+

# |       K5            ---------      L16  L12  L08  L04  L00 |

# |      [16]          /    AD   \    [11] [15] [20] [22] [28] |

# |                   /     .     \                            |

# | K4    K2    K3   |     /|\     |  [10] [18] [19] [21] [27] |

# |[17]  [13]  [14]  |      .      |                           |

# |                  |      |      |  [09] [07] [05] [03] [01] |

# |       K1          \     |     /                            |

# |      [12]          \   [26]  /    [08] [06] [04] [02] [00] |

# |                     ---------                              |

# +------------------------------------------------------------+

#

# [XX] - GPIOXX


from machine import Pin

import time

import urandom


Blink = Pin("LED", Pin.OUT) # ONBOARD LED


buttonK1 = Pin(12, Pin.IN, Pin.PULL_UP)

buttonK2 = Pin(13, Pin.IN, Pin.PULL_UP)

buttonK3 = Pin(14, Pin.IN, Pin.PULL_UP)

buttonK4 = Pin(17, Pin.IN, Pin.PULL_UP)

buttonK5 = Pin(16, Pin.IN, Pin.PULL_UP)


led=[28,27,01,00,22,21,03,02,20,19,05,04,15,18,07,06,11,10,09,08]


Pin(led[00], Pin.OUT) # 28

Pin(led[01], Pin.OUT) # 27

Pin(led[02], Pin.OUT) #  1

Pin(led[03], Pin.OUT) #  0

Pin(led[04], Pin.OUT) # 22

Pin(led[05], Pin.OUT) # 21

Pin(led[06], Pin.OUT) #  3

Pin(led[07], Pin.OUT) #  2

Pin(led[08], Pin.OUT) # 20

Pin(led[09], Pin.OUT) # 19

Pin(led[10], Pin.OUT) #  5

Pin(led[11], Pin.OUT) #  4

Pin(led[12], Pin.OUT) # 15

Pin(led[13], Pin.OUT) # 18

Pin(led[14], Pin.OUT) #  7

Pin(led[15], Pin.OUT) #  6

Pin(led[16], Pin.OUT) # 11

Pin(led[17], Pin.OUT) # 10

Pin(led[18], Pin.OUT) #  9

Pin(led[19], Pin.OUT) #  8


print("")

print("+-------------------------------------------+")

print("| Press any button to view a random number! |")

print("+-------------------------------------------+")


#--------------------------------------------

def Number0():

#         0 - ZERO

Pin(led[00], Pin.OUT).high()

Pin(led[01], Pin.OUT).high()

Pin(led[02], Pin.OUT).high()

Pin(led[03], Pin.OUT).high()

Pin(led[04], Pin.OUT).high()

Pin(led[05], Pin.OUT).low()

Pin(led[06], Pin.OUT).low()

Pin(led[07], Pin.OUT).high()

Pin(led[08], Pin.OUT).high()

Pin(led[09], Pin.OUT).low()

Pin(led[10], Pin.OUT).low()

Pin(led[11], Pin.OUT).high()

Pin(led[12], Pin.OUT).high()

Pin(led[13], Pin.OUT).low()

Pin(led[14], Pin.OUT).low()

Pin(led[15], Pin.OUT).high()

Pin(led[16], Pin.OUT).high()

Pin(led[17], Pin.OUT).high()

Pin(led[18], Pin.OUT).high()

Pin(led[19], Pin.OUT).high()

#--------------------------------------------

def Number1():

#         1 - ONE

Pin(led[00], Pin.OUT).low()

Pin(led[01], Pin.OUT).low()

Pin(led[02], Pin.OUT).high()

Pin(led[03], Pin.OUT).low()

Pin(led[04], Pin.OUT).low()

Pin(led[05], Pin.OUT).high()

Pin(led[06], Pin.OUT).high()

Pin(led[07], Pin.OUT).low()

Pin(led[08], Pin.OUT).low()

Pin(led[09], Pin.OUT).low()

Pin(led[10], Pin.OUT).high()

Pin(led[11], Pin.OUT).low()

Pin(led[12], Pin.OUT).low()

Pin(led[13], Pin.OUT).low()

Pin(led[14], Pin.OUT).high()

Pin(led[15], Pin.OUT).low()

Pin(led[16], Pin.OUT).low()

Pin(led[17], Pin.OUT).high()

Pin(led[18], Pin.OUT).high()

Pin(led[19], Pin.OUT).high()

#--------------------------------------------

def Number2():

#         2 - TWO

Pin(led[00], Pin.OUT).high()

Pin(led[01], Pin.OUT).high()

Pin(led[02], Pin.OUT).high()

Pin(led[03], Pin.OUT).high()

Pin(led[04], Pin.OUT).low()

Pin(led[05], Pin.OUT).low()

Pin(led[06], Pin.OUT).low()

Pin(led[07], Pin.OUT).high()

Pin(led[08], Pin.OUT).high()

Pin(led[09], Pin.OUT).high()

Pin(led[10], Pin.OUT).high()

Pin(led[11], Pin.OUT).high()

Pin(led[12], Pin.OUT).high()

Pin(led[13], Pin.OUT).low()

Pin(led[14], Pin.OUT).low()

Pin(led[15], Pin.OUT).low()

Pin(led[16], Pin.OUT).high()

Pin(led[17], Pin.OUT).high()

Pin(led[18], Pin.OUT).high()

Pin(led[19], Pin.OUT).high()

#--------------------------------------------

def Number3():

#         3 - THREE

Pin(led[00], Pin.OUT).high()

Pin(led[01], Pin.OUT).high()

Pin(led[02], Pin.OUT).high()

Pin(led[03], Pin.OUT).high()

Pin(led[04], Pin.OUT).low()

Pin(led[05], Pin.OUT).low()

Pin(led[06], Pin.OUT).low()

Pin(led[07], Pin.OUT).high()

Pin(led[08], Pin.OUT).high()

Pin(led[09], Pin.OUT).high()

Pin(led[10], Pin.OUT).high()

Pin(led[11], Pin.OUT).high()

Pin(led[12], Pin.OUT).low()

Pin(led[13], Pin.OUT).low()

Pin(led[14], Pin.OUT).low()

Pin(led[15], Pin.OUT).high()

Pin(led[16], Pin.OUT).high()

Pin(led[17], Pin.OUT).high()

Pin(led[18], Pin.OUT).high()

Pin(led[19], Pin.OUT).high()

#--------------------------------------------

def Number4():

#         4 - FOUR

Pin(led[00], Pin.OUT).high()

Pin(led[01], Pin.OUT).low()

Pin(led[02], Pin.OUT).low()

Pin(led[03], Pin.OUT).high()

Pin(led[04], Pin.OUT).high()

Pin(led[05], Pin.OUT).low()

Pin(led[06], Pin.OUT).low()

Pin(led[07], Pin.OUT).high()

Pin(led[08], Pin.OUT).high()

Pin(led[09], Pin.OUT).high()

Pin(led[10], Pin.OUT).high()

Pin(led[11], Pin.OUT).high()

Pin(led[12], Pin.OUT).low()

Pin(led[13], Pin.OUT).low()

Pin(led[14], Pin.OUT).low()

Pin(led[15], Pin.OUT).high()

Pin(led[16], Pin.OUT).low()

Pin(led[17], Pin.OUT).low()

Pin(led[18], Pin.OUT).low()

Pin(led[19], Pin.OUT).high()

#--------------------------------------------

def Number5():

#         5 - FIVE

Pin(led[00], Pin.OUT).high()

Pin(led[01], Pin.OUT).high()

Pin(led[02], Pin.OUT).high()

Pin(led[03], Pin.OUT).high()

Pin(led[04], Pin.OUT).high()

Pin(led[05], Pin.OUT).low()

Pin(led[06], Pin.OUT).low()

Pin(led[07], Pin.OUT).low()

Pin(led[08], Pin.OUT).high()

Pin(led[09], Pin.OUT).high()

Pin(led[10], Pin.OUT).high()

Pin(led[11], Pin.OUT).high()

Pin(led[12], Pin.OUT).low()

Pin(led[13], Pin.OUT).low()

Pin(led[14], Pin.OUT).low()

Pin(led[15], Pin.OUT).high()

Pin(led[16], Pin.OUT).high()

Pin(led[17], Pin.OUT).high()

Pin(led[18], Pin.OUT).high()

Pin(led[19], Pin.OUT).high()

#--------------------------------------------

def Number6():

#         6 - SIX

Pin(led[00], Pin.OUT).high()

Pin(led[01], Pin.OUT).high()

Pin(led[02], Pin.OUT).high()

Pin(led[03], Pin.OUT).high()

Pin(led[04], Pin.OUT).high()

Pin(led[05], Pin.OUT).low()

Pin(led[06], Pin.OUT).low()

Pin(led[07], Pin.OUT).low()

Pin(led[08], Pin.OUT).high()

Pin(led[09], Pin.OUT).high()

Pin(led[10], Pin.OUT).high()

Pin(led[11], Pin.OUT).high()

Pin(led[12], Pin.OUT).high()

Pin(led[13], Pin.OUT).low()

Pin(led[14], Pin.OUT).low()

Pin(led[15], Pin.OUT).high()

Pin(led[16], Pin.OUT).high()

Pin(led[17], Pin.OUT).high()

Pin(led[18], Pin.OUT).high()

Pin(led[19], Pin.OUT).high()

#--------------------------------------------

def Number7():

#         7 - SEVEN

Pin(led[00], Pin.OUT).high()

Pin(led[01], Pin.OUT).high()

Pin(led[02], Pin.OUT).high()

Pin(led[03], Pin.OUT).high()

Pin(led[04], Pin.OUT).low()

Pin(led[05], Pin.OUT).low()

Pin(led[06], Pin.OUT).low()

Pin(led[07], Pin.OUT).high()

Pin(led[08], Pin.OUT).low()

Pin(led[09], Pin.OUT).low()

Pin(led[10], Pin.OUT).low()

Pin(led[11], Pin.OUT).high()

Pin(led[12], Pin.OUT).low()

Pin(led[13], Pin.OUT).low()

Pin(led[14], Pin.OUT).low()

Pin(led[15], Pin.OUT).high()

Pin(led[16], Pin.OUT).low()

Pin(led[17], Pin.OUT).low()

Pin(led[18], Pin.OUT).low()

Pin(led[19], Pin.OUT).high()

#--------------------------------------------

def Number8():

#         8 - EIGHT

Pin(led[00], Pin.OUT).high()

Pin(led[01], Pin.OUT).high()

Pin(led[02], Pin.OUT).high()

Pin(led[03], Pin.OUT).high()

Pin(led[04], Pin.OUT).high()

Pin(led[05], Pin.OUT).low()

Pin(led[06], Pin.OUT).low()

Pin(led[07], Pin.OUT).high()

Pin(led[08], Pin.OUT).high()

Pin(led[09], Pin.OUT).high()

Pin(led[10], Pin.OUT).high()

Pin(led[11], Pin.OUT).high()

Pin(led[12], Pin.OUT).high()

Pin(led[13], Pin.OUT).low()

Pin(led[14], Pin.OUT).low()

Pin(led[15], Pin.OUT).high()

Pin(led[16], Pin.OUT).high()

Pin(led[17], Pin.OUT).high()

Pin(led[18], Pin.OUT).high()

Pin(led[19], Pin.OUT).high()

#--------------------------------------------

def Number9():

#         9 - NINE

Pin(led[00], Pin.OUT).high()

Pin(led[01], Pin.OUT).high()

Pin(led[02], Pin.OUT).high()

Pin(led[03], Pin.OUT).high()

Pin(led[04], Pin.OUT).high()

Pin(led[05], Pin.OUT).low()

Pin(led[06], Pin.OUT).low()

Pin(led[07], Pin.OUT).high()

Pin(led[08], Pin.OUT).high()

Pin(led[09], Pin.OUT).high()

Pin(led[10], Pin.OUT).high()

Pin(led[11], Pin.OUT).high()

Pin(led[12], Pin.OUT).low()

Pin(led[13], Pin.OUT).low()

Pin(led[14], Pin.OUT).low()

Pin(led[15], Pin.OUT).high()

Pin(led[16], Pin.OUT).high()

Pin(led[17], Pin.OUT).high()

Pin(led[18], Pin.OUT).high()

Pin(led[19], Pin.OUT).high()

#--------------------------------------------

while True:


   if ((buttonK1.value() == 1) &

       (buttonK2.value() == 1) &

       (buttonK3.value() == 1) &

       (buttonK4.value() == 1) &

       (buttonK5.value() == 1)):

       Blink.toggle()

       i = urandom.randint(0, 9)

       if i   < 1:

           Number0()

       elif i < 2:    

           Number1()

       elif i < 3:    

           Number2()

       elif i < 4:    

           Number3()

       elif i < 5:    

           Number4()

       elif i < 6:    

           Number5()

       elif i < 7:    

           Number6()

       elif i < 8:    

           Number7()

       elif i < 9:    

           Number8()

       else:  

           Number9()

       time.sleep(0.02)    

   else:

       Pin(Blink, Pin.OUT).low()

       time.sleep(2)

#--------------------------------------------

Pico all gpio test
0answers