def render(self): # 绘制图像 self.clear() lcd.setColor(self.color) lcd.fillCircle(self.x, self.y, self.r) self.old_x = self.x self.old_y = self.y
def render(self): if self.active: self.obs.render() else: lcd.setColor(0xffffff) lcd.text(20, 40, "Press") lcd.text(31, 55, "M5") lcd.text(22, 70, "Start") lcd.text(20, 85, "Game")
def show(self): ScreenManager.isShown(self) self._isShown = True lcd.clear(lcd.WHITE) lcd.setColor(lcd.BLACK) lcd.font(lcd.FONT_Tooney, transparent=True) lcd.print('speckbosch', lcd.CENTER, 10) lcd.font(lcd.FONT_DejaVu24, transparent=True) lcd.print('Chicken Shed Mgr {}'.format(self._getVersion()), lcd.CENTER, 45)
def main(): start_wifi() print('started wifi and tools') # move to lowest line on M5STACK display lcd.setCursor(0, 227) lcd.setColor(lcd.WHITE) lcd.print("RTC Clock 1") # initiate rtc print("Synchronize time from NTP server with TZ=US Central ...") rtc.ntp_sync(server="hr.pool.ntp.org", tz="CST6CDT5,M4.1.0/2,M10.5.0/2") #https://prom-electric.ru/media/uclibc-zoneinfo-list.txt _thread.start_new_thread ("clock",watch, ())
def render(self): # 清空上一帧内容 lcd.setColor(0) for ob in self.obs[self.type]: lcd.fillRect(self.old_x + ob[0], self.y + ob[1], ob[2], ob[3]) # lcd.drawRect(self.collision[self.type][0]+ self.old_x, self.collision[self.type][1] + self.y, self.collision[self.type][2], self.collision[self.type][3]) if not self.off_screen(): # 绘制当前帧内容 lcd.setColor(0x00ff00) for ob in self.obs[self.type]: lcd.fillRect(self.x + ob[0], self.y + ob[1], ob[2], ob[3])
def __init__(self): self.score = 0 lcd.setColor(0xffffff) self.components = [] self.dino = Dino(self, 10, 120) self.obs_generator = ObstacleGenerator(self, 1) self.cloud = Cloud(80, 20, 0) self.components.append(self.dino) self.components.append(self.cloud) self.components.append(self.obs_generator) lcd.font(lcd.FONT_Default) self.create_init_ui()
def watch(): while True: # start position for Date if not rtc.synced(): # set color to sync status lcd.setColor(lcd.RED) else: lcd.setColor(lcd.GREEN) # lcd.setCursor(92, 227) # uncomment if you need date on display # lcd.print("Date {}".format(utime.strftime("%Y-%m-%d", utime.localtime()))) # uncomment if needed # start position for time only lcd.setCursor(213, 227) # uncomment if date active (see upper lines) lcd.print(" Time {}".format(utime.strftime('%H:%M:%S', utime.localtime()))) utime.sleep(1)
def main(): from m5stack import lcd, buttonA from mpu9250 import MPU9250 from time import sleep_ms from machine import I2C import network # lcd.font(lcd.FONT_Small, transparent=True, fixedwidth=False) try: sta_if = network.WLAN(network.STA_IF) if sta_if.active() == True: m_acc = network.mqtt('acc', 'mqtt://srdmobilex.ddns.net', port=65530, clientid='a') m_gyro = network.mqtt('gyro', 'mqtt://srdmobilex.ddns.net', port=65530, clientid='g') m_acc.start() m_gyro.start() m_acc.subscribe('acc', 2) m_gyro.subscribe('gyro', 0) i2c = I2C(sda = 21, scl = 22) imu = MPU9250(i2c) lcd.clear() lcd.setColor(lcd.WHITE) lcd.font(lcd.FONT_Small, transparent=False) counter = 0 while not buttonA.isPressed(): accel = imu.acceleration gyro = imu.gyro mag = imu.magnetic lcd.print("ACCEL: {:+7.2f} {:+7.2f} {:+7.2f}".format(accel[0], accel[1], accel[2]), lcd.CENTER, 20) lcd.print("GYRO: {:+7.2f} {:+7.2f} {:+7.2f}".format(gyro[0], gyro[1], gyro[2]), lcd.CENTER, 40) lcd.print("MAG: {:+7.2f} {:+7.2f} {:+7.2f}".format(mag[0], mag[1], mag[2]), lcd.CENTER, 60) if sta_if.active() == True: m_acc.publish('acc', '{:+7.2f},{:+7.2f},{:+7.2f}'.format(accel[0], accel[1], accel[2]) + '(%d)'%counter) m_gyro.publish('gyro', '{:+7.2f} {:+7.2f} {:+7.2f}'.format(gyro[0], gyro[1], gyro[2]) + '(%d)'%counter) counter += 1 sleep_ms(20) m_acc.free() m_gyro.free() i2c.deinit() lcd.print('Exit.', 0, 100) except: return -1
def render(self): lcd.setColor(0) for rect in self.roundRect[self.type]: lcd.fillRoundRect(self.old_x + rect[0], self.y + rect[1], rect[2], rect[3], rect[4]) lcd.setColor(0x999999) if not self.off_screen(): for rect in self.roundRect[self.type]: lcd.fillRoundRect(self.x + rect[0], self.y + rect[1], rect[2], rect[3], rect[4]) else: # 重新生成一片云 self.type = randint(0, 2) self.x = randint(80, 100) self.y = randint(30, 60) self.vx = randint(1, 3)
def clock(): rtc = machine.RTC() print("Synchronize time from NTP server ...") lcd.println("Synchronize time from NTP server ...") rtc.ntp_sync( server="ru.pool.ntp.org", tz="CET-3CEST,M3.5.0,M10.5.0/3") # Часовой пояс меняется в CET-3CEST lcd.clear(lcd.BLUE) lcd.setColor(lcd.BLACK, lcd.BLUE) lcd.font(lcd.FONT_Comic, fixedwidth=True, dist=16, width=2) while True: d = time.strftime("%d-%m-%Y", time.localtime()) t = time.strftime("%H:%M:%S", time.localtime()) lcd.print(d, lcd.CENTER, 50) lcd.print(t, lcd.CENTER, 130) time.sleep(0.02) if buttonA.isPressed(): break if buttonС.isPressed(): break
def loadImage(): global ix, START_IX, LOAD_LIMIT, isTryingLoad isTryingLoad = True if ix < 0: ix = len(screens) - 1 if ix > len(screens) - 1 : START_IX += LOAD_LIMIT appendScreensIds() lcd.clear() lcd.setCursor(0, 0) lcd.setColor(lcd.WHITE) lcd.print('Top of ZXART.EE: #%s %s' % (ix + 1, screens[ix][1])) data = open(TEMP_FILE, 'wb') addr = ZX_ART_HOST % screens[ix][0] http_getFile(addr, data) loadedData = open(TEMP_FILE, 'rb').read() convertToScreen(loadedData) lcd.print(" << A Reload - B C >>", 0, 224)
def main(): from m5stack import lcd, buttonA from alib.mpu6050 import MPU6050 from time import sleep_ms from machine import I2C # lcd.font(lcd.FONT_Small, transparent=True, fixedwidth=False) i2c = I2C(sda = 21, scl = 22, speed=400000) try: # lcd.println('I2C port has been used.') imu = MPU6050(i2c) lcd.clear() lcd.setColor(lcd.WHITE) lcd.font(lcd.FONT_Small, transparent=False) while not buttonA.isPressed(): accel = imu.acceleration gyro = imu.gyro # mag = imu.magnetic # print("ACCEL: {:8.3f} {:8.3f} {:8.3f}".format(accel[0], accel[1], accel[2])) # print("GYRO: {:8.3f} {:8.3f} {:8.3f}".format(gyro[0], gyro[1], gyro[2])) # print("MAG: {:8.3f} {:8.3f} {:8.3f}".format(mag[0], mag[1], mag[2])) # print('') lcd.print("ACCEL: {:+7.2f} {:+7.2f} {:+7.2f}".format(accel[0], accel[1], accel[2]), lcd.CENTER, 20) lcd.print("GYRO: {:+7.2f} {:+7.2f} {:+7.2f}".format(gyro[0], gyro[1], gyro[2]), lcd.CENTER, 40) # lcd.print("MAG: {:+7.2f} {:+7.2f} {:+7.2f}".format(mag[0], mag[1], mag[2]), lcd.CENTER, 60) sleep_ms(10) lcd.print('Exit.', 0, 100) except: print('ERR') i2c.deinit()
def task(expires_date): global g_track_id global g_track_img global g_showing_spotify_logo try: now = utime.time() if now > expires_date: next_expire_delta = refresh_token_if_necessary() expires_date = now + next_expire_delta track = get_current_playing_track() if track is not None: track_item = track['item'] if track_item['id'] != g_track_id: image_url = get_image_url(track_item) lcd.clear() lcd.setCursor(0, 0) lcd.setColor(lcd.WHITE) if image_url and image_url != g_track_img: download_image_to_file(image_url, 'tmp.jpg') show_image('tmp.jpg') print_title(track_item) print_artist(track_item) g_track_id = track_item['id'] g_track_img = image_url g_showing_spotify_logo = False else: if g_showing_spotify_logo is False: lcd.clear() show_image('spotify.jpg') g_showing_spotify_logo = True return expires_date except Exception as e: lcd.print('Exception(task): ' + str(e)) import sys sys.print_exception(e) raise e
def draw(self,index): a,b=divmod(len(self.applist),self.lines) A,B=divmod(index,self.lines) if A == a: frontlist=self.applist[A*self.lines:] else: frontlist=self.applist[A*self.lines:(A+1)*self.lines] if self.previous_index is None: self.clear() lcd.font(self.font, fixedwidth=0) for i in range(len(frontlist)): print(i,frontlist[i],end=" ") if i == B: lcd.setColor(self.color_2[0],self.color_2[1]) lcd.rect(self.x,self.y+B*self.fontheight,self.length,self.fontheight,self.color_2[1],self.color_2[1]) if frontlist[i][0]=="/sd": lcd.text(self.x,self.y+i*self.fontheight,"SD-"+frontlist[i][1][:-4]) else: lcd.text(self.x, self.y + i * self.fontheight, "FLASH-" + frontlist[i][1][:-7]) else: lcd.setColor(self.color_1[0], self.color_1[1]) lcd.rect(self.x, self.y + i * self.fontheight, self.length,self.fontheight,self.color_1[1], self.color_1[1]) if frontlist[i][0]=="/sd": lcd.text(self.x,self.y+i*self.fontheight,"SD-"+frontlist[i][1][:-4]) else: lcd.text(self.x, self.y + i * self.fontheight, "FLASH-" + frontlist[i][1][:-7]) self.previous_index=index else: if A != divmod(self.previous_index, self.lines)[0]: self.previous_index = None self.draw(index) else: pb = divmod(self.previous_index, self.lines)[1] lcd.setColor(self.color_1[0], self.color_1[1]) lcd.rect(self.x, self.y + pb * self.fontheight,self.length,self.fontheight,self.color_1[1], self.color_1[1]) if frontlist[pb][0] == "/sd": lcd.text(self.x, self.y + pb * self.fontheight, "SD-" + frontlist[pb][1][:-4]) else: lcd.text(self.x, self.y + pb * self.fontheight, "FLASH-" + frontlist[pb][1][:-7]) lcd.setColor(self.color_2[0], self.color_2[1]) lcd.rect(self.x, self.y + B * self.fontheight, self.length,self.fontheight,self.color_2[1], self.color_2[1]) if frontlist[B][0] == "/sd": lcd.text(self.x, self.y + B * self.fontheight, "SD-" + frontlist[B][1][:-4]) else: lcd.text(self.x, self.y + B * self.fontheight, "FLASH-" + frontlist[B][1][:-7]) self.previous_index=index
def render(self): lcd.setColor(0) if self.act == 2 or self.act == 3 or self.act == 4: # 跳跃状态才需要清空之前一帧绘制的内容 # 清空上一帧绘制的内容 for line in self.head_lines: lcd.drawLine(self.old_x + line[0], self.old_y + line[1], self.old_x + line[2], self.old_y + line[3]) for rect in self.body_rects: lcd.fillRect(self.old_x + rect[0], self.old_y + rect[1], rect[2], rect[3]) for pixel in self.extra_pixels: lcd.drawPixel(self.old_x + pixel[0], self.old_y + pixel[1]) # 清空运动中上一帧眨眼的坐标 lcd.drawPixel(self.old_x + 12, self.old_y + 1) # self.act == 4这是从跳跃状态转移至普通状态的中间状态, # 此时仍然需要清空上一帧内容,不然会导致状态错误而留下残影 if self.act == 4: # 清空完上一帧内容,再去转变状态 self.act = 1 self.leg_status = 0 self.clear_leg() # 绘制本一帧的内容 lcd.setColor(0xffffff) for line in self.head_lines: lcd.drawLine(self.x + line[0], self.y + line[1], self.x + line[2], self.y + line[3]) for rect in self.body_rects: lcd.fillRect(self.x + rect[0], self.y + rect[1], rect[2], rect[3]) for pixel in self.extra_pixels: lcd.drawPixel(self.x + pixel[0], self.y + pixel[1]) # 由于不断更新的,所以脚单独绘制 self.draw_leg() if self.blink < 40: lcd.setColor(0) lcd.drawPixel(self.x + 12, self.y + 1) elif self.blink < 60: # 闭眼效果在此 lcd.setColor(0xffffff) lcd.drawPixel(self.x + 12, self.y + 1) else: self.blink = 0 self.blink += 1
filetemp = uos.listdir('/flash') for i in filetemp: if ".app.py" == i.lower()[-7:]: applist.append(['/flash', i]) lcd.println('OK!') except: lcd.println("SD mount fail!") lcd.println("read file in flash!") filetemp = uos.listdir('/flash') for i in filetemp: if ".app.py" == i.lower()[-7:]: applist.append(['/flash', i]) lcd.println('OK!') lcd.setColor(lcd.RED,lcd.BLACK) for i in applist: if i[0] == "/sd": lcd.print(i[0]+" ") else: lcd.print(i[0] + " ") lcd.println(i[1]) class List: def __init__(self,applist): # 第一次显示应该显示widget的当前索引 self.x = 10
def render(self): lcd.setColor(0xffffff) lcd.text(0, 145, str(self.score)) for com in self.components: com.render()
def main(): ########## 初期化 ########## # 液晶画面を初期化する lcd.setColor(color, background_color) lcd.clear() # センサーを初期化する sensor = DHT12() # 温度計、湿度計の表示を初期化する temperature_view = ThermometerView(10, 10, min_value=-15, max_value=45) humidity_view = ThermometerView(80, 10, min_value=0, max_value=100, color=lcd.BLUE, label='%') # SDカードのマウント uos.mountsd() # 背景の描画 temperature_view.init() humidity_view.init() ########## 無限ループ ########## while not buttonC.isPressed(): # センサーで温度と湿度を計測する sensor.measure() temperature = sensor.temperature() humidity = sensor.humidity() # デバッグ用 print("Temperature: {} `C, Humidity: {} %".format( temperature, humidity)) # 温度計、湿度計の表示を更新する temperature_view.update(temperature) humidity_view.update(humidity) # WBGT値を求める try: wbgt = calc_wbgt(temperature, humidity) except ValueError: wbgt = None # WBGT値を画面に表示する lcd.font(lcd.FONT_Default, color=color, transparent=False) lcd.textClear(160, 30, 'WBGT: Unknown') if wbgt is not None: lcd.text(160, 30, 'WBGT: {}'.format(wbgt)) else: lcd.text(160, 30, 'WBGT: Unknown') image_path = None # WBGT値に応じて画像を描画する # 31度以上 : 危険 # 28度以上31度未満 : 厳重警戒 # 25度以上28度未満 : 警戒 # 25度未満 : 注意 if temperature >= 21 and wbgt is not None: if wbgt >= 31: # 危険 image_path = image_path_kiken elif wbgt >= 28: # 厳重警戒 image_path = image_path_genjukeikai elif wbgt >= 25: # 警戒 image_path = image_path_keikai # 湿度に応じてインフルエンザ注意情報を表示する # 湿度40%未満 : インフルエンザ感染注意 if humidity < 40: image_path = image_path_influenza if image_path is not None: # 画像を描画する lcd.image(image_x, image_y, image_path) else: # 画像を描画した領域を背景色で塗りつぶす lcd.rect(image_x, image_y, image_width, image_height, background_color, background_color) # 表示の更新間隔 utime.sleep(interval)
lcd.init(lcd.M5STACK, width=320, height=240, mosi=23, miso=12, clk=18, cs=27, dc=26, rst_pin=5, invrot=0, bgr=True) lcd.orient(3) sta_if = network.WLAN(network.STA_IF) sta_if.active(True) sta_if.scan() # Scan for available access points sta_if.connect("login", "password") # Connect to an AP sta_if.isconnected() # Check for successful connection #rez = str(sta_if.ifconfig()) if not sta_if.isconnected(): sta_if.connect() print("Waiting for connection...") while not sta_if.isconnected(): utime.sleep(1) lcd.setCursor(0, 40) lcd.setColor() lcd.println(str(sta_if.ifconfig()))
def create_dead_ui(self): lcd.setColor(0xff0000) lcd.text(19, 30, "Dead!")
# UI.Flow 1.2 以前はタイムスタンプの出力に以下のように time.strftime を使用していたが #print(time.strftime('%Y-%m-%d %H:%M:%S', time.localtime()), ' Script Name: ', __name__) # UI.Flow 1.3 以降は time.strftime が使えないため以下で対応 print('{}-{:02d}-{:02d} {:02d}:{:02d}:{:02d}'.format(*time.localtime()[:6]), ' Script Name: ', __name__) am = ambient.Ambient(AMBIENT_CHANNEL_ID, AMBIENT_WRITE_KEY) i2c = i2c_bus.get(i2c_bus.M_BUS) dht12 = DHT12(i2c) bmp280 = BMP280(i2c) mhz19 = machine.UART(2, tx=17, rx=16) mhz19.init(9600, bits=8, parity=None, stop=1) lcd.setColor(lcd.BLACK, lcd.WHITE) lcd.setTextColor(lcd.BLACK, lcd.WHITE) lcd.clear(lcd.BLACK) win_w, win_h = lcd.winsize() # (320, 240) meter_mode = 0 while True: lcd.clear(lcd.BLACK) if meter_mode == 0: # 画面を4分割して、気温計、湿度計、気圧計、CO2濃度計を表示 # 表示フォーマットは、表示桁数が減った時に(気圧が1000から999になった時等) # 前の表示を消すために前後に空白を入れている t_meter = Meter(0, 0, win_w // 2, win_h // 2, 0, 40, lcd.ORANGE, 'Temp', ' {:.1f}C ')
def styleInit(): lcd.setColor(lcd.WHITE) lcd.font(lcd.FONT_Ubuntu, transparent=True, fixedwidth=False)
from m5stack import lcd from machine import I2C, Pin from motor import Motor from time import sleep_ms lcd.clear() lcd.setCursor(0, 0) lcd.setColor(lcd.WHITE) lcd.print("Hello World!") i2c = I2C(scl=Pin(22), sda=Pin(21)) m = Motor(i2c=i2c, address=0x0F) while True: m.setMotorSpeed(100, 100) m.setDirection(0b0000) sleep_ms(1000) m.setDirection(0b0101) sleep_ms(1000) m.setDirection(0b1010) sleep_ms(1000) m.setDirection(0b1111) sleep_ms(1000)
def clear(self): # 清空上一帧内容 lcd.setColor(lcd.BLACK) lcd.fillCircle(self.old_x, self.old_y, self.r)
def clear_leg(self): lcd.setColor(0) lcd.fillRect(self.old_x + 5, self.old_y + 16, 10, 4)
def but_b(): lcd.clear(lcd.ORANGE) lcd.setCursor(100, 100) lcd.setColor(lcd.BLACK, lcd.ORANGE) lcd.print('World') return ()
from m5stack import lcd, speaker from machine import I2C import time i2c = I2C(freq=400000, sda=21, scl=22) while True: temp_byte = i2c.readfrom(72, 2) # アドレス72番から2byte読み込み temp = int.from_bytes(temp_byte, "big") / 128 # 温度換算 print(temp) if temp > 30: lcd.clear(lcd.RED) lcd.setColor(lcd.WHITE, lcd.RED) lcd.text(lcd.CENTER, lcd.CENTER, str(temp)) speaker.volume(1) speaker.tone(freq=1000, duration=200) # 30℃以上で else: lcd.clear(lcd.BLUE) lcd.setColor(lcd.WHITE, lcd.BLUE) lcd.text(lcd.CENTER, lcd.CENTER, str(temp)) time.sleep(5)
import _thread, network, ujson, ubinascii, machine from m5stack import lcd import utime as time wlan_sta = network.WLAN(network.STA_IF) wlan_sta.active(True) lcd.setColor(0xCCCCCC, 0) # # Define the WiFi events callback function # def wifi_cb(info): # print("[WiFi] event: {} ({})".format(info[0], info[1])) # if (info[2]): # print(" info: {}".format(info[2])) def do_connect(ntwrk_ssid, netwrk_pass): if not wlan_sta.isconnected(): print('Connect WiFi: SSID:' + ntwrk_ssid + ' PASSWD:' + netwrk_pass + ' network...') lcd.println('Connect WiFi: \r\nWiFi SSID:' + ntwrk_ssid) # lcd.println('Connect WiFi: \r\nWiFi SSID:'+ntwrk_ssid+' \t\nPASSWD:'+netwrk_pass) # wlan_sta.eventCB(wifi_cb) wlan_sta.connect(ntwrk_ssid, netwrk_pass) lcd.print('Connecting.') a = 0 while not wlan_sta.isconnected() | (a > 50): time.sleep_ms(500) a += 1 print('.', end='') lcd.print('.', wrap=1) if wlan_sta.isconnected():
# ライブラリ導入 from m5stack import lcd # 初期化 lcd.clear() # フォント指定 lcd.font(lcd.FONT_Dejavu24) # フォント FONT_Dejavu24 に設定 # 画像挿入 lcd.image(lcd.CENTER, lcd.BOTTOM, file="/flash/icon.jpg") # 見出し lcd.setCursor(0, 0) lcd.setColor(lcd.WHITE, lcd.BLUE) fw, fh = lcd.fontSize() ww, wh = lcd.winsize() lcd.rect(0, 0, ww, fh + 1, lcd.BLUE, lcd.BLUE) lcd.println("N High School students Card") # 文字 lcd.setColor(lcd.WHITE, lcd.BLACK) lcd.print('Waricoma', 10, 30)
def but_a(): lcd.clear(lcd.GREEN) lcd.setCursor(100, 100) lcd.setColor(lcd.BLACK, lcd.GREEN) lcd.print('Hello')