import time
time.sleep(0.1) # Wait for USB to become ready
print('Starting')
from picolcd import *
from boxes_buffer import *
if __name__ == '__main__':
print('Testing')
display = GraphicLCD(width=240,height=240)
buffer_width = 240
buffer_height = 240
try:
boxes = [Box(buffer_width - 1, buffer_height - 1, randint(7, 40), display,
display.color565(randint(30, 256), randint(30, 256), randint(30, 256))) for i in range(50)]
# print(free())
start_time = ticks_us()
frame_count = 0
while True:
for b in boxes:
b.update_pos()
for b in boxes:
b.draw()
# render display
display.show()
display.fill(0)
frame_count += 1
if frame_count == 100:
frame_rate = 100 / ((ticks_us() - start_time) / 1000000)
print(frame_rate)
start_time = ticks_us()
frame_count = 0
except KeyboardInterrupt:
display.cleanup()
if __name__=='__displaytest__':
pwm = PWM(Pin(13))
pwm.freq(1000)
pwm.duty_u16(10000)#max 65535
LCD = GraphicLCD(width=240,height=240)
#color BRG
LCD.fill(LCD.white)
LCD.show()
keyA = Pin(15,Pin.IN,Pin.PULL_UP)
keyB = Pin(17,Pin.IN,Pin.PULL_UP)
keyX = Pin(19 ,Pin.IN,Pin.PULL_UP)
keyY= Pin(21 ,Pin.IN,Pin.PULL_UP)
up = Pin(2,Pin.IN,Pin.PULL_UP)
dowm = Pin(18,Pin.IN,Pin.PULL_UP)
left = Pin(16,Pin.IN,Pin.PULL_UP)
right = Pin(20,Pin.IN,Pin.PULL_UP)
ctrl = Pin(3,Pin.IN,Pin.PULL_UP)
LCD.text('hello',0,100)
# display is a framebuffer object
LCD.large_text('double', 0, 0, 2, 1) # double size text
LCD.large_text('size!', 0, 16, 2, 1)
LCD.large_text('HUGE', 0, 32, 4, 1) # quadruple size text
# draw a circle centred at point (x=64, y=64) with radius 56 and colour 1.
#LCD.circle(64, 64, 56 , c=1)
#LCD.circle(64, 64, 48 , c=1, f=True) # filled circle
# draw a filled triangle with corners at (x=0, y=0), (x=0, y=127) and (x=127, y=127)
# filled with colour 1.
LCD.triangle(0, 15, 0, 127, 127, 143, c=1, f=True)
while(1):
if keyA.value() == 0:
LCD.fill_rect(208,15,30,30,LCD.red)
else :
LCD.fill_rect(208,15,30,30,LCD.white)
LCD.rect(208,15,30,30,LCD.red)
if(keyB.value() == 0):
LCD.fill_rect(208,75,30,30,LCD.red)
else :
LCD.fill_rect(208,75,30,30,LCD.white)
LCD.rect(208,75,30,30,LCD.red)
if(keyX.value() == 0):
LCD.fill_rect(208,135,30,30,LCD.red)
else :
LCD.fill_rect(208,135,30,30,LCD.white)
LCD.rect(208,135,30,30,LCD.red)
if(keyY.value() == 0):
LCD.fill_rect(208,195,30,30,LCD.red)
else :
LCD.fill_rect(208,195,30,30,LCD.white)
LCD.rect(208,195,30,30,LCD.red)
if(up.value() == 0):
LCD.fill_rect(60,60,30,30,LCD.red)
else :
LCD.fill_rect(60,60,30,30,LCD.white)
LCD.rect(60,60,30,30,LCD.red)
if(dowm.value() == 0):
LCD.fill_rect(60,150,30,30,LCD.red)
else :
LCD.fill_rect(60,150,30,30,LCD.white)
LCD.rect(60,150,30,30,LCD.red)
if(left.value() == 0):
LCD.fill_rect(15,105,30,30,LCD.red)
else :
LCD.fill_rect(15,105,30,30,LCD.white)
LCD.rect(15,105,30,30,LCD.red)
if(right.value() == 0):
LCD.fill_rect(105,105,30,30,LCD.red)
else :
LCD.fill_rect(105,105,30,30,LCD.white)
LCD.rect(105,105,30,30,LCD.red)
if(ctrl.value() == 0):
LCD.fill_rect(60,105,30,30,LCD.red)
else :
LCD.fill_rect(60,105,30,30,LCD.white)
LCD.rect(60,105,30,30,LCD.red)
LCD.show()
#time.sleep(1)
LCD.fill(0xFFFF)