"""ILI9341 demo (fonts rotated)."""
from time import sleep
from ili9341 import Display, color565
from machine import Pin, SPI
from xglcd_font import XglcdFont
import mySetup
def test():
"""Test code."""
display = mySetup.createMyDisplay()
# Baud rate of 40000000 seems about the max
#spi = SPI(1, baudrate=40000000, sck=Pin(14), mosi=Pin(13))
#display = Display(spi, dc=Pin(4), cs=Pin(16), rst=Pin(17))
print('Loading fonts...')
print('Loading arcadepix')
arcadepix = XglcdFont('ArcadePix9x11.c', 9, 11)
print('Loading bally')
bally = XglcdFont('Bally7x9.c', 7, 9)
print('Loading broadway')
broadway = XglcdFont('Broadway17x15.c', 17, 15)
print('Loading espresso_dolce')
espresso_dolce = XglcdFont('EspressoDolce18x24.c', 18, 24)
print('Loading fixed_font')
fixed_font = XglcdFont('FixedFont5x8.c', 5, 8)
print('Loading neato')
neato = XglcdFont('Neato5x7.c', 5, 7, letter_count=223)
print('Loading robotron')
robotron = XglcdFont('Robotron13x21.c', 13, 21)
print('Loading unispace')
unispace = XglcdFont('Unispace12x24.c', 12, 24)
print('Loading wendy')
wendy = XglcdFont('Wendy7x8.c', 7, 8)
print('Fonts loaded.')
display.draw_text(0, 0, 'Arcade Pix 9x11', arcadepix, color565(255, 0, 0), rotate_180=True)
display.draw_text(0, 22, 'Bally 7x9', bally, color565(0, 255, 0), rotate_180=True)
display.draw_text(0, 43, 'Broadway 17x15', broadway, color565(0, 0, 255), rotate_180=True)
display.draw_text(0, 66, 'Espresso Dolce 18x24', espresso_dolce,
color565(0, 255, 255), rotate_180=True)
display.draw_text(0, 104, 'Fixed Font 5x8', fixed_font,
color565(255, 0, 255), rotate_180=True)
display.draw_text(0, 125, 'Neato 5x7', neato, color565(255, 255, 0), rotate_180=True)
display.draw_text(0, 155, 'ROBOTRON 13X21', robotron,
color565(255, 255, 255), rotate_180=True)
display.draw_text(0, 190, 'Unispace 12x24', unispace,
color565(255, 128, 0), rotate_180=True)
display.draw_text(0, 220, 'Wendy 7x8', wendy, color565(255, 0, 128), rotate_180=True)
sleep(9)
display.clear()
display.draw_text(0, 320, 'Arcade Pix 9x11 plop', arcadepix,
color565(255, 0, 0),
landscape=True)
display.draw_text(12, 320, 'Arcade Pix 9x11 plop', arcadepix,
color565(255, 0, 0),
landscape=True)
display.draw_text(22, 255, 'Bally 7x9', bally, color565(0, 255, 0),
landscape=True)
display.draw_text(43, 255, 'Broadway 17x15', broadway, color565(0, 0, 255),
landscape=True)
display.draw_text(66, 255, 'Espresso Dolce 18x24', espresso_dolce,
color565(0, 255, 255), landscape=True)
display.draw_text(104, 255, 'Fixed Font 5x8', fixed_font,
color565(255, 0, 255), landscape=True)
display.draw_text(125, 255, 'Neato 5x7', neato, color565(255, 255, 0),
landscape=True)
display.draw_text(155, 255, 'ROBOTRON 13X21', robotron,
color565(255, 255, 255),
landscape=True)
display.draw_text(190, 255, 'Unispace 12x24', unispace,
color565(255, 128, 0),
landscape=True)
display.draw_text(220, 255, 'Wendy 7x8', wendy, color565(255, 0, 128),
landscape=True)
sleep(9)
display.clear()
display.draw_text(0, 0, 'Arcade Pix 9x11', arcadepix, color565(255, 0, 0),
background=color565(0, 255, 255), rotate_180=True)
display.draw_text(0, 22, 'Bally 7x9', bally, color565(0, 255, 0),
background=color565(0, 0, 128), rotate_180=True)
display.draw_text(0, 43, 'Broadway', broadway, color565(0, 0, 255),
background=color565(255, 255, 0), rotate_180=True)
display.draw_text(0, 66, 'Espresso', espresso_dolce,
color565(0, 255, 255), background=color565(255, 0, 0), rotate_180=True)
display.draw_text(0, 104, 'Fixed Font 5x8', fixed_font,
color565(255, 0, 255), background=color565(0, 128, 0), rotate_180=True)
display.draw_text(0, 125, 'Neato 5x7', neato, color565(255, 255, 0),
background=color565(0, 0, 255), rotate_180=True)
display.draw_text(0, 155, 'ROBOTRON 13X21', robotron,
color565(255, 255, 255),
background=color565(128, 128, 128), rotate_180=True)
display.draw_text(0, 190, 'Unispace 0123456789', unispace,
color565(255, 255, 255),
background=color565(128, 128, 128), rotate_180=True)
display.draw_text(0, 230, 'Unispace', unispace, color565(255, 128, 0),
background=color565(0, 128, 255), rotate_180=True)
display.draw_text(0, 260, 'Wendy 7x8', wendy, color565(255, 0, 128),
background=color565(255, 255, 255), rotate_180=True)
sleep(9)
display.clear()
# ArcadePix
font_height = arcadepix.height
display.draw_text(0, 0,
'Portrait', arcadepix,
color565(255, 255, 0),
landscape=False, rotate_180=False)
text_width = arcadepix.measure_text('Landscape')
display.draw_text(0, display.height - 1,
'Landscape', arcadepix,
color565(255, 0, 0),
landscape=True, rotate_180=False)
text_width = arcadepix.measure_text('Portrait, Rotate 180')
display.draw_text(display.width - text_width - 1,
display.height - font_height,
'Portrait, Rotate 180', arcadepix,
color565(255, 0, 255),
landscape=False, rotate_180=True)
text_width = arcadepix.measure_text('Landscape, Rotate 180')
display.draw_text(display.width - font_height - 1 , text_width,
'Landscape, Rotate 180', arcadepix,
color565(0, 0, 255),
landscape=True, rotate_180=True)
sleep(5)
# Espresso Dolce
display.clear()
font_height = espressodolce.height
display.draw_text(0, 0,
'PORTRAIT', espressodolce,
color565(255, 255, 0),
landscape=False, rotate_180=False)
text_width = espressodolce.measure_text('LANDSCAPE')
display.draw_text(0, display.height - 1,
'LANDSCAPE', espressodolce,
color565(255, 0, 0),
landscape=True, rotate_180=False)
text_width = espressodolce.measure_text('PORTRAIT,')
display.draw_text(display.width - text_width - 1,
display.height - font_height,
'PORTRAIT,', espressodolce,
color565(255, 0, 255),
landscape=False, rotate_180=True)
text_width = espressodolce.measure_text('ROTATE 180')
display.draw_text(display.width - text_width - 1,
display.height - font_height * 2,
'ROTATE 180', espressodolce,
color565(255, 0, 255),
landscape=False, rotate_180=True)
text_width = espressodolce.measure_text('LANDSCAPE,')
display.draw_text(display.width - font_height - 1 , text_width,
'LANDSCAPE,', espressodolce,
color565(0, 0, 255),
landscape=True, rotate_180=True)
text_width = espressodolce.measure_text('ROTATE 180')
display.draw_text(display.width - font_height * 2 - 1 , text_width,
'ROTATE 180', espressodolce,
color565(0, 0, 255),
landscape=True, rotate_180=True)
sleep(5)
# Neato
display.clear()
font_height = neato.height
display.draw_text(0, 0,
'Portrait', neato,
color565(255, 255, 0),
landscape=False, rotate_180=False)
text_width = neato.measure_text('Landscape')
display.draw_text(0, display.height - 1,
'Landscape', neato,
color565(255, 0, 0),
landscape=True, rotate_180=False)
text_width = neato.measure_text('Portrait, Rotate 180')
display.draw_text(display.width - text_width - 1,
display.height - font_height,
'Portrait, Rotate 180', neato,
color565(255, 0, 255),
landscape=False, rotate_180=True)
text_width = neato.measure_text('Landscape, Rotate 180')
display.draw_text(display.width - font_height - 1 , text_width,
'Landscape, Rotate 180', neato,
color565(0, 0, 255),
landscape=True, rotate_180=True)
sleep(5)
# Robotron
display.clear()
font_height = robotron.height
display.draw_text(0, 0,
'PORTRAIT', robotron,
color565(255, 255, 0),
landscape=False, rotate_180=False)
text_width = robotron.measure_text('LANDSCAPE')
display.draw_text(0, display.height - 1,
'LANDSCAPE', robotron,
color565(255, 0, 0),
landscape=True, rotate_180=False)
text_width = robotron.measure_text('PORTRAIT,')
display.draw_text(display.width - text_width - 1,
display.height - font_height,
'PORTRAIT,', robotron,
color565(255, 0, 255),
landscape=False, rotate_180=True)
text_width = robotron.measure_text('ROTATE 180')
display.draw_text(display.width - text_width - 1,
display.height - font_height * 2,
'ROTATE 180', robotron,
color565(255, 0, 255),
landscape=False, rotate_180=True)
text_width = robotron.measure_text('LANDSCAPE,')
display.draw_text(display.width - font_height - 1 , text_width,
'LANDSCAPE,', robotron,
color565(0, 0, 255),
landscape=True, rotate_180=True)
text_width = robotron.measure_text('ROTATE 180')
display.draw_text(display.width - font_height * 2 - 1 , text_width,
'ROTATE 180', robotron,
color565(0, 0, 255),
landscape=True, rotate_180=True)
sleep(5)
# Unispace
display.clear()
font_height = unispace.height
display.draw_text(0, 0,
'PORTRAIT', unispace,
color565(255, 255, 0),
background=color565(255, 0, 0),
landscape=False, rotate_180=False)
text_width = unispace.measure_text('LANDSCAPE')
display.draw_text(0, display.height - 1,
'LANDSCAPE', unispace,
color565(255, 0, 0),
background=color565(255, 255, 0),
landscape=True, rotate_180=False)
text_width = unispace.measure_text('PORTRAIT,')
display.draw_text(display.width - text_width - 1,
display.height - font_height,
'PORTRAIT,', unispace,
color565(255, 0, 255),
background=color565(0, 255, 0),
landscape=False, rotate_180=True)
text_width = unispace.measure_text('ROTATE 180')
display.draw_text(display.width - text_width - 1,
display.height - font_height * 2,
'ROTATE 180', unispace,
color565(255, 0, 255),
background=color565(0, 255, 0),
landscape=False, rotate_180=True)
text_width = unispace.measure_text('LANDSCAPE,')
display.draw_text(display.width - font_height - 1 , text_width,
'LANDSCAPE,', unispace,
color565(0, 0, 255),
background=color565(255, 255, 0),
landscape=True, rotate_180=True)
text_width = unispace.measure_text('ROTATE 180')
display.draw_text(display.width - font_height * 2 - 1 , text_width,
'ROTATE 180', unispace,
color565(0, 0, 255),
background=color565(255, 255, 0),
landscape=True, rotate_180=True)
sleep(10)
display.cleanup()
test()