from machine import Pin, SoftI2C
from ssd1306 import SSD1306_I2C
from eyes import *
import framebuf
import time
import math
from writer import Writer
#import roboto16
import symbols
i2c = SoftI2C(scl=Pin(22), sda=Pin(21))
oled_width = 128
oled_height = 64
lcd = SSD1306_I2C(oled_width, oled_height, i2c)
lcd.fill(1)
lcd.show()
time.sleep_ms(300)
# RoboEyes callback event
def robo_show(roboeyes):
global lcd
lcd.show()
# Plug RoboEyes on any FrameBuffer descendant
robo = RoboEyes(lcd, oled_width, oled_height, frame_rate=100, on_show=robo_show)
# Define some automated eyes behaviour
robo.set_auto_blinker(ON, 3, 2) # Start auto blinker animation cycle -> bool active, int interval, int variation -> turn on/off, set interval between each blink in full seconds, set range for random interval variation in full seconds
robo.set_idle_mode(ON, 2, 2) # Start idle animation cycle (eyes looking in random directions) -> turn on/off, set interval between each eye repositioning in full seconds, set range for random time interval variation in full seconds
# --[ Define eye shapes, all values in pixels ]--
#robo.eyes_width(28, 28) # byte leftEye, byte rightEye
#robo.eyes_height(45, 45) # byte leftEye, byte rightEye
#robo.eyes_radius(8, 8) # byte leftEye, byte rightEye
#robo.eyes_radius(18, 18) # byte leftEye, byte rightEye (looking round when height=width=36)
#robo.eyes_spacing(10) # int space between eyes-> can also be negative
# --[ Cyclops mode ]--
# robo.cyclops = True # if turned on, robot has only on eye
# --[ Initial setup animation ]--
# Give a second to the eyes to open in their default state
start = time.ticks_ms()
while time.ticks_diff(time.ticks_ms(), start) < 1000:
robo.update()
# --[ Open/Close Eyes ]--
# Auto blinker must be disable to properly run this
#robo.close() # Close Eyes
#robo.open() # Open Eyes
# --[ Define mood, curiosity and position ]--
#robo.mood = DEFAULT # mood expressions, can be TIRED, ANGRY, HAPPY, FROZEN, AFRAID, CURIOUS, DEFAULT
#robo.position = DEFAULT # cardinal directions, can be N, NE, E, SE, S, SW, W, NW, DEFAULT (default = horizontally and vertically centered)
#robo.curious = True # bool on/off -> when turned on, height of the outer eyes increases when moving to the very left or very right
# --[ Set horizontal or vertical flickering ]--
#robo.horiz_flicker(True, 2) # bool on/off, byte amplitude -> horizontal flicker: alternately displacing the eyes in the defined amplitude in pixels
#robo.vert_flicker(True, 2) # bool on/off, byte amplitude -> vertical flicker: alternately displacing the eyes in the defined amplitude in pixels
# --[ Play prebuilt oneshot animations ]--
#robo.confuse() # confused - eyes shaking left and right
#robo.laugh() # laughing - eyes shaking up and down
#robo.wink( right=True ) # make the right Eye Winking
wri = Writer(lcd, symbols) # verbose = False to suppress console output
while True:
Writer.set_textpos(lcd, 0, 0) # In case a previous test has altered this
# update eyes drawings
wri.printstring('Sunday\n12 Aug 2018\n10.30am')
#robo.update()
lcd.show()
# Dont' use sleep() or sleep_ms() here in order to ensure fluid eyes animations.
# Check the AnimationSequences example for common practices.