from machine import Pin, SPI import time import utime import random spi = SPI(0, baudrate=40000000,polarity=0,phase=0,bits=8,sck=2,mosi=3,miso=4) def Help(): print('LCD Library for the 480x320 ST7766 graphics driver') print('rev 3/16/24 JSG') print('uses pins 2,3,4,5,6,7') print(' ') print('Functions:') print('Init() Initialize the LCD display') print('Clear(color) Clear the display, set color of background') print('color = RGB(red, green, blue) return a 16-bit color value') print('Pixel(x, y, color) turn on pixel (x,y) at color') print('Line(x0,y0,x1,y1,color) Draw a line from (x0,y0) to (x1,y1)') print('Box(x0,y0,x1,y1,color) Draw a box from (x0,y0) to (x1,y1)') print('Solid_Box(x0,y0,x1,y1,color) Draw a solid box from (x0,y0) to (x1,y1)') print('Lander(x,y,color) Draw a symbol for the lunar lander at (x,y)') print('Number(Value, Digits, Decimal, x, y, color1, color0) Print a number at (x,y) scaling = 1') print('Number2(Value, Digits, Decimal, x, y, color1, color0) Print a number at (x,y) scaling = 2') print('Text(Messave, x, y, color1, color0) Send Message to the LCD starting at (x,y) scaling = 1') print('Text2(Messave, x, y, color1, color0) Send Message to the LCD starting at (x,y) scaling = 2') print('Light(OnOff, x, y, color) Draw a 10x10 box that is hollow (0) or solid (1) at (x,y)') print('Binary_Out(N, x, y) Draw 16 boxes and turn on the boxes that equal N in binary') print('Bar_Out(N, x, y) Draw 16 boxes and turn on box #N') print('Dice(N, x, y, color1, color0) Display a 6-sided die at (x,y) Size = 50x50') print('Card(Value, Suit, x, y) Draw a playing cart at (x,y) Size = 45x65') print('Y = Sort(X) Return the order of the variables in array X') print('Y = Shuffle() Shuffle a deck of 52 playing cards. Y is random order of 0..51') print(' ') print('Executing Times (test case)') print('Clear: 116.332 ms') print('Solid Box: 15.305 ms') print('Box: 11.720 ms') print('Lander: 7.934 ms') print('Dice: 23.051 ms') print('Card: 41.880 ms') print('Shuffle 47.003 ms') print('Line 3.004 ms') print('Line 179.925 ms') print('Text2: 118.431 ms (Hello World)') print('Text 1: 40.758 ms (Hello World)') print('Number2 108.503 ms (f8.6)') print('Number 37.517 ms (f8.6)') Font = ( [ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 ], [ 0x00, 0x00, 0x7e, 0x81, 0xa5, 0x81, 0x81, 0xbd, 0x99, 0x81, 0x81, 0x7e, 0x00, 0x00, 0x00, 0x00 ], [ 0x00, 0x00, 0x7e, 0xff, 0xdb, 0xff, 0xff, 0xc3, 0xe7, 0xff, 0xff, 0x7e, 0x00, 0x00, 0x00, 0x00 ], [ 0x00, 0x00, 0x00, 0x00, 0x6c, 0xfe, 0xfe, 0xfe, 0xfe, 0x7c, 0x38, 0x10, 0x00, 0x00, 0x00, 0x00 ], [ 0x00, 0x00, 0x00, 0x00, 0x10, 0x38, 0x7c, 0xfe, 0x7c, 0x38, 0x10, 0x00, 0x00, 0x00, 0x00, 0x00 ], [ 0x00, 0x00, 0x00, 0x18, 0x3c, 0x3c, 0xe7, 0xe7, 0xe7, 0x18, 0x18, 0x3c, 0x00, 0x00, 0x00, 0x00 ], [ 0x00, 0x00, 0x00, 0x18, 0x3c, 0x7e, 0xff, 0xff, 0x7e, 0x18, 0x18, 0x3c, 0x00, 0x00, 0x00, 0x00 ], [ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x18, 0x3c, 0x3c, 0x18, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 ], [ 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xe7, 0xc3, 0xc3, 0xe7, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff ], [ 0x00, 0x00, 0x00, 0x00, 0x00, 0x3c, 0x66, 0x42, 0x42, 0x66, 0x3c, 0x00, 0x00, 0x00, 0x00, 0x00 ], [ 0x00, 0x00, 0xfc, 0x66, 0x66, 0x66, 0x7c, 0x66, 0x66, 0x66, 0x66, 0xfc, 0x00, 0x00, 0x00, 0x00 ], [ 0x00, 0x00, 0x18, 0x18, 0x00, 0x38, 0x18, 0x18, 0x18, 0x18, 0x18, 0x3c, 0x00, 0x00, 0x00, 0x00 ], [ 0x00, 0x00, 0x00, 0x00, 0x00, 0x7c, 0xc6, 0x60, 0x38, 0x0c, 0xc6, 0x7c, 0x00, 0x00, 0x00, 0x00 ], [ 0x00, 0x00, 0x00, 0x00, 0x00, 0x7c, 0xc6, 0xc6, 0xc6, 0xc6, 0xc6, 0x7c, 0x00, 0x00, 0x00, 0x00 ], [ 0x00, 0x00, 0x00, 0x00, 0x00, 0xdc, 0x66, 0x66, 0x66, 0x66, 0x66, 0x66, 0x00, 0x00, 0x00, 0x00 ], [ 0x00, 0x00, 0x10, 0x38, 0x6c, 0xc6, 0xc6, 0xfe, 0xc6, 0xc6, 0xc6, 0xc6, 0x00, 0x00, 0x00, 0x00 ], [ 0x00, 0x00, 0x00, 0x00, 0x00, 0x7c, 0xc6, 0xc0, 0xc0, 0xc0, 0xc6, 0x7c, 0x00, 0x00, 0x00, 0x00 ], [ 0x00, 0x00, 0x00, 0x00, 0x00, 0x78, 0x0c, 0x7c, 0xcc, 0xcc, 0xcc, 0x76, 0x00, 0x00, 0x00, 0x00 ], [ 0x00, 0x00, 0x1c, 0x0c, 0x0c, 0x3c, 0x6c, 0xcc, 0xcc, 0xcc, 0xcc, 0x76, 0x00, 0x00, 0x00, 0x00 ], [ 0x00, 0x00, 0x00, 0x00, 0x00, 0x7c, 0xc6, 0xfe, 0xc0, 0xc0, 0xc6, 0x7c, 0x00, 0x00, 0x00, 0x00 ], [ 0x00, 0x00, 0x00, 0x00, 0x00, 0xe6, 0xff, 0xdb, 0xdb, 0xdb, 0xdb, 0xdb, 0x00, 0x00, 0x00, 0x00 ], [ 0x00, 0x00, 0x00, 0x00, 0x00, 0xc6, 0xc6, 0xc6, 0xc6, 0xc6, 0xc6, 0x7e, 0x06, 0x0c, 0xf8, 0x00 ], [ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x18, 0x18, 0x00, 0x00, 0x00, 0x00 ], [ 0x00, 0x00, 0x00, 0x00, 0x00, 0x7c, 0xc6, 0xc0, 0xc0, 0xc0, 0xc6, 0x7c, 0x00, 0x00, 0x00, 0x00 ], [ 0x00, 0x00, 0x00, 0x00, 0x00, 0x7c, 0xc6, 0xc6, 0xc6, 0xc6, 0xc6, 0x7c, 0x00, 0x00, 0x00, 0x00 ], [ 0x00, 0x00, 0x00, 0x00, 0x00, 0xe6, 0xff, 0xdb, 0xdb, 0xdb, 0xdb, 0xdb, 0x00, 0x00, 0x00, 0x00 ], [ 0x00, 0x00, 0x00, 0x00, 0x00, 0x18, 0x0c, 0xfe, 0x0c, 0x18, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 ], [ 0x00, 0x00, 0x00, 0x00, 0x00, 0x30, 0x60, 0xfe, 0x60, 0x30, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 ], [ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xc0, 0xc0, 0xc0, 0xfe, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 ], [ 0x00, 0x00, 0x00, 0x00, 0x00, 0x24, 0x66, 0xff, 0x66, 0x24, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 ], [ 0x00, 0x00, 0x00, 0x00, 0x10, 0x38, 0x38, 0x7c, 0x7c, 0xfe, 0xfe, 0x00, 0x00, 0x00, 0x00, 0x00 ], [ 0x00, 0x00, 0x00, 0x00, 0xfe, 0xfe, 0x7c, 0x7c, 0x38, 0x38, 0x10, 0x00, 0x00, 0x00, 0x00, 0x00 ], [ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 ], [ 0x00, 0x00, 0x18, 0x3c, 0x3c, 0x3c, 0x18, 0x18, 0x18, 0x00, 0x18, 0x18, 0x00, 0x00, 0x00, 0x00 ], [ 0x00, 0x66, 0x66, 0x66, 0x24, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 ], [ 0x00, 0x00, 0x00, 0x6c, 0x6c, 0xfe, 0x6c, 0x6c, 0x6c, 0xfe, 0x6c, 0x6c, 0x00, 0x00, 0x00, 0x00 ], [ 0x18, 0x18, 0x7c, 0xc6, 0xc2, 0xc0, 0x7c, 0x06, 0x06, 0x86, 0xc6, 0x7c, 0x18, 0x18, 0x00, 0x00 ], [ 0x00, 0x00, 0x00, 0x00, 0xc2, 0xc6, 0x0c, 0x18, 0x30, 0x60, 0xc6, 0x86, 0x00, 0x00, 0x00, 0x00 ], [ 0x00, 0x00, 0x38, 0x6c, 0x6c, 0x38, 0x76, 0xdc, 0xcc, 0xcc, 0xcc, 0x76, 0x00, 0x00, 0x00, 0x00 ], [ 0x00, 0x30, 0x30, 0x30, 0x60, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 ], [ 0x00, 0x00, 0x0c, 0x18, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x18, 0x0c, 0x00, 0x00, 0x00, 0x00 ], [ 0x00, 0x00, 0x30, 0x18, 0x0c, 0x0c, 0x0c, 0x0c, 0x0c, 0x0c, 0x18, 0x30, 0x00, 0x00, 0x00, 0x00 ], [ 0x00, 0x00, 0x00, 0x00, 0x00, 0x66, 0x3c, 0xff, 0x3c, 0x66, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 ], [ 0x00, 0x00, 0x00, 0x00, 0x00, 0x18, 0x18, 0x7e, 0x18, 0x18, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 ], [ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x18, 0x18, 0x18, 0x30, 0x00, 0x00, 0x00 ], [ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xfe, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 ], [ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x18, 0x18, 0x00, 0x00, 0x00, 0x00 ], [ 0x00, 0x00, 0x00, 0x00, 0x02, 0x06, 0x0c, 0x18, 0x30, 0x60, 0xc0, 0x80, 0x00, 0x00, 0x00, 0x00 ], [ 0x00, 0x00, 0x3c, 0x66, 0xc3, 0xc3, 0xdb, 0xdb, 0xc3, 0xc3, 0x66, 0x3c, 0x00, 0x00, 0x00, 0x00 ], [ 0x00, 0x00, 0x18, 0x38, 0x78, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x7e, 0x00, 0x00, 0x00, 0x00 ], [ 0x00, 0x00, 0x7c, 0xc6, 0x06, 0x0c, 0x18, 0x30, 0x60, 0xc0, 0xc6, 0xfe, 0x00, 0x00, 0x00, 0x00 ], [ 0x00, 0x00, 0x7c, 0xc6, 0x06, 0x06, 0x3c, 0x06, 0x06, 0x06, 0xc6, 0x7c, 0x00, 0x00, 0x00, 0x00 ], [ 0x00, 0x00, 0x0c, 0x1c, 0x3c, 0x6c, 0xcc, 0xfe, 0x0c, 0x0c, 0x0c, 0x1e, 0x00, 0x00, 0x00, 0x00 ], [ 0x00, 0x00, 0xfe, 0xc0, 0xc0, 0xc0, 0xfc, 0x06, 0x06, 0x06, 0xc6, 0x7c, 0x00, 0x00, 0x00, 0x00 ], [ 0x00, 0x00, 0x38, 0x60, 0xc0, 0xc0, 0xfc, 0xc6, 0xc6, 0xc6, 0xc6, 0x7c, 0x00, 0x00, 0x00, 0x00 ], [ 0x00, 0x00, 0xfe, 0xc6, 0x06, 0x06, 0x0c, 0x18, 0x30, 0x30, 0x30, 0x30, 0x00, 0x00, 0x00, 0x00 ], [ 0x00, 0x00, 0x7c, 0xc6, 0xc6, 0xc6, 0x7c, 0xc6, 0xc6, 0xc6, 0xc6, 0x7c, 0x00, 0x00, 0x00, 0x00 ], [ 0x00, 0x00, 0x7c, 0xc6, 0xc6, 0xc6, 0x7e, 0x06, 0x06, 0x06, 0x0c, 0x78, 0x00, 0x00, 0x00, 0x00 ], [ 0x00, 0x00, 0x00, 0x00, 0x18, 0x18, 0x00, 0x00, 0x00, 0x18, 0x18, 0x00, 0x00, 0x00, 0x00, 0x00 ], [ 0x00, 0x00, 0x00, 0x00, 0x18, 0x18, 0x00, 0x00, 0x00, 0x18, 0x18, 0x30, 0x00, 0x00, 0x00, 0x00 ], [ 0x00, 0x00, 0x00, 0x06, 0x0c, 0x18, 0x30, 0x60, 0x30, 0x18, 0x0c, 0x06, 0x00, 0x00, 0x00, 0x00 ], [ 0x00, 0x00, 0x00, 0x00, 0x00, 0x7e, 0x00, 0x00, 0x7e, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 ], [ 0x00, 0x00, 0x00, 0x60, 0x30, 0x18, 0x0c, 0x06, 0x0c, 0x18, 0x30, 0x60, 0x00, 0x00, 0x00, 0x00 ], [ 0x00, 0x00, 0x7c, 0xc6, 0xc6, 0x0c, 0x18, 0x18, 0x18, 0x00, 0x18, 0x18, 0x00, 0x00, 0x00, 0x00 ], [ 0x00, 0x00, 0x00, 0x7c, 0xc6, 0xc6, 0xde, 0xde, 0xde, 0xdc, 0xc0, 0x7c, 0x00, 0x00, 0x00, 0x00 ], [ 0x00, 0x00, 0x10, 0x38, 0x6c, 0xc6, 0xc6, 0xfe, 0xc6, 0xc6, 0xc6, 0xc6, 0x00, 0x00, 0x00, 0x00 ], [ 0x00, 0x00, 0xfc, 0x66, 0x66, 0x66, 0x7c, 0x66, 0x66, 0x66, 0x66, 0xfc, 0x00, 0x00, 0x00, 0x00 ], [ 0x00, 0x00, 0x3c, 0x66, 0xc2, 0xc0, 0xc0, 0xc0, 0xc0, 0xc2, 0x66, 0x3c, 0x00, 0x00, 0x00, 0x00 ], [ 0x00, 0x00, 0xf8, 0x6c, 0x66, 0x66, 0x66, 0x66, 0x66, 0x66, 0x6c, 0xf8, 0x00, 0x00, 0x00, 0x00 ], [ 0x00, 0x00, 0xfe, 0x66, 0x62, 0x68, 0x78, 0x68, 0x60, 0x62, 0x66, 0xfe, 0x00, 0x00, 0x00, 0x00 ], [ 0x00, 0x00, 0xfe, 0x66, 0x62, 0x68, 0x78, 0x68, 0x60, 0x60, 0x60, 0xf0, 0x00, 0x00, 0x00, 0x00 ], [ 0x00, 0x00, 0x3c, 0x66, 0xc2, 0xc0, 0xc0, 0xde, 0xc6, 0xc6, 0x66, 0x3a, 0x00, 0x00, 0x00, 0x00 ], [ 0x00, 0x00, 0xc6, 0xc6, 0xc6, 0xc6, 0xfe, 0xc6, 0xc6, 0xc6, 0xc6, 0xc6, 0x00, 0x00, 0x00, 0x00 ], [ 0x00, 0x00, 0x3c, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x3c, 0x00, 0x00, 0x00, 0x00 ], [ 0x00, 0x00, 0x1e, 0x0c, 0x0c, 0x0c, 0x0c, 0x0c, 0xcc, 0xcc, 0xcc, 0x78, 0x00, 0x00, 0x00, 0x00 ], [ 0x00, 0x00, 0xe6, 0x66, 0x66, 0x6c, 0x78, 0x78, 0x6c, 0x66, 0x66, 0xe6, 0x00, 0x00, 0x00, 0x00 ], [ 0x00, 0x00, 0xf0, 0x60, 0x60, 0x60, 0x60, 0x60, 0x60, 0x62, 0x66, 0xfe, 0x00, 0x00, 0x00, 0x00 ], [ 0x00, 0x00, 0xc3, 0xe7, 0xff, 0xff, 0xdb, 0xc3, 0xc3, 0xc3, 0xc3, 0xc3, 0x00, 0x00, 0x00, 0x00 ], [ 0x00, 0x00, 0xc6, 0xe6, 0xf6, 0xfe, 0xde, 0xce, 0xc6, 0xc6, 0xc6, 0xc6, 0x00, 0x00, 0x00, 0x00 ], [ 0x00, 0x00, 0x7c, 0xc6, 0xc6, 0xc6, 0xc6, 0xc6, 0xc6, 0xc6, 0xc6, 0x7c, 0x00, 0x00, 0x00, 0x00 ], [ 0x00, 0x00, 0xfc, 0x66, 0x66, 0x66, 0x7c, 0x60, 0x60, 0x60, 0x60, 0xf0, 0x00, 0x00, 0x00, 0x00 ], [ 0x00, 0x00, 0x7c, 0xc6, 0xc6, 0xc6, 0xc6, 0xc6, 0xc6, 0xd6, 0xde, 0x7c, 0x0c, 0x0e, 0x00, 0x00 ], [ 0x00, 0x00, 0xfc, 0x66, 0x66, 0x66, 0x7c, 0x6c, 0x66, 0x66, 0x66, 0xe6, 0x00, 0x00, 0x00, 0x00 ], [ 0x00, 0x00, 0x7c, 0xc6, 0xc6, 0x60, 0x38, 0x0c, 0x06, 0xc6, 0xc6, 0x7c, 0x00, 0x00, 0x00, 0x00 ], [ 0x00, 0x00, 0xff, 0xdb, 0x99, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x3c, 0x00, 0x00, 0x00, 0x00 ], [ 0x00, 0x00, 0xc6, 0xc6, 0xc6, 0xc6, 0xc6, 0xc6, 0xc6, 0xc6, 0xc6, 0x7c, 0x00, 0x00, 0x00, 0x00 ], [ 0x00, 0x00, 0xc3, 0xc3, 0xc3, 0xc3, 0xc3, 0xc3, 0xc3, 0x66, 0x3c, 0x18, 0x00, 0x00, 0x00, 0x00 ], [ 0x00, 0x00, 0xc3, 0xc3, 0xc3, 0xc3, 0xc3, 0xdb, 0xdb, 0xff, 0x66, 0x66, 0x00, 0x00, 0x00, 0x00 ], [ 0x00, 0x00, 0xc3, 0xc3, 0x66, 0x3c, 0x18, 0x18, 0x3c, 0x66, 0xc3, 0xc3, 0x00, 0x00, 0x00, 0x00 ], [ 0x00, 0x00, 0xc3, 0xc3, 0xc3, 0x66, 0x3c, 0x18, 0x18, 0x18, 0x18, 0x3c, 0x00, 0x00, 0x00, 0x00 ], [ 0x00, 0x00, 0xff, 0xc3, 0x86, 0x0c, 0x18, 0x30, 0x60, 0xc1, 0xc3, 0xff, 0x00, 0x00, 0x00, 0x00 ], [ 0x00, 0x00, 0x3c, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x3c, 0x00, 0x00, 0x00, 0x00 ], [ 0x00, 0x00, 0x00, 0x80, 0xc0, 0xe0, 0x70, 0x38, 0x1c, 0x0e, 0x06, 0x02, 0x00, 0x00, 0x00, 0x00 ], [ 0x00, 0x00, 0x3c, 0x0c, 0x0c, 0x0c, 0x0c, 0x0c, 0x0c, 0x0c, 0x0c, 0x3c, 0x00, 0x00, 0x00, 0x00 ], [ 0x10, 0x38, 0x6c, 0xc6, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 ], [ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xff, 0x00, 0x00 ], [ 0x30, 0x30, 0x18, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 ], [ 0x00, 0x00, 0x00, 0x00, 0x00, 0x78, 0x0c, 0x7c, 0xcc, 0xcc, 0xcc, 0x76, 0x00, 0x00, 0x00, 0x00 ], [ 0x00, 0x00, 0xe0, 0x60, 0x60, 0x78, 0x6c, 0x66, 0x66, 0x66, 0x66, 0x7c, 0x00, 0x00, 0x00, 0x00 ], [ 0x00, 0x00, 0x00, 0x00, 0x00, 0x7c, 0xc6, 0xc0, 0xc0, 0xc0, 0xc6, 0x7c, 0x00, 0x00, 0x00, 0x00 ], [ 0x00, 0x00, 0x1c, 0x0c, 0x0c, 0x3c, 0x6c, 0xcc, 0xcc, 0xcc, 0xcc, 0x76, 0x00, 0x00, 0x00, 0x00 ], [ 0x00, 0x00, 0x00, 0x00, 0x00, 0x7c, 0xc6, 0xfe, 0xc0, 0xc0, 0xc6, 0x7c, 0x00, 0x00, 0x00, 0x00 ], [ 0x00, 0x00, 0x38, 0x6c, 0x64, 0x60, 0xf0, 0x60, 0x60, 0x60, 0x60, 0xf0, 0x00, 0x00, 0x00, 0x00 ], [ 0x00, 0x00, 0x00, 0x00, 0x00, 0x76, 0xcc, 0xcc, 0xcc, 0xcc, 0xcc, 0x7c, 0x0c, 0xcc, 0x78, 0x00 ], [ 0x00, 0x00, 0xe0, 0x60, 0x60, 0x6c, 0x76, 0x66, 0x66, 0x66, 0x66, 0xe6, 0x00, 0x00, 0x00, 0x00 ], [ 0x00, 0x00, 0x18, 0x18, 0x00, 0x38, 0x18, 0x18, 0x18, 0x18, 0x18, 0x3c, 0x00, 0x00, 0x00, 0x00 ], [ 0x00, 0x00, 0x06, 0x06, 0x00, 0x0e, 0x06, 0x06, 0x06, 0x06, 0x06, 0x06, 0x66, 0x66, 0x3c, 0x00 ], [ 0x00, 0x00, 0xe0, 0x60, 0x60, 0x66, 0x6c, 0x78, 0x78, 0x6c, 0x66, 0xe6, 0x00, 0x00, 0x00, 0x00 ], [ 0x00, 0x00, 0x38, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x3c, 0x00, 0x00, 0x00, 0x00 ], [ 0x00, 0x00, 0x00, 0x00, 0x00, 0xe6, 0xff, 0xdb, 0xdb, 0xdb, 0xdb, 0xdb, 0x00, 0x00, 0x00, 0x00 ], [ 0x00, 0x00, 0x00, 0x00, 0x00, 0xdc, 0x66, 0x66, 0x66, 0x66, 0x66, 0x66, 0x00, 0x00, 0x00, 0x00 ], [ 0x00, 0x00, 0x00, 0x00, 0x00, 0x7c, 0xc6, 0xc6, 0xc6, 0xc6, 0xc6, 0x7c, 0x00, 0x00, 0x00, 0x00 ], [ 0x00, 0x00, 0x00, 0x00, 0x00, 0xdc, 0x66, 0x66, 0x66, 0x66, 0x66, 0x7c, 0x60, 0x60, 0xf0, 0x00 ], [ 0x00, 0x00, 0x00, 0x00, 0x00, 0x76, 0xcc, 0xcc, 0xcc, 0xcc, 0xcc, 0x7c, 0x0c, 0x0c, 0x1e, 0x00 ], [ 0x00, 0x00, 0x00, 0x00, 0x00, 0xdc, 0x76, 0x66, 0x60, 0x60, 0x60, 0xf0, 0x00, 0x00, 0x00, 0x00 ], [ 0x00, 0x00, 0x00, 0x00, 0x00, 0x7c, 0xc6, 0x60, 0x38, 0x0c, 0xc6, 0x7c, 0x00, 0x00, 0x00, 0x00 ], [ 0x00, 0x00, 0x10, 0x30, 0x30, 0xfc, 0x30, 0x30, 0x30, 0x30, 0x36, 0x1c, 0x00, 0x00, 0x00, 0x00 ], [ 0x00, 0x00, 0x00, 0x00, 0x00, 0xcc, 0xcc, 0xcc, 0xcc, 0xcc, 0xcc, 0x76, 0x00, 0x00, 0x00, 0x00 ], [ 0x00, 0x00, 0x00, 0x00, 0x00, 0xc3, 0xc3, 0xc3, 0xc3, 0x66, 0x3c, 0x18, 0x00, 0x00, 0x00, 0x00 ], [ 0x00, 0x00, 0x00, 0x00, 0x00, 0xc3, 0xc3, 0xc3, 0xdb, 0xdb, 0xff, 0x66, 0x00, 0x00, 0x00, 0x00 ], [ 0x00, 0x00, 0x00, 0x00, 0x00, 0xc3, 0x66, 0x3c, 0x18, 0x3c, 0x66, 0xc3, 0x00, 0x00, 0x00, 0x00 ], [ 0x00, 0x00, 0x00, 0x00, 0x00, 0xc6, 0xc6, 0xc6, 0xc6, 0xc6, 0xc6, 0x7e, 0x06, 0x0c, 0xf8, 0x00 ], [ 0x00, 0x00, 0x00, 0x00, 0x00, 0xfe, 0xcc, 0x18, 0x30, 0x60, 0xc6, 0xfe, 0x00, 0x00, 0x00, 0x00 ], [ 0x00, 0x00, 0x0e, 0x18, 0x18, 0x18, 0x70, 0x18, 0x18, 0x18, 0x18, 0x0e, 0x00, 0x00, 0x00, 0x00 ], [ 0x00, 0x00, 0x18, 0x18, 0x18, 0x18, 0x00, 0x18, 0x18, 0x18, 0x18, 0x18, 0x00, 0x00, 0x00, 0x00 ], [ 0x00, 0x00, 0x70, 0x18, 0x18, 0x18, 0x0e, 0x18, 0x18, 0x18, 0x18, 0x70, 0x00, 0x00, 0x00, 0x00 ], [ 0x00, 0x00, 0x76, 0xdc, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 ], [ 0x00, 0x00, 0x00, 0x00, 0x10, 0x38, 0x6c, 0xc6, 0xc6, 0xc6, 0xfe, 0x00, 0x00, 0x00, 0x00, 0x00 ]) #clk = Pin(2, Pin.OUT) #din = Pin(3, Pin.OUT) cs = Pin(5, Pin.OUT) dc = Pin(6, Pin.OUT) rst = Pin(7, Pin.OUT) def Write_cmd(X): dc.value(0) cs.value(0) spi.write(bytearray([X])) cs.value(1) def Write_data(X): dc.value(1) cs.value(0) spi.write(bytearray([X])) cs.value(1) def Write16(X): dc.value(1) cs.value(0) spi.write(bytearray([X>>8,X])) cs.value(1) def Write16x8(X): dc.value(1) cs.value(0) spi.write(bytearray([X>>8, X, X>>8, X, X>>8, X, X>>8, X, X>>8, X, X>>8, X, X>>8, X, X>>8, X])) cs.value(1) def Write16xN(X): dc.value(1) cs.value(0) spi.write(X) cs.value(1) #/*Initialize your display and the required peripherals.*/ def Init(): cs.value(0) dc.value(1) rst.value(1) time.sleep(0.005) rst.value(0) time.sleep(0.015) rst.value(1) cs.value(1) time.sleep(0.001) cs.value(0) Write_cmd(0x01) # Software reset and Delay 150ms cs.value(1) time.sleep(0.15) Write_cmd(0x11) # Sleep out and Delay 500ms time.sleep(0.50) Write_cmd(0x3A) # # Set color mode to 16 bits per pixel and Delay 10ms Write_data(0x55) Write_data(0x0A) time.sleep(0.10) Write_cmd(0x29) # Display on, delay 150ms time.sleep(0.15) Write_cmd(0x21) # inversion off Write_cmd(0x36) # # _MADCTL for landscape mode Write_data(0x28) time.sleep(0.1) def Address_Set(x0, y0, x1, y1): Write_cmd(0x2A) # column range Write16(x0) Write16(x1) Write_cmd(0x2B) # row range Write16(y0) Write16(y1) Write_cmd(0x2C) # memory write def StartWrite(): rst.value(1) cs.value(0) def EndWrite(): cs.value(1) def RGB(r, g, b): r = r & 0xF8 g = g & 0xFC b = b & 0xF8 X = (r << 8) | (g << 3) | (b >> 3) return(X) def Pixel(x, y, color): dc.value(0) cs.value(0) spi.write(bytearray([0x2A])) dc.value(1) spi.write(bytearray([x>>8,x])) dc.value(0) spi.write(bytearray([0x2B])) dc.value(1) spi.write(bytearray([y>>8,y])) dc.value(0) spi.write(bytearray([0x2C])) dc.value(1) spi.write(bytearray([color>>8,color])) cs.value(1) def Pixel2(x, y, color): Address_Set(x, y, x+1, y+1) X = bytearray([color>>8,color,color>>8,color,color>>8,color,color>>8]) StartWrite() Write16xN(X) EndWrite() def Line(x0, y0, x1, y1, color): if(x0==x1): if(y1>y0): Solid_Box(x0,y0,x0,y1,color) else: Solid_Box(x0,y1,x0,y0,color) elif(y0==y1): if(x1>x0): Solid_Box(x0,y0,x1,y0,color) else: Solid_Box(x1,y0,x0,y0,color) else: dx = (x1-x0) dy = (y1-y0) if(abs(dx) > abs(dy)): if(x0>x1): temp = x1 x1 = x0 x0 = temp temp = y1 y1 = y0 y0 = temp iy = y0 dydx = int(100*(y1-y0)/(x1-x0)) y100 = 50 for i in range(x0,x1): Pixel(i,iy,color) y100 += dydx if(y100 > 100): y100 -= 100 iy += 1 if(y100 < 0): y100 += 100 iy -= 1 else: if(y0>y1): temp = x1 x1 = x0 x0 = temp temp = y1 y1 = y0 y0 = temp ix = x0 dxdy = int(100*(x1-x0)/(y1-y0)) x100 = 50 for i in range(y0,y1): Pixel(ix,i,color) x100 += dxdy if(x100 > 100): x100 -= 100 ix += 1 if(x100 < 0): x100 += 100 ix -= 1 def Box(x0, y0, x1, y1, color): Line(x0, y0, x1, y0, color) Line(x1, y0, x1, y1, color) Line(x1, y1, x0, y1, color) Line(x0, y1, x0, y0, color) def Lander(x, y, color): x = int(x) y = int(y) Line(x-5, y, x, y-10, color) Line(x, y-10, x+5, y, color) # -- Scaling = 1 ----- # output a number at point (x,y) with foreground color1 and background color0 def Number(Value, Digits, Decimals, x, y, color1, color0): Value = Value % 10**Digits format = "%"+str(Digits)+"."+str(Decimals)+"f" X = str(format%Value) n = len(X) if(Decimals==0): n -= 1 else: n -= 2 for i in range(0,Digits-n): X = ' ' + X Text(X, x, y, color1, color0) def Text(Message, x, y, color1, color0): global Font N = len(Message) Con_high = color1 >> 8 Con_low = color1 & 0xFF Coff_high = color0 >> 8 Coff_low = color0 & 0xFF for k in range(0,N): Array = Font[ord(Message[k])] Address_Set(x+k*8,y,x+k*8+7,y+15) X = bytearray() for j in range(0,16): Aj = Array[j] for i in range(0,8): if((Aj & (0x80>>i)) > 0): X.append(Con_high) X.append(Con_low) else: X.append(Coff_high) X.append(Coff_low) Write16xN(X) # -- Scaling = 2 def Number2(Value, Digits, Decimals, x, y, color1, color0): Value = Value % 10**Digits format = "%"+str(Digits)+"."+str(Decimals)+"f" X = str(format%Value) n = len(X) if(Decimals==0): n -= 1 else: n -= 2 for i in range(0,Digits-n): X = ' ' + X Text2(X, x, y, color1, color0) def Text2(Message, x, y, color1, color0): global Font N = len(Message) Con_high = color1 >> 8 Con_low = color1 & 0xFF Coff_high = color0 >> 8 Coff_low = color0 & 0xFF for k in range(0,N): Array = Font[ord(Message[k])] Address_Set(x+k*16,y,x+k*16+15,y+31) X = bytearray() for j in range(0,16): Aj = Array[j] for i2 in range(1,3): for i in range(0,8): if((Aj & (0x80>>i)) > 0): X.append(Con_high) X.append(Con_low) X.append(Con_high) X.append(Con_low) else: X.append(Coff_high) X.append(Coff_low) X.append(Coff_high) X.append(Coff_low) Write16xN(X) # --------------------- def Clear(color): Address_Set(0, 0, 480, 320) Ch = color >> 8 Cl = color & 0xFF X = bytearray() for i in range(0,480): X.append(Ch) X.append(Cl) StartWrite() for i in range(0,320): Write16xN(X) EndWrite() def Solid_Box(x1, y1, x2, y2, color): Address_Set(x1, y1, x2, y2) X = bytearray([color>>8,color,color>>8,color,color>>8,color,color>>8,color,color>>8,color,color>>8,color,color>>8,color,color>>8,color]) StartWrite() N = int((x2-x1+1)*(y2-y1+1)/8)+1 for i in range(0, N): Write16xN(X) EndWrite() # -- LED Functions ----------------- def Light(OnOff, x, y, color): Address_Set(x, y, x+9, y+9) C1 = bytearray([color>>8,color,color>>8,color,color>>8,color,color>>8,color,color>>8,color,color>>8,color,color>>8,color,color>>8,color,color>>8,color,color>>8,color]) C0 = bytearray([color>>8,color,0,0,color,0,0,0,0,0,0,0,0,0,0,0,0,0,color>>8,color]) if(OnOff == 1): StartWrite() Write16xN(C1) Write16xN(C1) Write16xN(C1) Write16xN(C1) Write16xN(C1) Write16xN(C1) Write16xN(C1) Write16xN(C1) Write16xN(C1) Write16xN(C1) EndWrite() else: StartWrite() Write16xN(C1) Write16xN(C1) Write16xN(C0) Write16xN(C0) Write16xN(C0) Write16xN(C0) Write16xN(C0) Write16xN(C0) Write16xN(C1) Write16xN(C1) EndWrite() def Binary_Out(X, x, y): for i in range(0,16): if(X & (0x8000 >> i)): Light(1, x+i*15, y, 0xFFFF) else: Light(0, x+i*15, y, 0xFFFF) def Bar_Out(X, x, y): for i in range(1,17): if(X == i): Light(1, x+(16-i)*15, y, 0xFFFF) else: Light(0, x+(16-i)*15, y, 0xFFFF) # - Dice and Card Games def Dice(N, x, y, color1, color0): Solid_Box(x, y, x+50, y+50, color0) Box(x, y, x+50, y+50, 0) if(N == 1): Pips = [0,0,0,0,1,0,0,0,0] if(N == 2): Pips = [0,0,1,0,0,0,1,0,0] if(N==3): Pips = [0,0,1,0,1,0,1,0,0] if(N==4): Pips = [1,0,1,0,0,0,1,0,1] if(N==5): Pips = [1,0,1,0,1,0,1,0,1] if(N==6): Pips = [1,0,1,1,0,1,1,0,1] for i in range(0,9): dx = i % 3 dy = int(i/3) if(Pips[i]): Light(1, x+12*dx+8, y+12*dy+8, color1) def Card(N, S, x, y): White = 0xFFFF; Red = RGB(250,0,0) Black = 0 Solid_Box(x, y, x+45, y+65, White) Box(x, y, x+45, y+65, 0) Value = ['A','2','3','4','5','6','7','8','9','10','J','Q','K'] Suit = ['\5','\4','\3','\6'] if(S in [0,3]): color = Black; else: color = Red Text(Value[N], x+5, y+5, color, White) Text2(Suit[S], x+12, y+15, color, White) Text(Value[N], x+25, y+45, color, White) def Sort(X): N = len(X) Y = [] for i in range(0,N): Y.append(i) for i in range(0,N-1): for j in range(0,N-1): if(X[j]>X[j+1]): temp = X[j] X[j] = X[j+1] X[j+1] = temp temp = Y[j] Y[j] = Y[j+1] Y[j+1] = temp return(Y) def Shuffle(): X = [] for i in range(0,52): X.append(random.uniform(0,1)) Y = Sort(X) return(Y)