from machine import Pin
from time import sleep_ms
import onebutton

#switch box @living room
boxID_1 = 'B1' 
pinList_1 = [14,12,13]
patList_1 = ['000','100','110','111','001']

#switch box @terrace
boxID_2 = 'B2'
pinList_2 = [4,5]
patList_2 = ['00','10','01','11']

Box_01 = onebutton.Config(boxID_1, pinList_1, patList_1)
Box_02 = onebutton.Config(boxID_2, pinList_2, patList_2)

#set pin 15 as button@living room
button1 = Pin(15, Pin.IN, Pin.PULL_UP)

#set pin 2 as button@terrace
button2 = Pin(2, Pin.IN, Pin.PULL_UP)

while True:
    while not button1.value() or not button2.value():
        pass
    if not button1.value():
        Box_01.push()
        Box_01.turn()
    if not button2.value():
        Box_02.push()
Exemple #2
0
    "MQTT_BROKER": "192.168.1.46",
    "USER": "",
    "PASSWORD": "",
    "PORT": 1883,
    # unique identifier of the chip
    "CLIENT_ID": b"ESP8266" + ubinascii.hexlify(machine.unique_id())
}
Topic = b"box1"

#switch box @living room
boxID = 'B1'
pinList = [14, 12, 13]
patList = ['000', '100', '110', '111', '001']

#create onebutton object
box = onebutton.Config(boxID, pinList, patList)

#set pin 15 as button
button = machine.Pin(15, machine.Pin.IN, machine.Pin.PULL_UP)


def sub_cb(topic, msg):
    msg = json.loads(msg)
    if msg['pattern'] != box.pattern:
        led.off()
        print(msg + "(from dashboard)")
        box.pattern = msg['pattern']
        box.iturn()
        if box.pattern in box.patternList:
            box.state = box.patternList.index(box.pattern)
        led.on()