View Single Post
Old 01-31-2021, 03:21 AM   #28
andyh2000
Avid reader
andyh2000 ought to be getting tired of karma fortunes by now.andyh2000 ought to be getting tired of karma fortunes by now.andyh2000 ought to be getting tired of karma fortunes by now.andyh2000 ought to be getting tired of karma fortunes by now.andyh2000 ought to be getting tired of karma fortunes by now.andyh2000 ought to be getting tired of karma fortunes by now.andyh2000 ought to be getting tired of karma fortunes by now.andyh2000 ought to be getting tired of karma fortunes by now.andyh2000 ought to be getting tired of karma fortunes by now.andyh2000 ought to be getting tired of karma fortunes by now.andyh2000 ought to be getting tired of karma fortunes by now.
 
andyh2000's Avatar
 
Posts: 889
Karma: 6543210
Join Date: Apr 2009
Location: UK
Device: Samsung Galaxy Z Flip 4 / Kindle Paperwhite / TCL Nxtpaper 14
The M5Stack devices really are a nice ecosystem and easy to program in blockly (uiflow) or straight micropython. I've got an Atom Matrix that talks to a Core via local mqtt broker. The Atom acts as a visual remote control and the Core is a free/busy sign for my study door when I'm on work video calls.

I'd been holding off getting an M5Paper as I have drawers full of unused microcontrollers but I feel myself weakening now.

Click image for larger version

Name:	Screenshot 2021-01-31 at 08.25.41.png
Views:	367
Size:	424.1 KB
ID:	185099

Atom Matrix code (from uiflow):
Code:
from m5stack import *
from m5ui import *
from uiflow import *
from m5mqtt import M5mqtt

rgb.set_screen([0,0,0,0,0,0,0xffffff,0,0xffffff,0,0,0,0,0,0,0xffffff,0,0,0,0xffffff,0,0xffffff,0xffffff,0xffffff,0])


current_state = None




# Describe this function...
def set_lights_blue():
  global current_state
  rgb.set_screen([0,0x0000ff,0x0000ff,0,0,0,0,0,0x0000ff,0,0,0,0x0000ff,0,0,0,0,0,0,0,0,0,0x0000ff,0,0])

# Describe this function...
def set_lights_green():
  global current_state
  rgb.set_screen([0,0,0,0,0,0,0,0,0,0x00ff00,0,0,0,0x00ff00,0,0x00ff00,0,0x00ff00,0,0,0,0x00ff00,0,0,0])

# Describe this function...
def set_lights_red():
  global current_state
  rgb.set_screen([0xff0000,0,0,0,0xff0000,0,0xff0000,0,0xff0000,0,0,0,0xff0000,0,0,0,0xff0000,0,0xff0000,0,0xff0000,0,0,0,0xff0000])


def fun__freebusy_check_(topic_data):
  global current_state
  current_state = int(topic_data)
  if current_state == 0:
    set_lights_green()
  else:
    if current_state == 1:
      set_lights_red()
    else:
      set_lights_blue()
  pass

def buttonA_wasPressed():
  global current_state
  if current_state == 0:
    m5mqtt.publish(str('/freebusy'),str('on'))
  else:
    if current_state == 1:
      m5mqtt.publish(str('/freebusy'),str('off'))
    else:
      m5mqtt.publish(str('/freebusy'),str('check'))
  pass
btnA.wasPressed(buttonA_wasPressed)


current_state = -1
m5mqtt = M5mqtt('m5atom_remote', '192.168.1.226', 1883, '', '', 300)
m5mqtt.subscribe(str('/freebusy_check'), fun__freebusy_check_)
m5mqtt.start()
set_lights_blue()
m5mqtt.publish(str('/freebusy'),str('check'))
while True:
  wait_ms(2)
Core code:
Code:
from m5stack import *
from uiflow import *
from m5ui import *
import wifiCfg
import socket
from m5mqtt import M5mqtt

want_check = False

def on_msg(payload):
  global want_check
  global state
  led_on = payload.find('on')
  led_off = payload.find('off')
  check = payload.find('check')

  if led_on == 0:
    state = 1
    rgb.setColorAll(0xFF0000)
    setScreenColor(0xFF0000)
    lcd.setBrightness(30)
    rectangle0.show()
    busylabel.show()
    want_check = True
  if led_off == 0:
    state = 0
    rgb.setColorAll(0x000000)
    setScreenColor(0x000000)
    lcd.setBrightness(0)
    rectangle0.hide()
    busylabel.hide()
    want_check = True

  if check == 0:
    want_check = True

state = 0 #state variable for the leds

ip = wifiCfg.wlan_sta.ifconfig()

rectangle0 = M5Rect(0, 0, 318, 240, 0xff0000, 0xFFFFFF)
busylabel = M5TextBox(61, 81, "BUSY", lcd.FONT_DejaVu72,0xFFFFFF, rotate=0)

rgb.setColorAll(0x000000)
setScreenColor(0x000000)
lcd.setBrightness(0)
rectangle0.hide()
busylabel.hide()

m5mqtt = M5mqtt('m5core_free_busy', '192.168.1.226', 1883, 'user', 'pw', 300)
m5mqtt.subscribe("/freebusy", on_msg)
m5mqtt.start()

while True:
  if want_check:
    m5mqtt.publish("/freebusy_check", str(state))
    want_check = False
  wait(1)
Andrew

Last edited by andyh2000; 01-31-2021 at 03:29 AM. Reason: Added screenshot
andyh2000 is offline   Reply With Quote