| Ligne 195 : |
Ligne 195 : |
| | from random import randint | | from random import randint |
| | from machine import Pin | | from machine import Pin |
| − |
| |
| | micropython.alloc_emergency_exception_buf(100) | | micropython.alloc_emergency_exception_buf(100) |
| | | | |
| Ligne 204 : |
Ligne 203 : |
| | counter += 1 | | counter += 1 |
| | | | |
| − | # https://docs.micropython.org/en/latest/library/machine.Pin.html
| |
| − | # https://docs.micropython.org/en/latest/reference/isr_rules.html
| |
| | btn = Pin( Pin.board.GP10, Pin.IN, Pin.PULL_UP ) | | btn = Pin( Pin.board.GP10, Pin.IN, Pin.PULL_UP ) |
| | btn.irq( handler=bouton_cb, trigger=Pin.IRQ_FALLING ) | | btn.irq( handler=bouton_cb, trigger=Pin.IRQ_FALLING ) |
| − |
| |
| | LEDs = [ Pin(Pin.board.GP27, Pin.OUT), Pin(Pin.board.GP26, Pin.OUT), | | LEDs = [ Pin(Pin.board.GP27, Pin.OUT), Pin(Pin.board.GP26, Pin.OUT), |
| | Pin(Pin.board.GP22, Pin.OUT) ] | | Pin(Pin.board.GP22, Pin.OUT) ] |
| Ligne 217 : |
Ligne 213 : |
| | while True: | | while True: |
| | if counter>0: # Button pressed? | | if counter>0: # Button pressed? |
| − | # Random number
| |
| | new_value = randint(1,6) | | new_value = randint(1,6) |
| | while new_value == old_value: | | while new_value == old_value: |
| | new_value = randint(1,6) | | new_value = randint(1,6) |
| − |
| + | |
| − | # show the number
| |
| | old_value = new_value | | old_value = new_value |
| | print( 'Random = %i = %s' % (new_value,bin(new_value)) ) | | print( 'Random = %i = %s' % (new_value,bin(new_value)) ) |
| − | # Show the LED value
| + | |
| | s = bin(new_value).replace( '0b','' ) | | s = bin(new_value).replace( '0b','' ) |
| | s = '%3s' % s | | s = '%3s' % s |
| Ligne 236 : |
Ligne 230 : |
| | time.sleep_ms( 500 ) | | time.sleep_ms( 500 ) |
| | # Reset button detection | | # Reset button detection |
| − | counter=0 | + | counter=0 |
| − |
| |
| | else: | | else: |
| | time.sleep_ms(200) | | time.sleep_ms(200) |