#=======Imports========#
from machine import Pin, SPI
import time
import max7219
import utime
#=======Initialize SPI========#
# Initialize the first SPI -eye
spi1 = SPI(0, baudrate=10000000, polarity=1, phase=0, sck=Pin(2), mosi=Pin(3))
ss1 = Pin(1, Pin.OUT)
# Initialize the second SPI -nose
spi2 = SPI(1, baudrate=10000000, polarity=1, phase=0, sck=Pin(10), mosi=Pin(11))
ss2 = Pin(9, Pin.OUT)
# Initialize the third SPI -mouth right
spi3 = SPI(0, baudrate=10000000, polarity=1, phase=0, sck=Pin(18), mosi=Pin(19))
ss3 = Pin(17, Pin.OUT)
# Initialize the forth SPI -mouth left
spi4 = SPI(0, baudrate=10000000, polarity=1, phase=0, sck=Pin(6), mosi=Pin(7))
ss4 = Pin(5, Pin.OUT)
#=======BITMAPS========#
# right Eye defalt
eyeR = [[
0b11000011,
0b01100110,
0b00111100,
0b00000000,
0b00000000,
0b00000000,
0b00000000,
0b00000000
],[
0b00000000,
0b00000000,
0b00000000,
0b00000000,
0b00111100,
0b01100110,
0b11000011,
0b11000011
],[
0b00000000,
0b00000000,
0b00000000,
0b00000000,
0b00000000,
0b00000000,
0b00000000,
0b00000000
],[
0b00000000,
0b00000000,
0b00000000,
0b00000000,
0b00000000,
0b00000000,
0b00000000,
0b00000000
],]
# left Eye defalt
eyeL = [[
0b00000000,
0b00000000,
0b00000000,
0b00000000,
0b00000000,
0b00000000,
0b00000000,
0b00000000
],[
0b00000000,
0b00000000,
0b00000000,
0b00000000,
0b00000000,
0b00000000,
0b00000000,
0b00000000
],[
0b11000011,
0b01100110,
0b00111100,
0b00000000,
0b00000000,
0b00000000,
0b00000000,
0b00000000
],[
0b00000000,
0b00000000,
0b00000000,
0b00000000,
0b00111100,
0b01100110,
0b11000011,
0b11000011
],]
# nose defalt
nose1 = [[
0b00000000,
0b00000000,
0b00000000,
0b00000000,
0b00000000,
0b00000000,
0b00000000,
0b00000000
],[
0b00000000,
0b00000000,
0b00000000,
0b00000000,
0b00000000,
0b00000000,
0b00000000,
0b00000000
],[
0b00000000,
0b00000000,
0b00000000,
0b00000000,
0b00000000,
0b00000000,
0b00000000,
0b00000000
],[
0b00011110,
0b01111000,
0b01110000,
0b11100000,
0b11000000,
0b10000000,
0b10000000,
0b00000000
],]
# Right mouth defalt
mouth1R = [ [
0b00001100,
0b00111000,
0b00111000,
0b01101000,
0b01101000,
0b11001000,
0b01111000,
0b00111000
],[
0b00000011,
0b00000001,
0b00000001,
0b00000011,
0b00000011,
0b00000110,
0b00000110,
0b00001100
],[
0b00011000,
0b00011000,
0b00001000,
0b00001100,
0b00001100,
0b00000110,
0b00000110,
0b00000011
],[
0b00000011,
0b00000110,
0b00000110,
0b00001100,
0b00011000,
0b00011000,
0b00110000,
0b00110000
]]
# Left mouth defalt
mouth1L = [[
0b00110000,
0b00110000,
0b00011000,
0b00011000,
0b00001100,
0b00000110,
0b00000110,
0b00000011
],[
0b00000011,
0b00000110,
0b00000110,
0b00001100,
0b00001100,
0b00001000,
0b00011000,
0b00011000
],[
0b00001100,
0b00000110,
0b00000110,
0b00000011,
0b00000011,
0b00000001,
0b00000001,
0b00000011
],[
0b00111000,
0b01111000,
0b11001000,
0b01101000,
0b01101000,
0b00111000,
0b00111000,
0b00001100
]]
# Right eyes swull 1
swullR1= [[
0b10101101,
0b10100001,
0b10111111,
0b10000000,
0b11111111,
0b00000000,
0b00000000,
0b00000000
],[
0b00000000,
0b00000000,
0b00000000,
0b00000000,
0b00000000,
0b11111111,
0b10000001,
0b10111101
],[
0b00000000,
0b00000000,
0b00000000,
0b00000000,
0b00000000,
0b00000000,
0b00000000,
0b00000000
],[
0b00000000,
0b00000000,
0b00000000,
0b00000000,
0b00000000,
0b00000000,
0b00000000,
0b00000000
],]
# Right eyes swull 2
swullR2= [[
0b10100101,
0b10101101,
0b10101101,
0b10100001,
0b10111111,
0b00000000,
0b00000000,
0b00000000
],[
0b00000000,
0b00000000,
0b00000000,
0b00000000,
0b00000000,
0b11111111,
0b10000001,
0b10111101
],[
0b00000000,
0b00000000,
0b00000000,
0b00000000,
0b00000000,
0b00000000,
0b00000000,
0b00000000
],[
0b00000000,
0b00000000,
0b00000000,
0b00000000,
0b00000000,
0b00000000,
0b00000000,
0b00000000
],]
# Right eyes swull 3
swullR3= [[
0b10000101,
0b10110101,
0b10111101,
0b10000001,
0b11111111,
0b00000000,
0b00000000,
0b00000000
],[
0b00000000,
0b00000000,
0b00000000,
0b00000000,
0b00000000,
0b11111111,
0b00000001,
0b11111101
],[
0b00000000,
0b00000000,
0b00000000,
0b00000000,
0b00000000,
0b00000000,
0b00000000,
0b00000000
],[
0b00000000,
0b00000000,
0b00000000,
0b00000000,
0b00000000,
0b00000000,
0b00000000,
0b00000000
],]
# Right eyes swull 4
swullR4= [[
0b10110101,
0b10100101,
0b10111101,
0b10000001,
0b11111111,
0b00000000,
0b00000000,
0b00000000
],[
0b00000000,
0b00000000,
0b00000000,
0b00000000,
0b00000000,
0b11111101,
0b10000101,
0b10110101
],[
0b00000000,
0b00000000,
0b00000000,
0b00000000,
0b00000000,
0b00000000,
0b00000000,
0b00000000
],[
0b00000000,
0b00000000,
0b00000000,
0b00000000,
0b00000000,
0b00000000,
0b00000000,
0b00000000
],]
# Left eyes swull 1
swullL1= [[
0b00000000,
0b00000000,
0b00000000,
0b00000000,
0b00000000,
0b00000000,
0b00000000,
0b00000000
],[
0b00000000,
0b00000000,
0b00000000,
0b00000000,
0b00000000,
0b00000000,
0b00000000,
0b00000000
],[
0b10100001,
0b10101101,
0b10111101,
0b10000001,
0b11111111,
0b00000000,
0b00000000,
0b00000000
],[
0b00000000,
0b00000000,
0b00000000,
0b00000000,
0b00000000,
0b11111111,
0b10000000,
0b10111111
],]
# Left eyes swull 2
swullL2= [[
0b00000000,
0b00000000,
0b00000000,
0b00000000,
0b00000000,
0b00000000,
0b00000000,
0b00000000
],[
0b00000000,
0b00000000,
0b00000000,
0b00000000,
0b00000000,
0b00000000,
0b00000000,
0b00000000
],[
0b10101101,
0b10100101,
0b10111101,
0b10000001,
0b11111111,
0b00000000,
0b00000000,
0b00000000
],[
0b00000000,
0b00000000,
0b00000000,
0b00000000,
0b00000000,
0b10111111,
0b10100001,
0b10101101
],]
# Left eyes swull 3
swullL3= [[
0b00000000,
0b00000000,
0b00000000,
0b00000000,
0b00000000,
0b00000000,
0b00000000,
0b00000000
],[
0b00000000,
0b00000000,
0b00000000,
0b00000000,
0b00000000,
0b00000000,
0b00000000,
0b00000000
],[
0b10110101,
0b10000101,
0b11111101,
0b00000001,
0b11111111,
0b00000000,
0b00000000,
0b00000000
],[
0b00000000,
0b00000000,
0b00000000,
0b00000000,
0b00000000,
0b11111111,
0b10000001,
0b10111101
],]
# Left eyes swull 4
swullL4= [[
0b00000000,
0b00000000,
0b00000000,
0b00000000,
0b00000000,
0b00000000,
0b00000000,
0b00000000
],[
0b00000000,
0b00000000,
0b00000000,
0b00000000,
0b00000000,
0b00000000,
0b00000000,
0b00000000
],[
0b10100101,
0b10110101,
0b10110101,
0b10000101,
0b11111101,
0b00000000,
0b00000000,
0b00000000
],[
0b00000000,
0b00000000,
0b00000000,
0b00000000,
0b00000000,
0b11111111,
0b10000001,
0b10111101
],]
# blink for Right eye
blinkR = [[
0b00110011,
0b01100011,
0b11000011,
0b10000010,
0b00000000,
0b00000000,
0b00000000,
0b00000000
],[
0b00000000,
0b00000000,
0b00000000,
0b00000000,
0b00000010,
0b00000111,
0b00001111,
0b00011011
],[
0b00000000,
0b00000000,
0b00000000,
0b00000000,
0b00000000,
0b00000000,
0b00000000,
0b00000000
],[
0b00000000,
0b00000000,
0b00000000,
0b00000000,
0b00000000,
0b00000000,
0b00000000,
0b00000000
],]
# blink for left eye
blinkL = [[
0b00000000,
0b00000000,
0b00000000,
0b00000000,
0b00000000,
0b00000000,
0b00000000,
0b00000000
],[
0b00000000,
0b00000000,
0b00000000,
0b00000000,
0b00000000,
0b00000000,
0b00000000,
0b00000000
],[
0b00011011,
0b00001111,
0b00000111,
0b00000010,
0b00000000,
0b00000000,
0b00000000,
0b00000000
],[
0b00000000,
0b00000000,
0b00000000,
0b00000000,
0b10000010,
0b11000011,
0b01100011,
0b00110011
],]
# heart for Right eye 1
heartR1 = [[
0b01100011,
0b11000110,
0b11001100,
0b01111000,
0b00000000,
0b00000000,
0b00000000,
0b00000000
],[
0b00000000,
0b00000000,
0b00000000,
0b00000000,
0b01111000,
0b11001100,
0b11000110,
0b01100011
],[
0b00000000,
0b00000000,
0b00000000,
0b00000000,
0b00000000,
0b00000000,
0b00000000,
0b00000000
],[
0b00000000,
0b00000000,
0b00000000,
0b00000000,
0b00000000,
0b00000000,
0b00000000,
0b00000000
],]
# heart for Right eye 2
heartR2 = [[
0b00111110,
0b01111100,
0b00111000,
0b00000000,
0b00000000,
0b00000000,
0b00000000,
0b00000000
],[
0b00000000,
0b00000000,
0b00000000,
0b00000000,
0b00000000,
0b00111000,
0b01111100,
0b00111110
],[
0b00000000,
0b00000000,
0b00000000,
0b00000000,
0b00000000,
0b00000000,
0b00000000,
0b00000000
],[
0b00000000,
0b00000000,
0b00000000,
0b00000000,
0b00000000,
0b00000000,
0b00000000,
0b00000000
],]
# heart for Left eye 1
heartL1 = [[
0b00000000,
0b00000000,
0b00000000,
0b00000000,
0b00000000,
0b00000000,
0b00000000,
0b00000000
],[
0b00000000,
0b00000000,
0b00000000,
0b00000000,
0b00000000,
0b00000000,
0b00000000,
0b00000000
],[
0b01100011,
0b11000110,
0b11001100,
0b01111000,
0b00000000,
0b00000000,
0b00000000,
0b00000000
],[
0b00000000,
0b00000000,
0b00000000,
0b00000000,
0b01111000,
0b11001100,
0b11000110,
0b01100011
],]
# heart for Left eye 2
heartL2 = [[
0b00000000,
0b00000000,
0b00000000,
0b00000000,
0b00000000,
0b00000000,
0b00000000,
0b00000000
],[
0b00000000,
0b00000000,
0b00000000,
0b00000000,
0b00000000,
0b00000000,
0b00000000,
0b00000000
],[
0b00111110,
0b01111100,
0b00111000,
0b00000000,
0b00000000,
0b00000000,
0b00000000,
0b00000000
],[
0b00000000,
0b00000000,
0b00000000,
0b00000000,
0b00000000,
0b00111000,
0b01111100,
0b00111110
],]
# Talk for Right mouth
talkR = [[
0b11111100,
0b11111100,
0b11111100,
0b11111100,
0b01111100,
0b00111110,
0b00111110,
0b00011111
],[
0b00001111,
0b00011110,
0b00011110,
0b00111110,
0b00111110,
0b00111110,
0b01111110,
0b01111110
],[
0b00111100,
0b00011110,
0b00011110,
0b00001111,
0b00001111,
0b00000111,
0b00000111,
0b00001111
],[
0b00111000,
0b01111000,
0b11001000,
0b01101000,
0b01101000,
0b00111000,
0b00111000,
0b00111100
],]
# Talk for Left mouth
talkL = [[
0b00111100,
0b00111000,
0b00111000,
0b01101000,
0b01101000,
0b11001000,
0b01111000,
0b00111000
],[
0b00001111,
0b00000111,
0b00000111,
0b00001111,
0b00001111,
0b00011110,
0b00011110,
0b00111100
],[
0b01111110,
0b01111110,
0b00111110,
0b00111110,
0b00111110,
0b00011110,
0b00011110,
0b00001111
],[
0b00011111,
0b00111110,
0b00111110,
0b01111100,
0b11111100,
0b11111100,
0b11111100,
0b11111100
],]
# Mad for Right eye
madeyeR = [[
0b01100011,
0b01100110,
0b00111100,
0b00000000,
0b00000000,
0b00000000,
0b00000000,
0b00000000
],[
0b00000000,
0b00000000,
0b00000000,
0b00000000,
0b00001100,
0b00011110,
0b00110011,
0b00100011
],[
0b00000000,
0b00000000,
0b00000000,
0b00000000,
0b00000000,
0b00000000,
0b00000000,
0b00000000
],[
0b00000000,
0b00000000,
0b00000000,
0b00000000,
0b00000000,
0b00000000,
0b00000000,
0b00000000
],]
# Mad for Left eye
madeyeL = [[
0b00000000,
0b00000000,
0b00000000,
0b00000000,
0b00000000,
0b00000000,
0b00000000,
0b00000000
],[
0b00000000,
0b00000000,
0b00000000,
0b00000000,
0b00000000,
0b00000000,
0b00000000,
0b00000000
],[
0b00110011,
0b00011110,
0b00001100,
0b00000000,
0b00000000,
0b00000000,
0b00000000,
0b00000000
],[
0b00000000,
0b00000000,
0b00000000,
0b00000000,
0b00111100,
0b01100110,
0b01100011,
0b00100011
],]
# Mad For right Mouth
madmouthR = [[
0b00001100,
0b00000111,
0b00001111,
0b00011011,
0b00011011,
0b00110011,
0b00111110,
0b00011100
],[
0b00110000,
0b01100000,
0b01100000,
0b00110000,
0b00110000,
0b00011000,
0b00011000,
0b00001100
],[
0b00000110,
0b00000110,
0b00000100,
0b00001100,
0b00001100,
0b00011000,
0b00011000,
0b00110000
],[
0b00110000,
0b00011000,
0b00001100,
0b00001100,
0b00000110,
0b00000110,
0b00000011,
0b00000011
],]
# Mad for left Mouth
madmouthL = [[
0b00000011,
0b00000011,
0b00000110,
0b00000110,
0b00001100,
0b00001100,
0b00011000,
0b00110000
],[
0b00110000,
0b00011000,
0b00011000,
0b00001100,
0b00001100,
0b00000100,
0b00000110,
0b00000110
],[
0b00001100,
0b00011000,
0b00011000,
0b00110000,
0b00110000,
0b01100000,
0b01100000,
0b00110000
],[
0b00011100,
0b00111110,
0b00110011,
0b00011011,
0b00011011,
0b00001111,
0b00000111,
0b00001100
],]
#=======Initialize========#
# Initialize the first LED matrix
num_matrices1 = 4
display1 = max7219.Matrix8x8(spi1, ss1, num_matrices1)
display1.brightness(1)
display1.fill(0)
# Initialize the second LED matrix
num_matrices2 = 4
display2 = max7219.Matrix8x8(spi2, ss2, num_matrices2)
display2.brightness(1)
display2.fill(0)
# Initialize the third LED matrix
num_matrices3 = 4
display3 = max7219.Matrix8x8(spi3, ss3, num_matrices3)
display3.brightness(1)
display3.fill(0)
# Initialize the forth LED matrix
num_matrices4 = 4
display4 = max7219.Matrix8x8(spi4, ss4, num_matrices4)
display4.brightness(1)
display4.fill(0)
# Function to show symbols display
def show_symbols(display, symbols):
for matrix_index in range(len(symbols)):
for i in range(8):
for j in range(8):
display.pixel(i + matrix_index * 8, j, symbols[matrix_index][i] & (1 << (7 - j)))
display.show()
#=======BUTTONS========#
# Connect button 1 to GPIO pin 28
button_pin = Pin(28, Pin.IN, Pin.PULL_UP)
# Connect button 2 to GPIO pin 27
button_pin_2 = Pin(27, Pin.IN, Pin.PULL_UP)
# Connect button 3 to GPIO pin 26
button_pin_3 = Pin(26, Pin.IN, Pin.PULL_UP)
# Connect button 4 to GPIO pin 22
button_pin_4 = Pin(22, Pin.IN, Pin.PULL_UP)
# Display1 = Eye right
# Display2 = Eyes left
# Display3 = mouth right
# Display4 = mouth left
# display5 = NA * to be nose
current_time = 0
while True:
# First button
if button_pin.value() == 0:
# Show swull on Eye right
show_symbols(display1, swullR1)
show_symbols(display2, swullL1)
time.sleep(.1)
show_symbols(display1, swullR2)
show_symbols(display2, swullL2)
time.sleep(.1)
show_symbols(display1, swullR3)
show_symbols(display2, swullL3)
time.sleep(.1)
show_symbols(display1, swullR4)
show_symbols(display2, swullL4)
time.sleep(.1)
show_symbols(display1, swullR1)
show_symbols(display2, swullL1)
time.sleep(.1)
show_symbols(display1, swullR2)
show_symbols(display2, swullL2)
time.sleep(.1)
show_symbols(display1, swullR3)
show_symbols(display2, swullL3)
time.sleep(.1)
show_symbols(display1, swullR4)
show_symbols(display2, swullL4)
time.sleep(.1)
# Second button
elif button_pin_2.value() == 0:
# Show Heart for Eye right
show_symbols(display1,heartR1)
show_symbols(display2, heartL1)
time.sleep(.1)
show_symbols(display1, heartR2)
show_symbols(display2, heartL2)
# Third button
elif button_pin_3.value() == 0:
# Show talk on Mouth Left & right
show_symbols(display3, talkL)
show_symbols(display4, talkR)
# Forth button
elif button_pin_4.value() == 0:
# Show mad on eyes & mouth on both left & right
show_symbols(display1, madeyeR)
show_symbols(display2, madeyeL)
show_symbols(display3, madmouthR)
show_symbols(display4, madmouthL)
#blink
elif current_time == 12:
show_symbols(display1, blinkR)
show_symbols(display2, blinkL)
time.sleep(.25)
current_time = 0
# Default
else:
# Show default symbols
show_symbols(display1, eyeR)
show_symbols(display2, eyeL)
show_symbols(display3, mouth1R)
show_symbols(display4, mouth1L)
current_time += 1
time.sleep(1)