예제 #1
0
def main():
    from gpiozero import LED, Button

    SOCKET = config.set_socket()
    FLOOR = 'f1'
    ROOM = 'bathroom'

    led1 = LED(21)
    led2 = LED(22)

    button1 = Button(11)
    button1.when_pressed = led1.toggle
    button2 = Button(12)
    button2.when_pressed = led2.toggle

    while True:
        command = SOCKET.recv(10240).decode(config.CODE).split(config.SPLIT)
        print(command)
        if command[0] == FLOOR or command[0] == config.ANY:
            if command[1] == ROOM or command[1] == config.ANY:
                if command[2] == config.LAMP or command[2] == config.ANY:
                    if command[3] == config.ONE or command[3] == config.ANY:
                        if command[4] == config.ON:
                            led1.on()
                        elif command[4] == config.OFF:
                            led1.off()
                        elif command[4] == config.CHANGE:
                            led1.toggle()
                    if command[3] == config.TWO or command[3] == config.ANY:
                        if command[4] == config.ON:
                            led2.on()
                        elif command[4] == config.OFF:
                            led2.off()
                        elif command[4] == config.CHANGE:
                            led2.toggle()
예제 #2
0
def main():
    from gpiozero import LED, Button

    SOCKET = config.set_socket()
    FLOOR = 'f1'
    ROOM = 'kitchen'
    COMMAND = 'f1;living_room;lamp;1;change'

    def button2_pressed():
        SOCKET.sendto(COMMAND.encode(config.CODE),
                      (config.MCAST_GRP, config.MCAST_PORT))

    led = LED(21)

    button1 = Button(11)
    button1.when_pressed = led.toggle

    button2 = Button(12)
    button2.when_pressed = button2_pressed

    while True:
        command = SOCKET.recv(10240).decode(config.CODE).split(config.SPLIT)
        print(command)
        if command[0] == FLOOR or command[0] == config.ANY:
            if command[1] == ROOM or command[1] == config.ANY:
                if command[2] == config.LAMP or command[2] == config.ANY:
                    if command[3] == config.ONE or command[3] == config.ANY:
                        if command[4] == config.ON:
                            led.on()
                        elif command[4] == config.OFF:
                            led.off()
                        elif command[4] == config.CHANGE:
                            led.toggle()
예제 #3
0
def main():
    from gpiozero import LED, Button
    from time import sleep

    SOCKET = config.set_socket()
    COMMAND = 'f1;*;lamp;*;off'

    def button2_pressed():
        SOCKET.sendto(COMMAND.encode(config.CODE),
                      (config.MCAST_GRP, config.MCAST_PORT))
        led.off()

    led = LED(21)

    button1 = Button(11)
    button1.when_pressed = led.toggle

    button2 = Button(12)
    button2.when_pressed = button2_pressed

    while True:
        sleep(0.1)