def temp(): adc = machine.ADC(PIN) # ADコンバータのインスタンスを生成 lcd.font(font) # フォントを指定 lcd.clear() # 画面をクリア while True: t = 0 for i in range(MULTISAMPLES): t = t + adc.read() / 10 # ADコンバータを読み、温度に変換 t = t / MULTISAMPLES lcd.print('\r', X0, Y0) # 表示位置以降をクリア lcd.print("%4.1f" % t, X0, Y0) # 温度を表示 time.sleep(5)
def draw(state): # draw time lcd.font(lcd.FONT_DejaVu40) m, s = divmod(state.time, 60) lcd.text(lcd.CENTER, 100, "{:02}:{:02}".format(m, s)) # draw menu lcd.font(lcd.FONT_DejaVu24) if state.state == IDLE: lcd.print("inc", 50, lcd.BOTTOM) lcd.print("dec", 140, lcd.BOTTOM) lcd.print("start", 225, lcd.BOTTOM) elif state.state == RUNNING: lcd.print(" ", 50, lcd.BOTTOM) lcd.print(" ", 140, lcd.BOTTOM) lcd.print("stop ", 227, lcd.BOTTOM)
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 display_header(): lcd.clear() lcd.font(DISPLAY_FONT) lcd.text(60, 20, "X-ACCEL:") lcd.text(60, 40, "Y-ACCEL:") lcd.text(60, 60, "Z-ACCEL:") if ORIENT_COOKED: lcd.text(60, 80, "HEADING:") lcd.text(88, 100, "PITCH:") lcd.text(102, 120, "ROLL:") else: lcd.text(88, 80, "X-ANGV:") lcd.text(88, 100, "Y-ANGV:") lcd.text(88, 120, "Z-ANGV:") lcd.text(102, 140, "LATI:") lcd.text(102, 160, "LONG:") lcd.text(88, 180, "SPEED:")