AJB2K3
Published © GPL3+

Core2AWS Light Switch

How to control a light using a slide switch on the screen of the Core2 AWS

BeginnerFull instructions provided1 hour5
Core2AWS Light Switch

Things used in this project

Hardware components

M5Stack Core2 AWS
×1
Mini 3A Relay Unit
M5Stack Mini 3A Relay Unit
×1

Software apps and online services

M5Stack UIFlow

Story

Read more

Code

UIFlow Lamp Control

MicroPython
from m5stack import *
from m5stack_ui import *
from uiflow import *
import unit


screen = M5Screen()
screen.clean_screen()
screen.set_screen_bg_color(0xFFFFFF)
relay_0 = unit.get(unit.RELAY, unit.PORTB)






switch0 = M5Switch(x=85, y=126, w=150, h=50, bg_c=0xCCCCCC, color=0x0288FB, parent=None)
label0 = M5Label('Light Switch', x=55, y=25, color=0x000, font=FONT_MONT_34, parent=None)
label1 = M5Label('label1', x=140, y=85, color=0x000, font=FONT_MONT_14, parent=None)

def switch0_on():
  # global params
  relay_0.on()
  pass
switch0.on(switch0_on)

def switch0_off():
  # global params
  relay_0.off()
  pass
switch0.off(switch0_off)


while True:
  label1.set_text(str(switch0.get_state()))
  wait_ms(2)

Credits

AJB2K3

AJB2K3

37 projects • 20 followers
I have always had an interest in electronics but having failed my school exams, it has taken me 20+ years to produce products to share.

Comments

Add projectSign up / Login