Skip to content

Instantly share code, notes, and snippets.

@zuku
Last active February 23, 2023 02:11
Show Gist options
  • Save zuku/3b30ee79f578162d22f828d9ca2f738f to your computer and use it in GitHub Desktop.
Save zuku/3b30ee79f578162d22f828d9ca2f738f to your computer and use it in GitHub Desktop.
M5StickC Plusで画面のちらつきを抑止する方法のMicroPython版サンプルコード
from m5stack import lcd
import utime
import wifiCfg
import ntptime
'''
M5StickC Plusで画面のちらつき(フリッカー)を抑止する方法のサンプルコード
MicroPython版
(Arduinoの場合はTFT_eSpriteを使うと良いらしい)
動作環境
UIFlow_StickC_Plus v1.11.1
sys.version = '3.4.0'
sys.implementation.version = (1, 12, 0)
以下の処理を行うと sprite の表示位置/サイズがおかしくなる
* lcd.setRotation() を使用
* lcd.orient() を使用
* lcd.sprite_delete() してから lcd.sprite_create() する (spriteの再生成)
そのため縦表示の状態で表示要素を回転して表示している
'''
lcd.clear()
wifiCfg.autoConnect(lcdShow=True)
ntptime.client(host='pool.ntp.org', timezone=9)
screen_w, screen_h = lcd.screensize()
lcd.sprite_create(screen_w, screen_h, lcd.SPRITE_8BIT)
lcd.font(lcd.FONT_DejaVu24, fixedwidth=True, color=lcd.WHITE, rotate=270)
font_w, font_h = lcd.fontSize()
text_w = lcd.textWidth('00:00:00')
position_x = int(screen_w / 2 - font_w / 2)
position_y = min(int(screen_h / 2 + text_w / 2), screen_h - font_h)
while True:
lcd.sprite_select()
lcd.fillRect(0, 0, screen_w, screen_h, lcd.BLACK)
_, _, _, hour, minute, second, *_ = utime.localtime()
lcd.text(position_x, position_y, '{:02d}:{:02d}:{:02d}'.format(hour, minute, second))
lcd.sprite_deselect()
lcd.sprite_show(0, 0)
utime.sleep(0.5)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment