def timedraw(): disp = SH1106.SH1106() disp.Init() disp.clear() while 42: times = q.get() try: image1 = Image.new('1', (disp.width, disp.height), "WHITE") draw = ImageDraw.Draw(image1) font = ImageFont.truetype('Font.ttf', 16) top=0 for name in times: draw.text((0,top), name, font = font, fill = 0) sec=times[name]; tstring='{:02}:{:02}:{:02}'.format(sec // 3600, sec % 3600 // 60, sec % 60) draw.text((50,top), tstring, font = font, fill = 0) top+=20 disp.ShowImage(disp.getbuffer(image1)) except IOError as e: print(e)
def __init__(self): self._disp = SH1106.SH1106() self._disp.Init() # Clear display. self._disp.clear() # init GPIO # for P4: # sudo vi /boot/config.txt # gpio=6,19,5,26,13,21,20,16=pu GPIO.setmode(GPIO.BCM) GPIO.setup(KEY_UP_PIN, GPIO.IN, pull_up_down=GPIO.PUD_UP) # Input with pull-up GPIO.setup(KEY_DOWN_PIN, GPIO.IN, pull_up_down=GPIO.PUD_UP) # Input with pull-up GPIO.setup(KEY_LEFT_PIN, GPIO.IN, pull_up_down=GPIO.PUD_UP) # Input with pull-up GPIO.setup(KEY_RIGHT_PIN, GPIO.IN, pull_up_down=GPIO.PUD_UP) # Input with pull-up GPIO.setup(KEY_PRESS_PIN, GPIO.IN, pull_up_down=GPIO.PUD_UP) # Input with pull-up GPIO.setup(KEY1_PIN, GPIO.IN, pull_up_down=GPIO.PUD_UP) # Input with pull-up GPIO.setup(KEY2_PIN, GPIO.IN, pull_up_down=GPIO.PUD_UP) # Input with pull-up GPIO.setup(KEY3_PIN, GPIO.IN, pull_up_down=GPIO.PUD_UP) # Input with pull-up self._button_pressing = [False for i in range(ButtonType.BUTTON_COUNT)]
def scroll_text(text,direction='up'): paged_text = SH1106.get_paged_text(text,spacing=4,offset=2) if direction=='up' or direction=='down': up = direction=='up' disp.scroll_page(up=up) disp.scroll_pages(paged_text,up=up) disp.scroll_page(up=up) disp.scroll_page(up=up) elif direction=='left' or direction=='right': left = direction=='left' disp.swipe_pages(2,paged_text,left=left,rate=0)
def init(self): if self._is_debug: self._disp = type('Expando', (object, ), {})() self._disp.getbuffer = self.debug_getbuffer self._disp.ShowImage = self.debug_ShowImage self._disp.width = 128 self._disp.height = 64 else: import SH1106 self._disp = SH1106.SH1106() self._disp.Init() self._disp.clear()
def sleep(): print inspect.stack()[0][3] for f in range(256): disp.set_brightness(255-f) time.sleep(0.01) disp.power_down() while get_input()!='double_click': pass disp.power_up() disp.clear_screen() disp.set_brightness(0) pages = SH1106.get_paged_text(' Hello!',spacing=4,offset=2) disp.send_pages(pages,page=2,column=2) for f in range(256): disp.set_brightness(f) time.sleep(0.01)
def main(): disp = SH1106.SH1106() # Initialize library. disp.Init() # Clear display. disp.clear() font = ImageFont.truetype("OpenSans-Regular.ttf", 20) font_small = ImageFont.truetype("OpenSans-Regular.ttf", 16) font_tiny = ImageFont.truetype("OpenSans-Regular.ttf", 12) font_super_tiny = ImageFont.truetype("OpenSans-Regular.ttf", 10) while True: price, diff, ohlc = fetch_crypto_data( "dogeusdt" ) # TODO: use any binance symbol you want (Ex.: DOGE = dogeusdt) # Clear Screen image1 = Image.new('1', (disp.width, disp.height), "WHITE") draw = ImageDraw.Draw(image1) # Title draw.rectangle((0, 0, 127, 17), outline=255, fill=0) # Background rectangle draw.text((35, 0), 'DOGECOIN ', font=font_tiny, fill=1) # Actual Price draw.text((30, 20), text="{} $".format(price_to_str(price)), font=font, fill=0) # Set price diff symbol diff_symbol = "" if diff > 0: diff_symbol = "+" if diff < 0: diff_symbol = "-" # Draw diff price draw.text((35, 40), text="{}{}$".format(diff_symbol, price_to_str(diff)), font=font_small, fill=0) disp.ShowImage(disp.getbuffer(image1)) time.sleep(5)
def __init__(self, scl=18, sda=23, leveys=16, rivit=6, lpikselit=128, kpikselit=64): self.rivit = [] self.nayttotekstit = [] self.aika = 5 # oletusnäyttöaika self.rivi = 1 """ Muodostetaan näytönohjaukseen tarvittavat objektit """ self.i2c = I2C(1, scl=Pin(scl), sda=Pin(sda), freq=400000) # naytto-objektin luonti self.nayttoleveys = leveys # merkkiä self.nayttorivit = rivit # riviä self.pikselit_leveys = lpikselit # pikseliä self.pikselit_korkeus = kpikselit self.naytto = oled.SH1106_I2C(self.pikselit_leveys, self.pikselit_korkeus, self.i2c) self.naytto.poweron() self.naytto.init_display() self.kaanteinen = False
#!/usr/bin/python # -*- coding:utf-8 -*- import SH1106 import time import config import traceback from PIL import Image, ImageDraw, ImageFont try: disp = SH1106.SH1106() print("\r\1.3inch OLED") # Initialize library. disp.Init() # Clear display. disp.clear() # Create blank image for drawing. image1 = Image.new('1', (disp.width, disp.height), "WHITE") draw = ImageDraw.Draw(image1) font = ImageFont.truetype('Font.ttf', 20) font10 = ImageFont.truetype('Font.ttf', 13) print("***draw line") draw.line([(0, 0), (127, 0)], fill=0) draw.line([(0, 0), (0, 63)], fill=0) draw.line([(0, 63), (127, 63)], fill=0) draw.line([(127, 0), (127, 63)], fill=0) print("***draw rectangle")
index = 0 disp.clear_screen() scroll_text(menu[0][0]) else: #successful function call, go back to root... return True else: #we've bailed out - show ourselves again scroll_text(menu[index][0],direction='right') elif option=='flip_left': if not first_time: return False #initialise various components prog = bootloader.Programmer() disp = SH1106.Display(prog) disp.power_up() disp.invert() time.sleep(5) disp.invert() disp.scroll_rate = 0 disp.clear_screen() mpu = motion.mpu9250(prog) mpu.configure() try: #sleep() show_menu(menu_items,True) print "finished" except KeyboardInterrupt: disp.power_down()
def write_text(disp,text,page,column): paged_text = SH1106.get_paged_text(text,spacing=4,offset=2) disp.send_pages(paged_text,page,column)
scroll_text(menu[0][0]) else: #successful function call, go back to root... return True else: #we've bailed out - show ourselves again scroll_text(menu[index][0],direction='right') elif option=='flip_left': if not first_time: return False #initialise various components gpio.setmode(gpio.BCM) gpio.setup(23,gpio.IN) gpio.setup(24,gpio.OUT,initial = gpio.HIGH) gpio.add_event_detect(23,gpio.RISING) disp = SH1106.Display() disp.power_up() disp.scroll_rate = 0 disp.clear_screen() mpu = motion.mpu9250() mpu.configure() try: sleep() show_menu(menu_items,True) print "finished" except KeyboardInterrupt: disp.power_down() gpio.cleanup()