├── README.md ├── ST7735.py ├── bmp.py ├── flower160x128.bmp ├── flower64x48.bmp ├── font5x7.fnt ├── lcd_gfx.py └── main.py /README.md: -------------------------------------------------------------------------------- 1 | # MicroPython_ST7735S 2 | 3 | Last update added support for a cheap 128x128 TFT display. 4 | offset - offsets the display by that number of pixels horizontally and vertically 5 | c_mode - Swaps around Blue and Red in the 565 colour packet. It seems some displays swap these. 6 | 7 | Sample usage 8 | ```python 9 | import ST7735 10 | 11 | # height defaults to 160 12 | ST7735.ST7735_TFTHEIGHT = 128 13 | spi = machine.SPI(1, baudrate=8000000, polarity=0, phase=0) 14 | 15 | # move image 3 pixels across and down 16 | # RGB is reversed = c_mode fixes that 17 | d = ST7735.ST7735(offset=3, c_mode='BGR') 18 | d.reset() 19 | d.begin() 20 | d._bground = 0xffff 21 | d.fill_screen(d._bground) 22 | ``` 23 | 24 | This is for a 128 x 160 display that uses a different set of pins to the default 25 | ```python 26 | import ST7735 27 | spi = machine.SPI(1, baudrate=8000000, polarity=0, phase=0) 28 | d = ST7735.ST7735(spi, rst=4, ce=5, dc=16) 29 | d.reset() 30 | d.begin() 31 | d._bground = 0xffff 32 | d.fill_screen(d._bground) 33 | ``` 34 | 35 | .mpy versions are available in the releases 36 | -------------------------------------------------------------------------------- /ST7735.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python 2 | # -*- coding: utf-8 -*- 3 | # 4 | # ST7735.py 5 | # 6 | from machine import Pin, SPI 7 | import time 8 | import math 9 | 10 | #constants 11 | DELAY = 0x80 12 | ST7735_TFTWIDTH = 128 13 | ST7735_TFTHEIGHT = 160 14 | 15 | ST7735_NOP = 0x00 16 | ST7735_SWRESET = 0x01 17 | ST7735_RDDID = 0x04 18 | ST7735_RDDST = 0x09 19 | 20 | ST7735_SLPIN = 0x10 21 | ST7735_SLPOUT = 0x11 22 | ST7735_PTLON = 0x12 23 | ST7735_NORON = 0x13 24 | 25 | ST7735_INVOFF = 0x20 26 | ST7735_INVON = 0x21 27 | ST7735_DISPOFF = 0x28 28 | ST7735_DISPON = 0x29 29 | ST7735_CASET = 0x2A 30 | ST7735_RASET = 0x2B 31 | ST7735_RAMWR = 0x2C 32 | ST7735_RAMRD = 0x2E 33 | 34 | ST7735_PTLAR = 0x30 35 | ST7735_COLMOD = 0x3A 36 | ST7735_MADCTL = 0x36 37 | 38 | ST7735_FRMCTR1 = 0xB1 39 | ST7735_FRMCTR2 = 0xB2 40 | ST7735_FRMCTR3 = 0xB3 41 | ST7735_INVCTR = 0xB4 42 | ST7735_DISSET5 = 0xB6 43 | 44 | ST7735_PWCTR1 = 0xC0 45 | ST7735_PWCTR2 = 0xC1 46 | ST7735_PWCTR3 = 0xC2 47 | ST7735_PWCTR4 = 0xC3 48 | ST7735_PWCTR5 = 0xC4 49 | ST7735_VMCTR1 = 0xC5 50 | 51 | ST7735_RDID1 = 0xDA 52 | ST7735_RDID2 = 0xDB 53 | ST7735_RDID3 = 0xDC 54 | ST7735_RDID4 = 0xDD 55 | 56 | ST7735_PWCTR6 = 0xFC 57 | 58 | ST7735_GMCTRP1 = 0xE0 59 | ST7735_GMCTRN1 = 0xE1 60 | 61 | # for the rotation definition 62 | ST7735_MADCTL_MY = 0x80 63 | ST7735_MADCTL_MX = 0x40 64 | ST7735_MADCTL_MV = 0x20 65 | ST7735_MADCTL_ML = 0x10 66 | ST7735_MADCTL_RGB = 0x00 67 | ST7735_MADCTL_BGR = 0x08 68 | ST7735_MADCTL_MH = 0x04 69 | 70 | class ST7735(): 71 | def __init__(self, spi, rst=4, ce=5, dc=16, offset=0, c_mode='RGB'): 72 | self._rst = Pin(rst, Pin.OUT) # 4 73 | self._ce = Pin(ce, Pin.OUT) # 5 74 | self._ce.high() 75 | self._dc = Pin(dc, Pin.OUT) # 16 76 | self._dc.high() 77 | self._offset = offset 78 | self._x = 0 79 | self._y = 0 80 | self._width = ST7735_TFTWIDTH 81 | self._height = ST7735_TFTHEIGHT 82 | self._color = 0 83 | self._bground = 0x64bd 84 | if c_mode == 'RGB': 85 | self._color_mode = ST7735_MADCTL_RGB 86 | else: 87 | self._color_mode = ST7735_MADCTL_BGR 88 | 89 | # SPI 90 | self._spi = spi 91 | 92 | def command(self,c): 93 | b = bytearray(1) 94 | b[0] = c 95 | self._dc.low() 96 | self._ce.low() 97 | self._spi.write(b) # write 1 byte on MOSI 98 | self._ce.high() 99 | # print ('C {0:2x}'.format(c)) 100 | 101 | def data(self, c): 102 | b = bytearray(1) 103 | b[0] = c 104 | self._dc.high() 105 | self._ce.low() 106 | self._spi.write(b) # write 1 byte on MOSI 107 | self._ce.high() 108 | # print ('D {0:2x}'.format(c)) 109 | 110 | def reset(self): 111 | self._rst.low() 112 | time.sleep_ms(50) # sleep for 50 milliseconds 113 | self._rst.high() 114 | time.sleep_ms(50) # sleep for 50 milliseconds 115 | 116 | # begin 117 | def begin(self): 118 | self.reset() 119 | commands = bytearray([ # Initialization commands for 7735B screens 120 | ST7735_SWRESET, DELAY, # 1: Software reset, 0 args, w/delay 121 | 150, # 150 ms delay 122 | ST7735_SLPOUT , DELAY, # 2: Out of sleep mode, 0 args, w/delay 123 | 255, # 500 ms delay 124 | ST7735_FRMCTR1, 3 , # 3: Frame rate ctrl - normal mode, 3 args: 125 | 0x01, 0x2C, 0x2D, # Rate = fosc/(1x2+40) * (LINE+2C+2D) 126 | ST7735_FRMCTR2, 3 , # 4: Frame rate control - idle mode, 3 args: 127 | 0x01, 0x2C, 0x2D, # Rate = fosc/(1x2+40) * (LINE+2C+2D) 128 | ST7735_FRMCTR3, 6 , # 5: Frame rate ctrl - partial mode, 6 args: 129 | 0x01, 0x2C, 0x2D, # Dot inversion mode 130 | 0x01, 0x2C, 0x2D, # Line inversion mode 131 | ST7735_INVCTR , 1 , # 6: Display inversion ctrl, 1 arg, no delay: 132 | 0x07, # No inversion 133 | ST7735_PWCTR1 , 3 , # 7: Power control, 3 args, no delay: 134 | 0xA2, 135 | 0x02, # -4.6V 136 | 0x84, # AUTO mode 137 | ST7735_PWCTR2 , 1 , # 8: Power control, 1 arg, no delay: 138 | 0xC5, # VGH25 = 2.4C VGSEL = -10 VGH = 3 * AVDD 139 | ST7735_PWCTR3 , 2 , # 9: Power control, 2 args, no delay: 140 | 0x0A, # Opamp current small 141 | 0x00, # Boost frequency 142 | ST7735_PWCTR4 , 2 , # 10: Power control, 2 args, no delay: 143 | 0x8A, # BCLK/2, Opamp current small & Medium low 144 | 0x2A, 145 | ST7735_PWCTR5 , 2 , # 11: Power control, 2 args, no delay: 146 | 0x8A, 0xEE, 147 | ST7735_VMCTR1 , 1 , # 12: Power control, 1 arg, no delay: 148 | 0x0E, 149 | ST7735_INVOFF , 0 , # 13: Don't invert display, no args, no delay 150 | ST7735_MADCTL , 1 , # 14: Memory access control (directions), 1 arg: 151 | 0xC8, # row addr/col addr, bottom to top refresh 152 | ST7735_COLMOD , 1 , # 15: set color mode, 1 arg, no delay: 153 | 0x05, # 16-bit color 154 | ST7735_CASET , 4 , # 1: Column addr set, 4 args, no delay: 155 | 0x00, 0x00, # XSTART = 0 156 | 0x00, 0x7F, # XEND = 127 157 | ST7735_RASET , 4 , # 2: Row addr set, 4 args, no delay: 158 | 0x00, 0x00, # XSTART = 0 159 | 0x00, 0x9F, # XEND = 159 160 | ST7735_GMCTRP1, 16 , # 1: Magical unicorn dust, 16 args, no delay: 161 | 0x02, 0x1c, 0x07, 0x12, 162 | 0x37, 0x32, 0x29, 0x2d, 163 | 0x29, 0x25, 0x2B, 0x39, 164 | 0x00, 0x01, 0x03, 0x10, 165 | ST7735_GMCTRN1, 16 , # 2: Sparkles and rainbows, 16 args, no delay: 166 | 0x03, 0x1d, 0x07, 0x06, 167 | 0x2E, 0x2C, 0x29, 0x2D, 168 | 0x2E, 0x2E, 0x37, 0x3F, 169 | 0x00, 0x00, 0x02, 0x10, 170 | ST7735_NORON , DELAY, # 3: Normal display on, no args, w/delay 171 | 10, # 10 ms delay 172 | ST7735_DISPON , DELAY, # 4: Main screen turn on, no args w/delay 173 | 100, # 100 ms delay 174 | ST7735_MADCTL, 1 , # change MADCTL color filter 175 | 0xC0|self._color_mode 176 | ]) 177 | 178 | argcount = 0 179 | cmd = 1 180 | delay = 0 181 | for c in commands: 182 | if argcount == 0: # no arguments collected 183 | if delay: # if a delay flagged this is delay value 184 | if c == 255: # if delay is 255ms make it 500ms 185 | c = 500 186 | time.sleep_ms(c) 187 | delay = 0 188 | else: 189 | if cmd == 1: # need to send command byte 190 | self.command(c) # send coommand 191 | cmd = 0 # clear flag to show command sent 192 | else: 193 | argcount = c & (0xff ^ DELAY) # Clear delay bit and get arguments 194 | delay = c & DELAY # set if delay required 195 | cmd = 1 # flag command now complete 196 | else: # arguments to send 197 | self.data(c) # send argument 198 | argcount -= 1 # decrement the counter 199 | 200 | # display 201 | def set_addr_window(self, x0, y0, x1, y1): 202 | self.command(ST7735_CASET) # Column addr setim 203 | 204 | self.data(0x00) 205 | self.data(x0 + self._offset) # XSTART 206 | self.data(0x00) 207 | self.data(x1 + self._offset) # XEND 208 | 209 | self.command(ST7735_RASET) # Row addr set 210 | self.data(0x00) 211 | self.data(y0 + self._offset) # YSTART 212 | self.data(0x00) 213 | self.data(y1 + self._offset) # YEND 214 | 215 | self.command(ST7735_RAMWR) # write to RAM 216 | 217 | def pixel(self, x, y, color): 218 | 219 | if(x < 0) or (x >= self._width) or (y < 0) or (y >= self._height): 220 | return 221 | 222 | self.set_addr_window(x,y,x+1,y+1) 223 | 224 | a=(color>>8)+((color & 0xff)<<8) # reverse bytes 225 | b=bytearray(a.to_bytes(2)) 226 | self._dc.high() 227 | self._ce.low() 228 | self._spi.write(b) # write 1 byte on MOSI 229 | self._ce.high() 230 | 231 | def draw_block(self,x,y,w,h,color): 232 | size = w * h 233 | max_rows = math.floor(500 / h) 234 | rows = 0 235 | while rows < h: 236 | block_rows = min(max_rows, h-rows) 237 | b=bytes([color>>8, color & 0xff])*w*block_rows 238 | self.draw_bmp(x,y+rows,w,block_rows,b) 239 | rows = rows + max_rows 240 | 241 | def draw_bmp(self,x,y,w,h,buffer): 242 | if((x >= self._width) or (y >= self._height)): 243 | return 244 | if (x + w - 1) >= self._width: 245 | w = self._width - x 246 | if (y + h - 1) >= self._height: 247 | h = self._height - y 248 | self.set_addr_window(x,y,x+w-1,y+h-1) 249 | self._dc.high() 250 | self._ce.low() 251 | self._spi.write(buffer) # write bytes on MOSI 252 | self._ce.high() 253 | 254 | def fill_screen(self,color): 255 | self.draw_block(0,0,self._width,self._height,color) 256 | 257 | def p_char(self, x, y, ch): 258 | fp = (ord(ch)-0x20) * 5 259 | f = open('font5x7.fnt','rb') 260 | f.seek(fp) 261 | b = f.read(5) 262 | char_buf=bytearray(b) 263 | char_buf.append(0) 264 | 265 | # make 8x6 image 266 | char_image = bytearray() 267 | for bit in range(8): 268 | for c in range (6): 269 | if ((char_buf[c]>>bit) & 1)>0: 270 | char_image.append(self._color >> 8) 271 | char_image.append(self._color & 0xff) 272 | else: 273 | char_image.append(self._bground >> 8) 274 | char_image.append(self._bground & 0xff) 275 | self.draw_bmp(x,y,6,8,char_image) 276 | 277 | def p_string(self, x, y, str): 278 | for ch in (str): 279 | self.p_char(x, y, ch) 280 | x += 6 281 | 282 | def rgb_to_565(self,r,g,b): 283 | return ((r & 0xF8) << 8) | ((g & 0xFC) << 3) | (b >> 3) 284 | 285 | def set_rotation(self, m): 286 | self.command(ST7735_MADCTL) 287 | rotation = m % 4 # can't be higher than 3 288 | if rotation == 0: 289 | self.data(ST7735_MADCTL_MX | ST7735_MADCTL_MY | self._color_mode) 290 | self._width = ST7735_TFTWIDTH 291 | self._height = ST7735_TFTHEIGHT 292 | elif rotation == 1: 293 | self.data(ST7735_MADCTL_MY | ST7735_MADCTL_MV | self._color_mode) 294 | self._width = ST7735_TFTHEIGHT 295 | self._height = ST7735_TFTWIDTH 296 | elif rotation == 2: 297 | self.data(self._color_mode) 298 | self._width = ST7735_TFTWIDTH 299 | self._height = ST7735_TFTHEIGHT 300 | elif rotation == 3: 301 | self.data(ST7735_MADCTL_MX | ST7735_MADCTL_MV | self._color_mode) 302 | self._width = ST7735_TFTHEIGHT 303 | self._height = ST7735_TFTWIDTH 304 | 305 | -------------------------------------------------------------------------------- /bmp.py: -------------------------------------------------------------------------------- 1 | def bmp(fname, display, x, y, color=0): 2 | f=open(fname,'rb') 3 | b=bytearray(54) 4 | b=f.read(54) 5 | # header check 6 | if b[0]==0x42 and b[1]==0x4D: 7 | # is bitmap 8 | size = b[2] + (b[3]<<8) + (b[4]<<16) +(b[5]<<24) 9 | offset = b[10] + (b[11]<<8) + (b[12]<<16) +(b[13]<<24) 10 | width = b[18] + (b[19]<<8) + (b[20]<<16) +(b[21]<<24) 11 | height = b[22] + (b[23]<<8) + (b[24]<<16) +(b[25]<<24) 12 | color_planes = b[26] + (b[27]<<8) 13 | bits_per_pixel = b[28] + (b[29]<<8) 14 | compression = b[30] + (b[31]<<8) + (b[32]<<16) +(b[33]<<24) 15 | image_size = b[34] + (b[35]<<8) + (b[36]<<16) +(b[37]<<24) 16 | 17 | f.seek(offset) 18 | 19 | row_bytes = int(bits_per_pixel/8) * width 20 | # Add up to multiple of 4 21 | if row_bytes % 4 > 0: 22 | row_bytes += 4 - row_bytes % 4 23 | 24 | buffer = bytearray(row_bytes) 25 | for row in range(height): 26 | # print(row) 27 | # read in a whole row 28 | buffer=f.read(row_bytes) 29 | d_buffer = bytearray(width*2) 30 | index = 0 31 | for index in range(width): 32 | y1 = (height-1) - row + y 33 | if color: 34 | b = buffer[index*3] 35 | g = buffer[index*3+1] 36 | r = buffer[index*3+2] 37 | c = display.rgb_to_565(r,g,b) 38 | d_buffer[index*2] = c >> 8 39 | d_buffer[index*2+1] = c & 0xff 40 | else: 41 | if buffer[index*3]!=0xff: 42 | display.pixel(x,y,1) 43 | if color: 44 | display.draw_bmp(x,y1,width,1,d_buffer); 45 | f.close() 46 | 47 | -------------------------------------------------------------------------------- /flower160x128.bmp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/AnthonyKNorman/MicroPython_ST7735/3396a5ca5e62e370994f8bad36e0b1da943c605e/flower160x128.bmp -------------------------------------------------------------------------------- /flower64x48.bmp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/AnthonyKNorman/MicroPython_ST7735/3396a5ca5e62e370994f8bad36e0b1da943c605e/flower64x48.bmp -------------------------------------------------------------------------------- /font5x7.fnt: -------------------------------------------------------------------------------- 1 | _$**#db6IU"P"AA"**>P0`` >QIE>B@BaQIF!AEK1'EEE9~~III6>AAA"AA"IIIA >AAQ2AA @A?"A@@@@>AAA> >AQ!^ )FFIII1?@@@? @   ccxaQIECAA AA@@@@@ TTTxHDD88DDD 8DDH8TTT~ TT<xD}@ @D=(DA@|x|x8DDD8|||HTTT ?D@ <@@ | @ <@0@ abs(x1 - x0); 8 | if steep: 9 | x0, y0 = y0, x0 10 | x1, y1 = y1, x1 11 | if x0>x1: 12 | x0, x1 = x1, x0 13 | y0, y1 = y1, y0 14 | dx=x1-x0 15 | dy=abs(y1-y0) 16 | err=dx/2 17 | ystep=-1 18 | if y0 < y1: ystep = 1 19 | for xx in range(x0, x1): 20 | if steep: 21 | thelcd.pixel(y0,xx,fill) 22 | else: 23 | thelcd.pixel(xx,y0,fill) 24 | err-=dy 25 | if err<0: 26 | y0+=ystep 27 | err+=dx 28 | 29 | def drawTrie(x0,y0,x1,y1,x2,y2,thelcd,fill): 30 | drawLine(x0,y0,x1,y1,thelcd,fill) 31 | drawLine(x2,y2,x1,y1,thelcd,fill) 32 | drawLine(x2,y2,x0,y0,thelcd,fill) 33 | 34 | def drawFillTrie(x0,y0,x1,y1,x2,y2,thelcd,fill): 35 | if y0 > y1: 36 | y0, y1=y1, y0 37 | x0, x1=x1, x0 38 | 39 | if y1 > y2: 40 | y2, y1=y1,y2 41 | x2, x1=x1,x2 42 | 43 | if y0 > y1: 44 | y0, y1=y1,y0 45 | x0, x1=x1,x0 46 | 47 | if y0 == y2: 48 | a = x0 49 | b = x0 50 | if x1 < a: 51 | a = x1 52 | else: 53 | if x1 > b: 54 | b = x1 55 | if x2 < a: 56 | a = x2 57 | else: 58 | if x2 > b: 59 | b = x2 60 | drawLine(a, y0,b+1,y0,thelcd,fill) 61 | return 62 | 63 | dx01 = x1 - x0 64 | dy01 = y1 - y0 65 | dx02 = x2 - x0 66 | dy02 = y2 - y0 67 | dx12 = x2 - x1 68 | dy12 = y2 - y1 69 | sa = 0 70 | sb = 0 71 | 72 | if y1 == y2: 73 | last = y1 74 | else: 75 | last = y1-1 76 | 77 | y=y0 78 | 79 | for y in range(y0, last+1): 80 | a= x0 + sa / dy01 81 | b= x0 + sb / dy02 82 | sa += dx01 83 | sb += dx02 84 | if a > b: 85 | a,b=b,a 86 | drawLine(int(a), y,int(b+1),y,thelcd,fill) 87 | 88 | sa = dx12 * (y - y1) 89 | sb = dx02 * (y - y0) 90 | 91 | for y in range(last+1, y2+1): 92 | a = x1 + sa / dy12 93 | b = x0 + sb / dy02 94 | sa += dx12 95 | sb += dx02 96 | if a > b: 97 | a,b=b,a 98 | drawLine(int(a), y,int(b+1),y,thelcd,fill) 99 | 100 | 101 | def drawRect(x,y,w,h,thelcd,fill): 102 | drawLine(x,y,x+w,y,thelcd,fill) 103 | drawLine(x+w-1,y,x+w-1,y+h,thelcd,fill) 104 | drawLine(x+w,y+h-1,x,y+h-1,thelcd,fill) 105 | drawLine(x,y+h,x,y,thelcd,fill) 106 | 107 | def drawFillRect(x,y,w,h,thelcd,fill): 108 | xa=x 109 | xe=x+w 110 | ya=y 111 | ye=y+h 112 | if xa>xe: 113 | xa,xe = xe,xa 114 | 115 | if ya>ye: 116 | ya,ye=ye,ya 117 | 118 | for yy in range(ya, ye): 119 | for xx in range(xa,xe): 120 | thelcd.pixel(xx,yy,fill) 121 | 122 | def drawCircle(x0,y0,r,thelcd,fill): 123 | f=1-r 124 | ddF_x = 1 125 | ddF_y = -2 * r 126 | x = 0 127 | y = r 128 | thelcd.pixel(x0 , y0+r,fill) 129 | thelcd.pixel(x0 , y0-r,fill) 130 | thelcd.pixel(x0+r, y0 ,fill) 131 | thelcd.pixel(x0-r, y0 ,fill) 132 | while x=0: 134 | y-=1 135 | ddF_y+=2 136 | f+=ddF_y 137 | x+=1 138 | ddF_x+=2 139 | f+=ddF_x 140 | thelcd.pixel(x0+x, y0+y, fill); 141 | thelcd.pixel(x0-x, y0+y, fill); 142 | thelcd.pixel(x0+x, y0-y, fill); 143 | thelcd.pixel(x0-x, y0-y, fill); 144 | thelcd.pixel(x0+y, y0+x, fill); 145 | thelcd.pixel(x0-y, y0+x, fill); 146 | thelcd.pixel(x0+y, y0-x, fill); 147 | thelcd.pixel(x0-y, y0-x, fill); 148 | 149 | def drawfillCircle(x0,y0,r,thelcd,fill): 150 | drawLine(x0, y0-r, x0,y0-r+2*r+1,thelcd, fill) 151 | f = 1 - r 152 | ddF_x = 1 153 | ddF_y = -2 * r 154 | x = 0 155 | y = r 156 | while x=0: 158 | y-=1 159 | ddF_y+=2 160 | f+=ddF_y 161 | x+=1 162 | ddF_x+=2 163 | f+=ddF_x 164 | drawLine(x0+x, y0-y, x0+x, y0-y+2*y+1,thelcd, fill); 165 | drawLine(x0+y, y0-x, x0+y, y0-x+2*x+1,thelcd, fill); 166 | drawLine(x0-x, y0-y, x0-x, y0-y+2*y+1,thelcd, fill); 167 | drawLine(x0-y, y0-x, x0-y, y0-x+2*x+1,thelcd, fill); 168 | 169 | -------------------------------------------------------------------------------- /main.py: -------------------------------------------------------------------------------- 1 | import time 2 | import lcd_gfx 3 | from bmp import bmp 4 | import machine 5 | import ST7735 6 | 7 | spi = machine.SPI(1, baudrate=8000000, polarity=0, phase=0) 8 | d = ST7735.ST7735(spi, rst=4, ce=5, dc=16) 9 | d.reset() 10 | d.begin() 11 | d._bground = 0xffff 12 | d.fill_screen(d._bground) 13 | 14 | d.set_rotation(0) 15 | bmp('flower64x48.bmp',d,10,10,1) 16 | 17 | d.set_rotation(1) 18 | bmp('flower64x48.bmp',d,10,10,1) 19 | 20 | d.set_rotation(2) 21 | bmp('flower64x48.bmp',d,10,10,1) 22 | 23 | d.set_rotation(3) 24 | bmp('flower64x48.bmp',d,10,10,1) 25 | 26 | d._color = 0 27 | d.set_rotation(0) 28 | d.p_string(10,10,'Hello World') 29 | 30 | d._color = 0xf100 31 | d.set_rotation(1) 32 | d.p_string(10,10,'Hello World') 33 | 34 | d._color = 0x07e0 35 | d.set_rotation(2) 36 | d.p_string(10,10,'Hello World') 37 | 38 | d._color = 0x001f 39 | d.set_rotation(3) 40 | d.p_string(10,10,'Hello World') 41 | 42 | time.sleep(5) 43 | d.set_rotation(3) 44 | bmp('flower160x128.bmp',d,0,0,1) 45 | 46 | time.sleep(5) 47 | x = int(d._width/2) 48 | y = int(d._height/2) 49 | r = int(min(x,y)/2) 50 | d.fill_screen(d.rgb_to_565(255,255,255)) 51 | color = d.rgb_to_565(0,36,125) 52 | lcd_gfx.drawfillCircle(x,y,r,d,color) 53 | r = int(r*2/3) 54 | color = d.rgb_to_565(255,255,255) 55 | lcd_gfx.drawfillCircle(x,y,r,d,color) 56 | r = int(r/2) 57 | color = d.rgb_to_565(206,17,38) 58 | lcd_gfx.drawfillCircle(x,y,r,d,color) 59 | --------------------------------------------------------------------------------