Example from M5Stack: https://github.com/m5stack/UIFlow-Code/wiki/Unit#tof """ from m5stack import lcd from m5ui import M5TextBox, M5Title, setScreenColor from uiflow import wait_ms import time import hat import math lcd.clear() lcd.setRotation(3) distfield = M5TextBox(40, 20, "0", lcd.FONT_DejaVu40, 0x08feab) distlabel = M5TextBox(0, 0, "M5Stick VL53L0X Hat", lcd.FONT_Small, 0xFFFFFF) tof = hat.get(hat.TOF) def mean(readings): sumHat = 0 for x in readings: sumHat += x return sumHat / len(readings) numReadings = [] while True: for i in range(50): distfield.setText(str(tof.GetDistance()))
from m5stack import * from m5ui import * from uiflow import * import espnow import wifiCfg lcd.setRotation(1) import hat import hat setScreenColor(0x111111) hat_spk1 = hat.get(hat.SPEAKER) wifiCfg.wlan_ap.active(True) espnow.init() txt = None NPD = None counter = None POWER = None stop_flag = None def recv_cb(_): global txt,NPD,counter,POWER,stop_flag _, _, txt = espnow.recv_data(encoder='str') if txt.count('NPD=') > 0: NPD = txt.replace('NPD=', '') POWER = float(NPD)
from m5stack import * from m5ui import * from uiflow import * import espnow import wifiCfg import hat axp.setLDO2Volt(2.8) setScreenColor(0x000000) hat_roverc0 = hat.get(hat.ROVERC) label0 = M5TextBox(1, 48, "Status", lcd.FONT_Default, 0xFFFFFF, rotate=0) label1 = M5TextBox(1, 62, "Controls", lcd.FONT_Default, 0xFFFFFF, rotate=0) titlebar = M5Title(title="text", x=3, fgcolor=0xFFFFFF, bgcolor=0x5b5b5b) paired = False addr = None data = None def main(): wifiCfg.wlan_ap.active(True) wifiCfg.wlan_sta.active(True) espnow.init() espnow.recv_cb(receive_msg) label0.setText(str('broadcasting'))
from m5stack import * from m5ui import * from uiflow import * import time import hat import BlynkLib from numbers import Number setScreenColor(0x111111) hat_pir3 = hat.get(hat.PIR) VC = None setScreenColor(0xff0000) BLYNK_AUTH = '<Your blynk API crendetial>' blynk = BlynkLib.Blynk(BLYNK_AUTH) @timerSch.event('__blynk_timer') def __blink_timer(): blynk.run() timerSch.run('__blynk_timer', 2, 0x00) wait(10) VC = 0 while True: if (hat_pir3.state) == 1: setScreenColor(0x33ff33) VC = (VC if isinstance(VC, Number) else 0) + 1
from m5stack import * from m5ui import * from uiflow import * import espnow import wifiCfg import json import hat setScreenColor(0x111111) hat_BeetleC9 = hat.get(hat.BEETLEC) espnow.init() title0 = M5Title(title="Title", x=3, fgcolor=0xFFFFFF, bgcolor=0x0000FF) label0 = M5TextBox(8, 56, "Text", lcd.FONT_Default, 0xFFFFFF, rotate=0) label1 = M5TextBox(43, 57, "Text", lcd.FONT_Default, 0xFFFFFF, rotate=0) label2 = M5TextBox(26, 86, "Text", lcd.FONT_Default, 0xFFFFFF, rotate=0) rectangle0 = M5Rect(28, 105, 20, 20, 0xFFFFFF, 0xFFFFFF) color = None addr = None data = None message = None left = None right = None def set_led(): global color, addr, data, message, left, right color = message['color']
from m5stack import * from m5ui import * from uiflow import * import hat import time import hat setScreenColor(0x111111) hat_spk0 = hat.get(hat.SPEAKER) title0 = M5Title(title="Timer", x=1 , fgcolor=0xFFFFFF, bgcolor=0x0000FF) button_time_label = M5TextBox(4, 72, "Text", lcd.FONT_Ubuntu,0xFFFFFF, rotate=0) rectangle0 = M5Rect(10, 140, 60, 10, 0xFFFFFF, 0xFFFFFF) rectangle1 = M5Rect(10, 120, 60, 10, 0xFFFFFF, 0xFFFFFF) rectangle2 = M5Rect(10, 100, 60, 10, 0xFFFFFF, 0xFFFFFF) timer_m = M5TextBox(2, 25, "22", lcd.FONT_DejaVu24,0xFFFFFF, rotate=0) timer_s = M5TextBox(41, 25, "00", lcd.FONT_DejaVu24,0xFFFFFF, rotate=0) colon = M5TextBox(33, 22, ":", lcd.FONT_DejaVu24,0xFFFFFF, rotate=0) timer_label = M5TextBox(41, 72, "2500", lcd.FONT_Ubuntu,0xFFFFFF, rotate=0) batt_label = M5TextBox(48, 4, "100%", lcd.FONT_DefaultSmall,0xFFFFFF, rotate=0) msg_label = M5TextBox(9, 55, "message", lcd.FONT_DefaultSmall,0xFFFFFF, rotate=0) from numbers import Number button_time = None timer_count = None button_press_count = None timer_running = None
import gc, hat, time speaker = hat.get(hat.SPEAKER) def tone(a, b): speaker.tone(int(b), a * 80) def delay(s): time.sleep(s / 1000) def noTone(s): time.sleep(s / 1000) C0 = 16.35 Db0 = 17.32 D0 = 18.35 Eb0 = 19.45 E0 = 20.60 F0 = 21.83 Gb0 = 23.12 G0 = 24.50 Ab0 = 25.96 A0 = 27.50 Bb0 = 29.14 B0 = 30.87 C1 = 32.70 Db1 = 34.65
FirstLine.setText(wifi) ############################# Server Setup #################################### # Declare the server characteristics server_protocol = "http" server_host = "3.14.28.95" server_port = "8086" server_query = "write?db=m5stack" # Create a socket that can be used to connect and send data sock_ai = socket.getaddrinfo(server_host, server_port, 0, socket.SOCK_STREAM) sock_ai = sock_ai[0] ############################# Sensors Setup ################################### # Retrieve hat environment on M5stack hat_env = hat.get(hat.ENV) # Initialize sensor variables temperature = None humidity = None pressure = None sensor_data_template = "environment,sensor=m5stack temperature={},humidity={},pressure={}" printout_template = "T:{},H:{},P:{}" ############################# Display Setup ################################### # Text box to display data SecondLine = M5TextBox(55, 10, "", lcd.FONT_Default, 0xFFFFFF, rotate=90) ThirdLine = M5TextBox(35, 10, "", lcd.FONT_Default, 0xFFFFFF, rotate=90) ############################# Measure and stream ############################## # Define maximum number of points and counter
from m5stack import * from m5ui import * from uiflow import * import time import hat setScreenColor(0x111111) hat_Joystick0 = hat.get(hat.JOYSTICK) atrouver = None niveau = None fdj = None dir2 = None sequence = None high_score = None action = None i = None k = None continue2 = None x = None y = None sens = M5TextBox(20, 5, "Text", lcd.FONT_Default, 0xFFFFFF, rotate=0) nivea = M5TextBox(0, 144, "Niveau", lcd.FONT_Default, 0xFFFFFF, rotate=0) niveau_en_cours = M5TextBox(59, 144, "Text", lcd.FONT_Default, 0xFFFFFF, rotate=0)
from m5stack import * from m5ui import * import espnow import wifiCfg import hat joy_pos = None paired = False addr = None data = None setScreenColor(0x000000) axp.setLDO2Volt(2.8) hat_joyc0 = hat.get(hat.JOYC) label0 = M5TextBox(22, 48, "Text", lcd.FONT_Default, 0xFFFFFF, rotate=0) label1 = M5TextBox(22, 62, "Text", lcd.FONT_Default, 0xFFFFFF, rotate=0) label2 = M5TextBox(22, 76, "Text", lcd.FONT_Default, 0xFFFFFF, rotate=0) label3 = M5TextBox(22, 90, "Text", lcd.FONT_Default, 0xFFFFFF, rotate=0) label4 = M5TextBox(22, 104, "Unpaired", lcd.FONT_Default, 0xFFFFFF, rotate=0) titlebar = M5Title(title="text", x=3, fgcolor=0xFFFFFF, bgcolor=0x5b5b5b) def main(): hat_joyc0.SetLedColor(0x3232ff) wifiCfg.wlan_ap.active(True) wifiCfg.wlan_sta.active(True) espnow.init() espnow.recv_cb(receive_msg)
def __init__(self): self.rv = hat.get(hat.ROVERC)