Skip to content

Instantly share code, notes, and snippets.

@samneggs
Created June 4, 2022 13:34
Show Gist options
  • Save samneggs/e5c19deda44216657cd0b422b570da41 to your computer and use it in GitHub Desktop.
Save samneggs/e5c19deda44216657cd0b422b570da41 to your computer and use it in GitHub Desktop.
LED 64x32 matrix driver and demo.
from machine import Pin, Timer
from time import sleep_ms, sleep_us, ticks_diff, ticks_us, sleep, localtime
from usys import exit
import framebuf, array
from uctypes import addressof
from micropython import const
import _thread
from random import randint
import gc
flag_buffer=bytearray(64*32*2)
flag = framebuf.FrameBuffer(flag_buffer, 60, 32, framebuf.RGB565)
color_l2 = array.array('H', [])
matrix_buffer=bytearray(64*32*2)
matrix = framebuf.FrameBuffer(matrix_buffer, 64, 32, framebuf.RGB565)
text_buffer = bytearray(64*32*2)
big_text = framebuf.FrameBuffer(text_buffer, 64, 32, framebuf.RGB565)
control_asm=array.array('I',(addressof(matrix_buffer),0xD0000000,0x40014000,0,99,0,32,0,0b00000_111111_11111,200,0))
R1 = Pin(2, Pin.OUT)
G1 = Pin(3, Pin.OUT)
B1 = Pin(4, Pin.OUT)
R2 = Pin(5, Pin.OUT)
G2 = Pin(8, Pin.OUT)
B2 = Pin(9, Pin.OUT)
CLK = Pin(11, Pin.OUT)
STB = Pin(12, Pin.OUT)
OE = Pin(13, Pin.OUT)
LINE_A = Pin(10,Pin.OUT)
LINE_B = Pin(16,Pin.OUT)
LINE_C = Pin(18,Pin.OUT)
LINE_D = Pin(20,Pin.OUT)
LINE_E = Pin(22,Pin.OUT)
LED = Pin(25,Pin.OUT)
IR = Pin(28, Pin.IN)
EMPTY = const(0)
WATER_COLOR = const(0b100)
SAND_COLOR = const(0b011)
FIXED_COLOR = const(0b111)
RANDOM_ADR = const(0x4006001c)
HIGH_NIBBLE = const(0b11110000)
LOW_NIBBLE = const(0b00001111)
BLUE = const(0x001f)
BLACK = const(0)
WHITE = const(0xffff)
GREEN = const(0x03e0)#e00A)
BROWN = const(0xe091)
RED = const(0b11111_000000_00000)
YELLOW=const(0xff00)
MAGENTA=const(0x1FF8)
ORANGE = const(0xfc06)
MAXSCREEN_X = const(64)
MAXSCREEN_Y = const(32)
MaxLed = 64
c12 = [0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1]
c13 = [0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0]
T = array.array('h',(2022, 5, 26, 17, 44, 6, 3, 146))
sandctl_asm=array.array('I',(addressof(matrix_buffer),0,64,SAND_COLOR,WATER_COLOR,FIXED_COLOR,RANDOM_ADR,0,0,0))
# http://www.penguintutor.com/programming/picodisplayanimations
def blit_image_file(filename,width,height,cw,ch): # file width, file height, char width, char height
with open (filename, "rb") as file:
file_position = 0
char_position = 0
ecount = 0
current_byte = file.read(4) # header
while file_position < (width * height * 2):
current_byte = file.read(1)
# if eof
if len(current_byte) == 0:
break
# copy to buffer
matrix_buffer[char_position] = ord(current_byte) #and LCD.red
char_position += 1
file_position += 1
if char_position == (cw * ch* 2):
char_position = 0
file.close()
return
@micropython.viper
def line():
global DONE
for n in range(16):#32
OE.value(1)
control_asm[3]=n
rgb_asm(control_asm)
LINE_A.value(n&0b00001)
LINE_B.value(n&0b00010)
LINE_C.value(n&0b00100)
LINE_D.value(n&0b01000)
LINE_E.value(n&0b10000)
OE.value(0)
# for d in range(1): #1
# pass
# OE.value(1)
# for d in range(1): #20
# pass
MATRIX_CTL = const(0) #0
SIO_START_CTL = const(4) #1
GPIO_START_CTL = const(8) #2
LINE_CTL = const(12) #3
DEBUG_CTL = const(16) #4
COUNT_CTL = const(20) #5
SHADES_CTL = const(24) #6
EXIT_CTL = const(28) #7
TEST_CTL = const(32) #8
BRIGHT_CTL = const(36) #9
@micropython.asm_thumb
def rgb_asm(r0):
label(NEW_SCREEN)
ldr(r1,[r0,EXIT_CTL])
cmp(r1,0)
beq(DONT_EXIT)
b(EXIT) # exit from upy
label(DONT_EXIT)
ldr(r4,[r0,LINE_CTL])
ldr(r1,[r0,SIO_START_CTL]) # r1=SIO_START_CTL
mov(r6,1)
lsl(r2,r6,13) # pin 13 (OE)
str(r2,[r1,0x14]) # GPIO_SET Register
mov(r7,r4)
label(CHECK_A)
ror(r7,r6)
bpl(CLEAR_A)
lsl(r2,r6,10) # pin 10 (LINE_A)
str(r2,[r1,0x14]) # GPIO_SET Register
b(CHECK_B)
label(CLEAR_A)
lsl(r2,r6,10) # pin 10 (LINE_A)
str(r2,[r1,0x18]) # GPIO_CLR Register
label(CHECK_B)
ror(r7,r6)
bpl(CLEAR_B)
lsl(r2,r6,16) # pin 16 (LINE_B)
str(r2,[r1,0x14]) # GPIO_SET Register
b(CHECK_C)
label(CLEAR_B)
lsl(r2,r6,16) # pin 16 (LINE_B)
str(r2,[r1,0x18]) # GPIO_CLR Register
label(CHECK_C)
ror(r7,r6)
bpl(CLEAR_C)
lsl(r2,r6,18) # pin 18 (LINE_C)
str(r2,[r1,0x14]) # GPIO_SET Register
b(CHECK_D)
label(CLEAR_C)
lsl(r2,r6,18) # pin 18 (LINE_C)
str(r2,[r1,0x18]) # GPIO_CLR Register
label(CHECK_D)
ror(r7,r6)
bpl(CLEAR_D)
lsl(r2,r6,20) # pin 20 (LINE_D)
str(r2,[r1,0x14]) # GPIO_SET Register
b(CHECK_E)
label(CLEAR_D)
lsl(r2,r6,20) # pin 20 (LINE_D)
str(r2,[r1,0x18]) # GPIO_CLR Register
label(CHECK_E)
ror(r7,r6)
bpl(CLEAR_E)
lsl(r2,r6,22) # pin 22 (LINE_E)
str(r2,[r1,0x14]) # GPIO_SET Register
b(DONE_LINES)
label(CLEAR_E)
lsl(r2,r6,22) # pin 22 (LINE_E)
str(r2,[r1,0x18]) # GPIO_CLR Register
label(DONE_LINES)
mov(r5,1)
lsl(r5,r5,12) # pin 12 (STB)
str(r5,[r1,0x14]) # GPIO_OE_CLR Register
mov(r5,1)
lsl(r5,r5,12) # pin 12 (STB)
str(r5,[r1,0x18]) # GPIO_OUT_SET Register
ldr(r4,[r0,LINE_CTL])
add(r4,1)
cmp(r4,16)
blt(STR_LINE_CTL)
mov(r4,0)
ldr(r1,[r0,SHADES_CTL])
add(r1,1)
cmp(r1,16)
blt(NO_RESET)
mov(r1,0)
label(NO_RESET)
str(r1,[r0,SHADES_CTL]) # 0-16 bright level
label(STR_LINE_CTL)
str(r4,[r0,LINE_CTL]) # 0-63 for line
ldr(r1,[r0,SIO_START_CTL]) # r1=SIO_START_CTL
mov(r2,0) # r2 = 0-64 (x)
label(LOOP)
ldr(r3,[r0,LINE_CTL]) # r3=line (y)
lsl(r3,r3,6) # =line*64
add(r3,r3,r2) # =(line*64)+r2
add(r3,r3,r3) # double ldrh
ldr(r4,[r0,MATRIX_CTL]) # r4=matrix address
add(r3,r3,r4) # r3=pixel address
ldrh(r4,[r3,0]) # r4=pixel data
bl(SETPIXEL1)
mov(r7,1)
lsl(r7,r7,11) # 2048 = 64*16*2
#str(r7,[r0,DEBUG_CTL])
add(r7,r3,r7) # RGB2 part of matrix
ldrh(r4,[r7,0]) # r7=RGB2 matrix pixel
bl(SETPIXEL2)
bl(DO_CLK)
bl(OFF_DELAY)
label(NEXT)
add(r2,1)
cmp(r2,64)#64
blt(LOOP)
mov(r5,1)
lsl(r5,r5,13) # pin 13 (OE)
str(r5,[r1,0x18]) # GPIO_CLR Register
bl(ON_DELAY)
b(NEW_SCREEN)
# -------------------------SUBS---------------------------------
label(DO_CLK)
mov(r5,1)
lsl(r6,r5,11) # pin 11 (CLK)
str(r6,[r1,0x14]) # GPIO_OUT_SET Register
str(r6,[r1,0x18]) # GPIO_OE_CLR Register
bx(lr)
label(ON_DELAY)
#mov(r7,200)#32
ldr(r7,[r0,BRIGHT_CTL])
label(LOOP2)
sub(r7,1)
cmp(r7,0)
bgt(LOOP2)
bx(lr)
label(OFF_DELAY)
mov(r7,1)#32
label(LOOP3)
sub(r7,1)
cmp(r7,0)
bgt(LOOP3)
bx(lr)
label(SETPIXEL1)
ldr(r7,[r0,SHADES_CTL])
lsr(r6,r4,11)#11
cmp(r6,r7)
ble(CLEAR_RED)
mov(r5,1<<2) # pin 2 (R1)
str(r5,[r1,0x14]) # GPIO_OUT_SET Register
b(CHECK_GREEN)
label(CLEAR_RED)
mov(r5,1<<2) # pin 2 (R1)
str(r5,[r1,0x18]) # GPIO_OE_CLR Register
label(CHECK_GREEN)
lsl(r6,r4,21) # clear out red
lsr(r6,r6,27)#26? # clear out blue
cmp(r6,r7)
ble(CLEAR_GREEN)
mov(r5,1<<3) # pin 3 (G1)
str(r5,[r1,0x14]) # GPIO_OUT_SET Register
b(CHECK_BLUE)
label(CLEAR_GREEN)
mov(r5,1<<3) # pin 3 (G1)
str(r5,[r1,0x18]) # GPIO_OE_CLR Register
label(CHECK_BLUE)
lsl(r6,r4,27) # clear red/green
lsr(r6,r6,27)
cmp(r6,r7)
ble(CLEAR_BLUE)
mov(r5,1<<4) # pin 4 (B1)
str(r5,[r1,0x14]) # GPIO_OUT_SET Register
b(PIXEL_DONE)
label(CLEAR_BLUE)
mov(r5,1<<4) # pin 4 (B1)
str(r5,[r1,0x18]) # GPIO_OE_CLR Register
label(PIXEL_DONE)
bx(lr)
label(SETPIXEL2)
ldr(r7,[r0,SHADES_CTL])
lsr(r6,r4,11)#11
cmp(r6,r7)
ble(CLEAR_RED2)
mov(r5,1<<5) # pin 5 (R1)
str(r5,[r1,0x14]) # GPIO_OUT_SET Register
b(CHECK_GREEN2)
label(CLEAR_RED2)
mov(r5,1<<5)
str(r5,[r1,0x18]) # GPIO_OE_CLR Register
label(CHECK_GREEN2)
lsl(r6,r4,21) # clear out red
lsr(r6,r6,27)#26? # clear out blue
cmp(r6,r7)
ble(CLEAR_GREEN2)
mov(r5,1)
lsl(r5,r5,8) # pin 8 (B2)
str(r5,[r1,0x14]) # GPIO_OUT_SET Register
b(CHECK_BLUE2)
label(CLEAR_GREEN2)
mov(r5,1)
lsl(r5,r5,8) # pin 8 (B2)
str(r5,[r1,0x18]) # GPIO_OE_CLR Register
label(CHECK_BLUE2)
lsl(r6,r4,27) # clear red/green
lsr(r6,r6,27)
cmp(r6,r7)
ble(CLEAR_BLUE2)
mov(r5,1)
lsl(r5,r5,9) # pin 9 (G2)
str(r5,[r1,0x14]) # GPIO_OUT_SET Register
b(PIXEL_DONE2)
label(CLEAR_BLUE2)
mov(r5,1)
lsl(r5,r5,9) # pin 9 (g2)
str(r5,[r1,0x18]) # GPIO_OE_CLR Register
label(PIXEL_DONE2)
bx(lr)
label(EXIT)
ldr(r0,[r0,DEBUG_CTL])
# @micropython.asm_thumb
# def test_asm(r0):
# lsl(r0,r0,27)
# lsr(r0,r0,27)
# pass
#
# print(bin(test_asm(0b11100_100011_10100)))
# exit()
def matrix_reset():
MaxLed=64
OE.value(1)
STB.value(0)
CLK.value(0)
for l in range(0, MaxLed):
y = l % 16
R1.value(0)# = False
G1.value(0)# = False
B1.value(0)# = False
R2.value(0)# = False
G2.value(0)# = False
B2.value(0)# = False
if c12[y] == 1:
R1.value(1)# = True
G1.value(1)# = True
B1.value(1)# = True
R2.value(1)# = True
G2.value(1)# = True
B2.value(1)# = True
if l > (MaxLed - 12):
STB.value(1)# = True
else:
STB.value(0)# = False
CLK.value(1)# = True
for delay in range(1000):
pass
#time.sleep(0.001) #(0.000002)
CLK.value(0)# = False
STB.value(0)# = False
CLK.value(0)# = False
for l in range(0, MaxLed):
y = l % 16
R1.value(0)# = False
G1.value(0)# = False
B1.value(0)# = False
R2.value(0)# = False
G2.value(0)# = False
B2.value(0)# = False
if c13[y] == 1:
R1.value(1)# = True
G1.value(1)# = True
B1.value(1)# = True
R2.value(1)# = True
G2.value(1)# = True
B2.value(1)# = True
if l > (MaxLed - 13):
STB.value(1)# = True
else:
STB.value(0)# = False
CLK.value(1)# = True
for delay in range(1000):
pass
#time.sleep(0.000002)
CLK.value(0)# = False
STB.value(0)# = False
CLK.value(0)# = False
@micropython.viper
def resize():
global matrix_buffer,text_buffer
screen_addr=ptr8(matrix_buffer)
text_addr=ptr8(text_buffer)
offset = 0
for y in range(8):
for x in range(32):
byte=text_addr[y*32+x]
color_h = (byte>>4)
color_l = byte&0x111
screen_addr[2*y*32+x] = (color_h<<4) + color_h
screen_addr[2*y*32+x+32] = (color_h<<4) + color_h
screen_addr[2*y*32+x+1] = (color_l<<4) + color_l
screen_addr[2*y*32+x+33] = (color_l<<4) + color_l
@micropython.viper
def water():
global matrix_buffer,text_buffer
screen_addr=ptr8(matrix_buffer)
text_addr=ptr8(text_buffer)
offset = 0
odd = 1
for y in range(31,0,-1):
for x in range(30,0,-1):
source = screen_addr[(y-1)*32+x]
if source == 0:
continue
dest = screen_addr[y*32+x]
dest_m = screen_addr[y*32+x-1]
dest_p = screen_addr[y*32+x+1]
source_m = screen_addr[((y-1)*32)+x-1]
source_p = screen_addr[((y-1)*32)+x+1]
source_high_sand = source & HIGH_NIBBLE == SAND_COLOR<<4
dest_high_water = dest & HIGH_NIBBLE == WATER_COLOR<<4
dest_low_water = dest & LOW_NIBBLE == WATER_COLOR
destm_low_water = dest_m & LOW_NIBBLE == WATER_COLOR
source_low_sand = source & LOW_NIBBLE == SAND_COLOR
dest_low_water = dest & LOW_NIBBLE == WATER_COLOR
destp_high_water = dest_p & HIGH_NIBBLE == WATER_COLOR<<4
dest_high_water = dest & HIGH_NIBBLE == WATER_COLOR<<4
if source & HIGH_NIBBLE < FIXED_COLOR<<4:
if dest & HIGH_NIBBLE == EMPTY or (source_high_sand and dest_high_water) : # check down
dest = dest & LOW_NIBBLE | source & HIGH_NIBBLE
source = source & LOW_NIBBLE
elif dest & LOW_NIBBLE == 0 or (source_high_sand and dest_low_water) : # check down/right
dest = dest & HIGH_NIBBLE | (source>>4)
source = source & LOW_NIBBLE
elif dest_m & LOW_NIBBLE == 0 or (source_high_sand and destm_low_water): # check down/left
dest_m = dest_m & HIGH_NIBBLE | (source>>4)
source = source & LOW_NIBBLE
elif source & HIGH_NIBBLE == WATER_COLOR<<4 and source & LOW_NIBBLE == 0: # water right
source = source>>4
elif source & HIGH_NIBBLE == WATER_COLOR<<4 and source_m & LOW_NIBBLE == 0: # water left
source_m = source_m | WATER_COLOR
source = source & LOW_NIBBLE
if source & LOW_NIBBLE < FIXED_COLOR:
if dest & LOW_NIBBLE == 0 or (source_low_sand and dest_low_water): # check down
dest = dest & HIGH_NIBBLE | source & LOW_NIBBLE
source = source & HIGH_NIBBLE
elif dest_p & HIGH_NIBBLE == 0 or (source_low_sand and destp_high_water): # check down/right
dest_p = dest_p & LOW_NIBBLE | ((source & LOW_NIBBLE) << 4)
source = source & HIGH_NIBBLE
elif dest & HIGH_NIBBLE == 0 or (source_low_sand and dest_high_water): # check down/left
dest = dest & LOW_NIBBLE | ((source & LOW_NIBBLE)<<4)
source = source & HIGH_NIBBLE
elif source & LOW_NIBBLE == WATER_COLOR and source_p & HIGH_NIBBLE == 0 : # water right
source_p = source_p | WATER_COLOR<<4
source = source & HIGH_NIBBLE
elif source & LOW_NIBBLE == WATER_COLOR and source & HIGH_NIBBLE == 0: # water left
source = source<<4
screen_addr[(y-1)*32+x] = source
screen_addr[y*32+x] = dest
screen_addr[y*32+x-1] = dest_m
screen_addr[y*32+x+1] = dest_p
screen_addr[(y-1)*32+x-1] = source_m
screen_addr[(y-1)*32+x+1] = source_p
def core1():
rgb_asm(control_asm)
global DONE,ALIVE
alive_here=ALIVE
count=0
while not DONE:
for i in range(1000):
gticks=ticks_us()
#matrix.pixel(randint(0,63),0,4)
#matrix.pixel(16,0,randint(1,6))
#matrix.pixel(48,0,4)
if count>1 : #randint(1,1)==1:
matrix.fill_rect(randint(1,63),0,1,1,4)
if count==99: #randint(0,200)==20:
matrix.fill_rect(randint(1,50),0,10,10,3)
#matrix.fill_rect(10,0,1,1,3)
#matrix.fill_rect(50,0,5,1,4)
#water()
#line()
#rgb_asm(control_asm)
#count+=1
if count==100:
count=0
fps=1_000_000//ticks_diff(ticks_us(), gticks)
DONE=True
if ALIVE==alive_here:
DONE=True
alive_here=ALIVE
OE.value(1)
DONE=True
#print(fps)
def print_matrix():
for y in range(1):
for x in range(0,64*2,2):
b=matrix_buffer[y*64+x]
print(b,' ',end='')
print(y)
for x in range(0,64*2,2):
b=matrix_buffer[y*64+x+(64*16*2)]
print(b,' ',end='')
print(y)
def get_time(x):
global T
T=localtime()
hr=T[3]
if T[3]>12:
hr=T[3]-12
t_str=str(hr)+":"+str(T[4]) #+':'+str(T[5])
print(t_str)
#print(f"{T:%Y-%m-%d %H:%M:%S")
#matrix.fill_rect(15,10,63,10,0)
#matrix.text(t_str,9,10,7)
#big_text.fill_rect(0,0,63,10,0)
#big_text.text(t_str,0,0,7) #randint(1,7))
#resize()
#print(gc.mem_free())
def fade(input_color1, input_color2):
color1=input_color1
red1 =color1>>11& 0b11111 # extract red #13
green1=color1>>6 & 0b11111 # extract green
blue1 =color1 & 0b11111 # extract blue
color2 = input_color2
red2 =color2>>11& 0b11111 # extract red
green2=color2>>6 & 0b11111 # extract green
blue2 =color2 & 0b11111 # extract blue
inc_red =(red2- red1)/31# 31 # find increment step
inc_green=(green2-green1)/31#31
inc_blue =(blue2- blue1)/31#31
for i in range(0,32):#32
red3 =red1 +int(i*inc_red) # build colors by steps
green3=green1+int(i*inc_green)
blue3 =blue1 +int(i*inc_blue)
color3=red3<<11 | green3<<6 | blue3 # combine RGB
color_l2.append(color3) # byte swap to LCD RGB565
def colors():
c=0
i=0
j=1
z=0
l=len(color_l2)
while(z<l-31):
i+=j
if j>l:
j=0
# if i>64 or i<0:
# j=j* (-1)
c+=1
#control_asm[9]=i<<2
for x in range(64):
matrix.text('PI PICO',3,10,0xffff)
for delay in range(40):
pass
c=(i+(x//2) )% (l-32)
matrix.line(x,0,x,31,color_l2[c+31])
z+=1
def init_fire():
for i in range(0,111,9):
c=((org_rgbs[i]>>4)<<11) | ((org_rgbs[i+1]>>4)<<6) | ((org_rgbs[i+2]>>4))
fire_rgb.append(c)
org_rgbs = [ 0,0,0,
0x07,0x07,0x07,
0x1F,0x07,0x07,
0x2F,0x0F,0x07,
0x47,0x0F,0x07,
0x57,0x17,0x07,
0x67,0x1F,0x07,
0x77,0x1F,0x07,
0x8F,0x27,0x07,
0x9F,0x2F,0x07,
0xAF,0x3F,0x07,
0xBF,0x47,0x07,
0xC7,0x47,0x07,
0xDF,0x4F,0x07,
0xDF,0x57,0x07,
0xDF,0x57,0x07,
0xD7,0x5F,0x07,
0xD7,0x5F,0x07,
0xD7,0x67,0x0F,
0xCF,0x6F,0x0F,
0xCF,0x77,0x0F,
0xCF,0x7F,0x0F,
0xCF,0x87,0x17,
0xC7,0x87,0x17,
0xC7,0x8F,0x17,
0xC7,0x97,0x1F,
0xBF,0x9F,0x1F,
0xBF,0x9F,0x1F,
0xBF,0xA7,0x27,
0xBF,0xA7,0x27,
0xBF,0xAF,0x2F,
0xB7,0xAF,0x2F,
0xB7,0xB7,0x2F,
0xB7,0xB7,0x37,
0xCF,0xCF,0x6F,
0xDF,0xDF,0x9F,
0xEF,0xEF,0xC7,
0xFF,0xFF,0xFF
]
fire_rgb=array.array('H',())
fire_buff=bytearray(MAXSCREEN_X*MAXSCREEN_Y)
@micropython.viper
def drawfire():
texture_addr=ptr16(matrix_buffer)
fire_addr=ptr8(fire_buff)
rgb_addr=ptr16(fire_rgb)
for x in range(0,MAXSCREEN_X):
fire_addr[(MAXSCREEN_Y-1)*MAXSCREEN_X+x]=6 # 35
for x in range(0,MAXSCREEN_X):
for y in range(0,MAXSCREEN_Y): # 100
f_from = y*MAXSCREEN_X+x
if fire_addr[f_from] == 0:
fire_addr[f_from-MAXSCREEN_X]=0
texture_addr[y*MAXSCREEN_X+x] = rgb_addr[fire_addr[0]]
else:
f_to = f_from - MAXSCREEN_X +1 - int(randint(0,3))
fire_addr[f_to] = fire_addr[f_from]- (int(randint(0,3)) & 1)
texture_addr[y*MAXSCREEN_X+x] = rgb_addr[fire_addr[f_to]]
water_buff=bytearray(MAXSCREEN_X*MAXSCREEN_Y)
@micropython.viper
def drawrain():
texture_addr=ptr16(matrix_buffer)
fire_addr=ptr8(water_buff)
color_addr=ptr16(color_l2)
for x in range(0,MAXSCREEN_X):
if int(randint(0,200))==1:
fire_addr[x]=25 # 316
for x in range(0,MAXSCREEN_X):
for y in range(MAXSCREEN_Y-1,-1,-1): # 100
#print(y)
f_from = y*MAXSCREEN_X+x
if fire_addr[f_from] == 0:
fire_addr[f_from]=0
texture_addr[f_from+MAXSCREEN_X] = 0# color_addr[fire_addr[0]]
else:
f_to = f_from + MAXSCREEN_X #- int(randint(0,3))
if fire_addr[f_to]==0:
fire_addr[f_to] = fire_addr[f_from]
else:
fire_addr[f_to] = fire_addr[f_to]-1 #- (int(randint(0,3)) & 1)
texture_addr[f_from] = color_addr[fire_addr[f_from]]
#print('.',end='')
def print_rain():
for y in range(MAXSCREEN_Y):
for x in range(20):
print(fire_buff[y*MAXSCREEN_X+x],' ',end='')
print()
fade(BLACK,GREEN)
#fade(YELLOW,GREEN)
fade(GREEN,BLUE)
fade(BLUE,RED)
fade(RED,GREEN)
print(len(color_l2))
#tim = Timer(period=1000, mode=Timer.PERIODIC, callback=get_time)
matrix_reset()
matrix.fill(0)
get_time(1)
init_fire()
control_asm[9]=200 #100 LED brightness
# blit_image_file("us_flag3.bin",64,32,64,32)
# flag.blit(matrix,0,0)
DONE=False
ALIVE=0
_thread.start_new_thread(core1, ())
c=0
while not DONE:
for pause in range(10000): #10000 fire, 15000 rain
pass
c+=1
if c<200:
drawfire()
elif c<400:
drawrain()
elif c<405:
colors()
elif c<410:
c=0
matrix.text('PI PICO',3,10,0xffff)
#drawrain()
#colors()
ALIVE+=1
if ALIVE>100:
ALIVE=0
print((control_asm[4]))
#tim.deinit()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment