charlcd_custom_character_nyan_cat.py
1 """Use custom characters to display Nyan cat""" 2 import time 3 import board 4 import digitalio 5 import adafruit_character_lcd.character_lcd as characterlcd 6 7 # Modify this if you have a different sized character LCD 8 lcd_columns = 16 9 lcd_rows = 2 10 11 # Metro M0/M4 Pin Config: 12 lcd_rs = digitalio.DigitalInOut(board.D7) 13 lcd_en = digitalio.DigitalInOut(board.D8) 14 lcd_d7 = digitalio.DigitalInOut(board.D12) 15 lcd_d6 = digitalio.DigitalInOut(board.D11) 16 lcd_d5 = digitalio.DigitalInOut(board.D10) 17 lcd_d4 = digitalio.DigitalInOut(board.D9) 18 lcd_backlight = digitalio.DigitalInOut(board.D13) 19 20 # Initialise the LCD class 21 lcd = characterlcd.Character_LCD_Mono( 22 lcd_rs, lcd_en, lcd_d4, lcd_d5, lcd_d6, lcd_d7, lcd_columns, lcd_rows, lcd_backlight 23 ) 24 25 head = [31, 17, 27, 17, 17, 21, 17, 31] 26 27 top_body = [31, 0, 31, 0, 18, 8, 2, 8] 28 top_left_corner_body = [31, 16, 16, 17, 22, 20, 20, 20] 29 top_right_corner_body = [31, 1, 1, 17, 13, 5, 5, 5] 30 31 # these three chars will be the above three reversed with a few minor changes to 32 # fit feet into the bottom 33 bot_body = [] 34 bot_left_corner_body = [] 35 bot_right_corner_body = [] 36 37 tail_neutral = [0, 0, 0, 0, 31, 31, 0, 0] 38 tail_up = [0, 8, 12, 6, 3, 1, 0, 0] 39 40 for i in range(7, -1, -1): 41 bot_body.append(top_body[i]) 42 bot_left_corner_body.append(top_left_corner_body[i]) 43 bot_right_corner_body.append(top_right_corner_body[i]) 44 45 # adding feet and making space for them 46 47 bot_body[6] = 31 48 bot_body[5] = 0 49 bot_body[4] = 31 50 bot_body[7] = 24 51 bot_left_corner_body[7] = 0 52 bot_left_corner_body[6] = 31 53 bot_left_corner_body[7] = 28 54 bot_right_corner_body[7] = 0 55 bot_right_corner_body[6] = 31 56 57 # bottom body with feet forward 58 bot_body2 = bot_body[:-1] + [3] 59 60 61 rainbow = [0, 0, 6, 25, 11, 29, 27, 12] 62 rainbow2 = [0, 0, 6, 31, 13, 5, 23, 12] 63 64 lcd.create_char(0, top_body) 65 lcd.create_char(1, top_left_corner_body) 66 lcd.create_char(2, rainbow) 67 lcd.create_char(3, bot_left_corner_body) 68 lcd.create_char(4, bot_body) 69 lcd.create_char(5, bot_right_corner_body) 70 lcd.create_char(6, head) 71 lcd.create_char(7, tail_neutral) 72 73 lcd.clear() 74 75 lcd.move_right() 76 lcd.message = ( 77 "\x02\x02\x02\x02\x01\x00\x00\x00\x06\n\x02\x02\x02\x07\x03\x04\x04\x04\x05" 78 ) 79 80 lcd.backlight = True 81 82 while True: 83 lcd.create_char(4, bot_body2) 84 lcd.create_char(7, tail_up) 85 lcd.create_char(2, rainbow2) 86 lcd.move_right() 87 time.sleep(0.4) 88 lcd.create_char(4, bot_body) 89 lcd.create_char(7, tail_neutral) 90 lcd.create_char(2, rainbow) 91 lcd.move_left() 92 time.sleep(0.4)