from rp2 import PIO, asm_pio, StateMachine from machine import Pin from time import sleep_ms FIRST_PIN = Pin(12) # a b f g e d dp c DIGITS = [ 0b00010000, 0b10111100, 0b00100001, 0b00101000, 0b10001100, 0b01001000, 0b01000000, 0b00111100, 0b00000000, 0b00001000, ] PATTERN = [ 0b00111111, 0b10101111, 0b11100111, 0b11110011, 0b11111010, 0b11101110, 0b11001111, 0b01011111 ] PATTERN_ENDING = [ 0b00111111, 0b10101111, 0b11100111, 0b11110011, 0b11111001, 0b11111101, 0b11111111 ] COUNT_START = [ 0b11111101, 0b11111000, 0b10110000, 0b00010000, ] COUNT_END = [ 0b00001000, 0b00001100, 0b00001111, 0b01001111, 0b11001111, 0b11101111, 0b11111111 ] @asm_pio(out_init=(PIO.OUT_HIGH,) * 8, out_shiftdir=PIO.SHIFT_RIGHT, autopull=True, pull_thresh=8) def prog(): # you can remove autopull and place pull() here out(pins, 8) # and that's it! easier than classic code! sm = StateMachine(0, prog, out_base=FIRST_PIN) sm.active(1) for _ in range(5): for i in range(len(PATTERN)): sm.put(PATTERN[i]) sleep_ms(100) for i in range(len(PATTERN_ENDING)): sm.put(PATTERN_ENDING[i]) sleep_ms(100) sleep_ms(700) for i in range(len(COUNT_START)): sm.put(COUNT_START[i]) sleep_ms(100) for i in range(20): d = DIGITS[i // 2] ^ ((i % 2) << 1) sm.put(d) sleep_ms(500) for i in range(len(COUNT_END)): sm.put(COUNT_END[i]) sleep_ms(100)