@kuriko it's created by block editing...
import os, sys, io
import M5
from M5 import *
from label_plus import LabelPlus
from hardware import *
import time
from unit import EncoderUnit
label0 = None
label1 = None
label2 = None
label3 = None
BtnA = None
BtnB = None
BtnC = None
rect0 = None
rect1 = None
rect2 = None
rect3 = None
rect4 = None
rect5 = None
rect6 = None
rect7 = None
rect8 = None
rect9 = None
rect10 = None
rect11 = None
rect12 = None
rect13 = None
rect14 = None
rect15 = None
rect16 = None
rect17 = None
rect18 = None
rect19 = None
label7 = None
label8 = None
label9 = None
label10 = None
label11 = None
label12 = None
label13 = None
LA_4 = None
LA_3 = None
LA_2 = None
LA_1 = None
LB_4 = None
LB_3 = None
LB_2 = None
LB_1 = None
LC_4 = None
LC_3 = None
LC_2 = None
LC_1 = None
pin3 = None
pin1 = None
pin2 = None
pin5 = None
i2c1 = None
pin25 = None
pin26 = None
pin35 = None
pin36 = None
encoder_0 = None
l_enc_inc = None
INT_clock = None
t_values = None
enc_mode = None
curr_value = None
loc_value = None
Describe this function...
def init_all_out_pins_as_():
global l_enc_inc, INT_clock, t_values, enc_mode, curr_value, loc_value, label0, label1, label2, label3, BtnA, BtnB, BtnC, rect0, rect1, rect2, rect3, rect4, rect5, rect6, rect7, rect8, rect9, rect10, rect11, rect12, rect13, rect14, rect15, rect16, rect17, rect18, rect19, label7, label8, label9, label10, label11, label12, label13, LA_4, LA_3, LA_2, LA_1, LB_4, LB_3, LB_2, LB_1, LC_4, LC_3, LC_2, LC_1, pin3, pin1, pin2, pin5, i2c1, pin25, pin26, pin35, pin36, encoder_0
pin3 = Pin(3, mode=Pin.OUT, pull=Pin.PULL_UP)
pin1 = Pin(1, mode=Pin.OUT, pull=Pin.PULL_UP)
pin2 = Pin(2, mode=Pin.OUT, pull=Pin.PULL_UP)
pin5 = Pin(5, mode=Pin.OUT, pull=Pin.PULL_UP)
pin25 = Pin(25, mode=Pin.OUT, pull=Pin.PULL_UP)
pin26 = Pin(26, mode=Pin.OUT, pull=Pin.PULL_UP)
pin35 = Pin(35, mode=Pin.OUT, pull=Pin.PULL_UP)
pin36 = Pin(36, mode=Pin.OUT, pull=Pin.PULL_UP)
Describe this function...
def relay_outs_pin_set():
global l_enc_inc, INT_clock, t_values, enc_mode, curr_value, loc_value, label0, label1, label2, label3, BtnA, BtnB, BtnC, rect0, rect1, rect2, rect3, rect4, rect5, rect6, rect7, rect8, rect9, rect10, rect11, rect12, rect13, rect14, rect15, rect16, rect17, rect18, rect19, label7, label8, label9, label10, label11, label12, label13, LA_4, LA_3, LA_2, LA_1, LB_4, LB_3, LB_2, LB_1, LC_4, LC_3, LC_2, LC_1, pin3, pin1, pin2, pin5, i2c1, pin25, pin26, pin35, pin36, encoder_0
if t_values[-1] == INT_clock:
pin3.value(1)
if t_values[0] == INT_clock:
pin1.value(1)
if t_values[1] == INT_clock:
pin2.value(1)
if t_values[2] == INT_clock:
pin5.value(1)
if t_values[3] == INT_clock:
pin25.value(1)
if t_values[4] == INT_clock:
pin26.value(1)
if t_values[5] == INT_clock:
pin35.value(1)
if t_values[6] == INT_clock:
pin36.value(1)
if t_values[7] == INT_clock:
pin25.value(0)
if t_values[8] == INT_clock:
pin26.value(0)
if t_values[9] == INT_clock:
pin35.value(0)
if t_values[10] == INT_clock:
pin36.value(0)
if t_values[7] + 25 == INT_clock:
pin3.value(0)
if t_values[8] + 25 == INT_clock:
pin1.value(0)
if t_values[9] + 25 == INT_clock:
pin2.value(0)
if t_values[10] + 25 == INT_clock:
pin5.value(0)
Describe this function...
def all_out_pins_to_zero():
global l_enc_inc, INT_clock, t_values, enc_mode, curr_value, loc_value, label0, label1, label2, label3, BtnA, BtnB, BtnC, rect0, rect1, rect2, rect3, rect4, rect5, rect6, rect7, rect8, rect9, rect10, rect11, rect12, rect13, rect14, rect15, rect16, rect17, rect18, rect19, label7, label8, label9, label10, label11, label12, label13, LA_4, LA_3, LA_2, LA_1, LB_4, LB_3, LB_2, LB_1, LC_4, LC_3, LC_2, LC_1, pin3, pin1, pin2, pin5, i2c1, pin25, pin26, pin35, pin36, encoder_0
pin3.value(0)
pin1.value(0)
pin2.value(0)
pin5.value(0)
pin25.value(0)
pin26.value(0)
pin35.value(0)
pin36.value(0)
def setup():
global label0, label1, label2, label3, BtnA, BtnB, BtnC, rect0, rect1, rect2, rect3, rect4, rect5, rect6, rect7, rect8, rect9, rect10, rect11, rect12, rect13, rect14, rect15, rect16, rect17, rect18, rect19, label7, label8, label9, label10, label11, label12, label13, LA_4, LA_3, LA_2, LA_1, LB_4, LB_3, LB_2, LB_1, LC_4, LC_3, LC_2, LC_1, pin3, pin1, pin2, pin5, i2c1, pin25, pin26, pin35, pin36, encoder_0, l_enc_inc, INT_clock, t_values, enc_mode, curr_value, loc_value
M5.begin()
Widgets.fillScreen(0x222222)
label0 = Widgets.Label("Key 1", 4, 185, 1.0, 0xffffff, 0x222222, Widgets.FONTS.DejaVu12)
label1 = Widgets.Label("Key 1", 4, 135, 1.0, 0xffffff, 0x222222, Widgets.FONTS.DejaVu12)
label2 = Widgets.Label("Key 2", 5, 85, 1.0, 0xffffff, 0x222222, Widgets.FONTS.DejaVu12)
label3 = Widgets.Label("Key 4", 5, 35, 1.0, 0xffffff, 0x222222, Widgets.FONTS.DejaVu12)
BtnA = Widgets.Label("A", 60, 222, 1.0, 0xffffff, 0x222222, Widgets.FONTS.DejaVu18)
BtnB = Widgets.Label("B", 150, 222, 1.0, 0xffffff, 0x222222, Widgets.FONTS.DejaVu18)
BtnC = Widgets.Label("C", 240, 222, 1.0, 0xffffff, 0x222222, Widgets.FONTS.DejaVu18)
rect0 = Widgets.Rectangle(100, 40, 40, 25, 0xffffff, 0x0f0957)
rect1 = Widgets.Rectangle(143, 40, 40, 25, 0xffffff, 0x0f0957)
rect2 = Widgets.Rectangle(186, 40, 40, 25, 0xffffff, 0x0f0957)
rect3 = Widgets.Rectangle(229, 40, 40, 25, 0xffffff, 0x0f0957)
rect4 = Widgets.Rectangle(100, 68, 40, 25, 0xffffff, 0x0f0957)
rect5 = Widgets.Rectangle(143, 68, 40, 25, 0xffffff, 0x0f0957)
rect6 = Widgets.Rectangle(186, 68, 40, 25, 0xffffff, 0x0f0957)
rect7 = Widgets.Rectangle(229, 68, 40, 25, 0xffffff, 0x0f0957)
rect8 = Widgets.Rectangle(100, 96, 40, 25, 0xffffff, 0x0f0957)
rect9 = Widgets.Rectangle(100, 124, 40, 25, 0xffffff, 0x0f0957)
rect10 = Widgets.Rectangle(100, 152, 40, 25, 0xffffff, 0x0f0957)
rect11 = Widgets.Rectangle(143, 96, 40, 25, 0xffffff, 0x0f0957)
rect12 = Widgets.Rectangle(186, 96, 40, 25, 0xffffff, 0x0f0957)
rect13 = Widgets.Rectangle(229, 96, 40, 25, 0xffffff, 0x0f0957)
rect14 = Widgets.Rectangle(143, 124, 40, 25, 0xffffff, 0x0f0957)
rect15 = Widgets.Rectangle(186, 124, 40, 25, 0xffffff, 0x0f0957)
rect16 = Widgets.Rectangle(229, 124, 40, 25, 0xffffff, 0x0f0957)
rect17 = Widgets.Rectangle(143, 152, 40, 25, 0xffffff, 0x0f0957)
rect18 = Widgets.Rectangle(186, 152, 40, 25, 0xffffff, 0x0f0957)
rect19 = Widgets.Rectangle(229, 152, 40, 25, 0xffffff, 0x0f0957)
label7 = Widgets.Label("A", 159, 46, 1.0, 0xffffff, 0x222222, Widgets.FONTS.DejaVu12)
label8 = Widgets.Label("B", 202, 46, 1.0, 0xffffff, 0x222222, Widgets.FONTS.DejaVu12)
label9 = Widgets.Label("C", 243, 46, 1.0, 0xffffff, 0x222222, Widgets.FONTS.DejaVu12)
label10 = Widgets.Label("K4", 112, 74, 1.0, 0xffffff, 0x222222, Widgets.FONTS.DejaVu12)
label11 = Widgets.Label("K3", 113, 102, 1.0, 0xffffff, 0x222222, Widgets.FONTS.DejaVu12)
label12 = Widgets.Label("K2", 113, 129, 1.0, 0xffffff, 0x222222, Widgets.FONTS.DejaVu12)
label13 = Widgets.Label("K1", 113, 157, 1.0, 0xffffff, 0x222222, Widgets.FONTS.DejaVu12)
LA_4 = LabelPlus("0,0", 153, 74, 1.0, 0x9aff00, 0x000000, Widgets.FONTS.DejaVu12, "http://", 3000, False, None, "error", 0xFF0000)
LA_3 = LabelPlus("0,0", 153, 102, 1.0, 0x9aff00, 0x000000, Widgets.FONTS.DejaVu12, "http://", 3000, False, None, "error", 0xFF0000)
LA_2 = LabelPlus("0,0", 153, 129, 1.0, 0x9aff00, 0x000000, Widgets.FONTS.DejaVu12, "http://", 3000, False, None, "error", 0xFF0000)
LA_1 = LabelPlus("0,0", 153, 157, 1.0, 0x9aff00, 0x000000, Widgets.FONTS.DejaVu12, "http://", 3000, False, None, "error", 0xFF0000)
LB_4 = LabelPlus("0,0", 195, 74, 1.0, 0x9aff00, 0x000000, Widgets.FONTS.DejaVu12, "http://", 3000, False, None, "error", 0xFF0000)
LB_3 = LabelPlus("0,0", 195, 102, 1.0, 0x9aff00, 0x000000, Widgets.FONTS.DejaVu12, "http://", 3000, False, None, "error", 0xFF0000)
LB_2 = LabelPlus("0,0", 195, 129, 1.0, 0x9aff00, 0x000000, Widgets.FONTS.DejaVu12, "http://", 3000, False, None, "error", 0xFF0000)
LB_1 = LabelPlus("0,0", 195, 157, 1.0, 0x9aff00, 0x000000, Widgets.FONTS.DejaVu12, "http://", 3000, False, None, "error", 0xFF0000)
LC_4 = LabelPlus("0,0", 239, 74, 1.0, 0x9aff00, 0x000000, Widgets.FONTS.DejaVu12, "http://", 3000, False, None, "error", 0xFF0000)
LC_3 = LabelPlus("0,0", 239, 102, 1.0, 0x9aff00, 0x000000, Widgets.FONTS.DejaVu12, "http://", 3000, False, None, "error", 0xFF0000)
LC_2 = LabelPlus("0,0", 239, 129, 1.0, 0x9aff00, 0x000000, Widgets.FONTS.DejaVu12, "http://", 3000, False, None, "error", 0xFF0000)
LC_1 = LabelPlus("0,0", 239, 157, 1.0, 0x9aff00, 0x000000, Widgets.FONTS.DejaVu12, "http://", 3000, False, None, "error", 0xFF0000)
init_all_out_pins_as_()
all_out_pins_to_zero()
i2c1 = I2C(1, scl=Pin(22), sda=Pin(21), freq=100000)
t_values = bytearray(12)
enc_mode = 0
curr_value = 0
INT_clock = 0
encoder_0 = EncoderUnit(i2c1, 0x40)
def loop():
global label0, label1, label2, label3, BtnA, BtnB, BtnC, rect0, rect1, rect2, rect3, rect4, rect5, rect6, rect7, rect8, rect9, rect10, rect11, rect12, rect13, rect14, rect15, rect16, rect17, rect18, rect19, label7, label8, label9, label10, label11, label12, label13, LA_4, LA_3, LA_2, LA_1, LB_4, LB_3, LB_2, LB_1, LC_4, LC_3, LC_2, LC_1, pin3, pin1, pin2, pin5, i2c1, pin25, pin26, pin35, pin36, encoder_0, l_enc_inc, INT_clock, t_values, enc_mode, curr_value, loc_value
M5.update()
time.sleep_us(20)
if INT_clock == 0:
time.sleep_ms(99)
INT_clock = INT_clock + 1
relay_outs_pin_set()
l_enc_inc = encoder_0.get_rotary_increments()
if encoder_0.get_button_status():
encoder_0.fill_color(0x990000)
enc_mode = 1
if l_enc_inc != 0:
curr_value = curr_value + l_enc_inc
while curr_value < 0:
curr_value = curr_value + 12
while curr_value > 11:
curr_value = curr_value - 12
else:
encoder_0.fill_color(0x000066)
enc_mode = 0
if l_enc_inc != 0:
loc_value = t_values[int(curr_value - 1)] + l_enc_inc
if loc_value < 0:
loc_value = 0
if loc_value > 99:
loc_value = 99
t_values[int(curr_value - 1)] = loc_value
if curr_value==0:
LA_4.setText(str(((str((loc_value / 10))).strip())))
elif curr_value==1:
LA_3.setText(str(((str((loc_value / 10))).strip())))
elif curr_value==2:
LA_2.setText(str(((str((loc_value / 10))).strip())))
elif curr_value==3:
LA_1.setText(str(((str((loc_value / 10))).strip())))
elif curr_value==4:
LB_4.setText(str(((str((loc_value / 10))).strip())))
elif curr_value==5:
LB_3.setText(str(((str((loc_value / 10))).strip())))
elif curr_value==6:
LB_2.setText(str(((str((loc_value / 10))).strip())))
elif curr_value==7:
LB_1.setText(str(((str((loc_value / 10))).strip())))
elif curr_value==8:
LC_4.setText(str(((str((loc_value / 10))).strip())))
elif curr_value==9:
LC_3.setText(str(((str((loc_value / 10))).strip())))
elif curr_value==10:
LC_2.setText(str(((str((loc_value / 10))).strip())))
elif curr_value==11:
LC_1.setText(str(((str((loc_value / 10))).strip())))
else:
pass
if name == 'main':
try:
setup()
while True:
loop()
except (Exception, KeyboardInterrupt) as e:
try:
from utility import print_error_msg
print_error_msg(e)
except ImportError:
print("please update to latest firmware")