コード例 #1
0
def task1(self):
    # Task1 setup here
    yield

    while True:
        # Task1 loop here
        yield [pyRTOS.timeout(1)]  # Delay in seconds (Other task can run)
コード例 #2
0
def task6(self):
    ledpin6 = machine.Pin(5, machine.Pin.OUT)
    ledpin6.value(0)
    yield
    
    while True:
        ledpin6.toggle()
        yield [pyRTOS.timeout(0.75)]
コード例 #3
0
def task5(self):
    ledpin5 = machine.Pin(4, machine.Pin.OUT)
    ledpin5.value(0)
    yield
    
    while True:
        ledpin5.toggle()
        yield [pyRTOS.timeout(0.80)]
コード例 #4
0
def task4(self):
    ledpin4 = machine.Pin(3, machine.Pin.OUT)
    ledpin4.value(0)
    yield
    
    while True:
        ledpin4.toggle()
        yield [pyRTOS.timeout(0.85)]
コード例 #5
0
def task3(self):
    ledpin3 = machine.Pin(2, machine.Pin.OUT)
    ledpin3.value(0)
    yield
    
    while True:
        ledpin3.toggle()
        yield [pyRTOS.timeout(0.90)]
コード例 #6
0
def task16(self):
    ledpin16 = machine.Pin(15, machine.Pin.OUT)
    ledpin16.value(0)
    yield

    while True:
        ledpin16.toggle()
        yield [pyRTOS.timeout(0.25)]
コード例 #7
0
def task15(self):
    ledpin15 = machine.Pin(14, machine.Pin.OUT)
    ledpin15.value(0)
    yield

    while True:
        ledpin15.toggle()
        yield [pyRTOS.timeout(0.30)]
コード例 #8
0
def task14(self):
    ledpin14 = machine.Pin(13, machine.Pin.OUT)
    ledpin14.value(0)
    yield

    while True:
        ledpin14.toggle()
        yield [pyRTOS.timeout(0.35)]
コード例 #9
0
def task2(self):
    ledpin2 = machine.Pin(1, machine.Pin.OUT)
    ledpin2.value(0)
    yield
    
    while True:
        ledpin2.toggle()
        yield [pyRTOS.timeout(0.95)]
コード例 #10
0
def task13(self):
    ledpin13 = machine.Pin(12, machine.Pin.OUT)
    ledpin13.value(0)
    yield

    while True:
        ledpin13.toggle()
        yield [pyRTOS.timeout(0.40)]
コード例 #11
0
def task9(self):
    ledpin9 = machine.Pin(8, machine.Pin.OUT)
    ledpin9.value(0)
    yield
    
    while True:
        ledpin9.toggle()
        yield [pyRTOS.timeout(0.60)]
コード例 #12
0
def task10(self):
    ledpin10 = machine.Pin(9, machine.Pin.OUT)
    ledpin10.value(0)
    yield

    while True:
        ledpin10.toggle()
        yield [pyRTOS.timeout(0.55)]
コード例 #13
0
def task11(self):
    ledpin11 = machine.Pin(10, machine.Pin.OUT)
    ledpin11.value(0)
    yield

    while True:
        ledpin11.toggle()
        yield [pyRTOS.timeout(0.50)]
コード例 #14
0
def task8(self):
    ledpin8 = machine.Pin(7, machine.Pin.OUT)
    ledpin8.value(0)
    yield
    
    while True:
        ledpin8.toggle()
        yield [pyRTOS.timeout(0.65)]
コード例 #15
0
def task7(self):
    ledpin7 = machine.Pin(6, machine.Pin.OUT)
    ledpin7.value(0)
    yield
    
    while True:
        ledpin7.toggle()
        yield [pyRTOS.timeout(0.70)]
コード例 #16
0
def led9(self):
    ledpin9 = digitalio.DigitalInOut(board.GP8)
    ledpin9.direction = digitalio.Direction.OUTPUT
    ledpin9.value = False
    yield

    while True:
        ledpin9.value = not ledpin9.value
        yield [pyRTOS.timeout(0.60)]
コード例 #17
0
def led7(self):
    ledpin7 = digitalio.DigitalInOut(board.GP6)
    ledpin7.direction = digitalio.Direction.OUTPUT
    ledpin7.value = False
    yield

    while True:
        ledpin7.value = not ledpin7.value
        yield [pyRTOS.timeout(0.70)]
コード例 #18
0
def led8(self):
    ledpin8 = digitalio.DigitalInOut(board.GP7)
    ledpin8.direction = digitalio.Direction.OUTPUT
    ledpin8.value = False
    yield

    while True:
        ledpin8.value = not ledpin8.value
        yield [pyRTOS.timeout(0.65)]
コード例 #19
0
def led1(self):
    ledpin1 = digitalio.DigitalInOut(board.GP0)
    ledpin1.direction = digitalio.Direction.OUTPUT
    ledpin1.value = False
    yield

    while True:
        ledpin1.value = not ledpin1.value
        yield [pyRTOS.timeout(1)]
コード例 #20
0
def led6(self):
    ledpin6 = digitalio.DigitalInOut(board.GP5)
    ledpin6.direction = digitalio.Direction.OUTPUT
    ledpin6.value = False
    yield

    while True:
        ledpin6.value = not ledpin6.value
        yield [pyRTOS.timeout(0.75)]
コード例 #21
0
def led4(self):
    ledpin4 = digitalio.DigitalInOut(board.GP3)
    ledpin4.direction = digitalio.Direction.OUTPUT
    ledpin4.value = False
    yield

    while True:
        ledpin4.value = not ledpin4.value
        yield [pyRTOS.timeout(0.85)]
コード例 #22
0
def led5(self):
    ledpin5 = digitalio.DigitalInOut(board.GP4)
    ledpin5.direction = digitalio.Direction.OUTPUT
    ledpin5.value = False
    yield

    while True:
        ledpin5.value = not ledpin5.value
        yield [pyRTOS.timeout(0.80)]
コード例 #23
0
def led2(self):
    ledpin2 = digitalio.DigitalInOut(board.GP1)
    ledpin2.direction = digitalio.Direction.OUTPUT
    ledpin2.value = False
    yield

    while True:
        ledpin2.value = not ledpin2.value
        yield [pyRTOS.timeout(0.95)]
コード例 #24
0
def led3(self):
    ledpin3 = digitalio.DigitalInOut(board.GP2)
    ledpin3.direction = digitalio.Direction.OUTPUT
    ledpin3.value = False
    yield

    while True:
        ledpin3.value = not ledpin3.value
        yield [pyRTOS.timeout(0.90)]
コード例 #25
0
def led10(self):
    ledpin10 = digitalio.DigitalInOut(board.GP9)
    ledpin10.direction = digitalio.Direction.OUTPUT
    ledpin10.value = False
    yield

    while True:
        ledpin10.value = not ledpin10.value
        yield [pyRTOS.timeout(0.55)]
コード例 #26
0
def DetectMotion(self):
    PIR = digitalio.DigitalInOut(board.GP1)  # Setup PIR sensor pin
    PIR.direction = digitalio.Direction.INPUT  # Setup pin as digital input
    global motion  # Use the global variable
    yield

    while True:
        if PIR.value:  # If the PIR sensor detects motion
            motion = 1  # Update the global variable
        yield [pyRTOS.timeout(0.1)]  # Delay in seconds (Other task can run)
コード例 #27
0
def AirQuality(self):
    airq = analogio.AnalogIn(board.A1)  # Setup air quality sensor on pin A1
    conv = 330 / (65535)  # Formula to convert analog value to percentage
    global air  # Use the global variable
    yield

    while True:
        air = round((airq.value * conv),
                    2)  # Round off the value to 2 decimal places and update
        yield [pyRTOS.timeout(0.2)]  # Delay in seconds (Other task can run)
コード例 #28
0
def DetectSound(self):
    mic = digitalio.DigitalInOut(board.GP3)  # Setup sound sensor pin
    mic.direction = digitalio.Direction.INPUT  # Setup pin as digital input
    global sound  # Use the global variable
    yield

    while True:
        if mic.value:  # If the sound sensor detects loud sound
            sound = 1  # Update the global variable
        yield [pyRTOS.timeout(0.1)]  # Delay in seconds (Other task can run)
コード例 #29
0
def SendData(self):
    global temp
    global humidity
    global air
    global motion
    global sound
    try:
        from secrets import secrets
    except ImportError:
        print("All secret keys are kept in secrets.py, please add them there!")
        raise
    # Initialize UART connection to the ESP8266 WiFi Module.
    RX = board.GP17
    TX = board.GP16
    uart = busio.UART(
        TX, RX, receiver_buffer_size=2048
    )  # Use large buffer as we're not using hardware flow control.
    esp = adafruit_espatcontrol.ESP_ATcontrol(uart, 115200, debug=False)
    requests.set_socket(socket, esp)
    print("Resetting ESP module")
    esp.soft_reset()
    # Connect to WiFi
    print("Connecting to WiFi...")
    esp.connect(secrets)
    print("Connected!")
    yield

    while True:
        # Update the blynk datastream using HTTP GET requests
        requests.get("https://blynk.cloud/external/api/update?token=" +
                     secrets["blynk_auth_token"] + "&v0=" + str(temp))
        yield [pyRTOS.timeout(0.5)]  # Let other tasks run
        requests.get("https://blynk.cloud/external/api/update?token=" +
                     secrets["blynk_auth_token"] + "&v1=" + str(humidity))
        yield [pyRTOS.timeout(0.5)]  # Let other tasks run
        requests.get("https://blynk.cloud/external/api/update?token=" +
                     secrets["blynk_auth_token"] + "&v2=" + str(air))
        yield [pyRTOS.timeout(0.5)]  # Let other tasks run
        requests.get("https://blynk.cloud/external/api/update?token=" +
                     secrets["blynk_auth_token"] + "&v3=" + str(motion))
        yield [pyRTOS.timeout(0.5)]  # Let other tasks run
        requests.get("https://blynk.cloud/external/api/update?token=" +
                     secrets["blynk_auth_token"] + "&v4=" + str(sound))
        yield [pyRTOS.timeout(0.5)]  # Let other tasks run
        # Reset the global variables
        if motion:
            motion = 0
        if sound:
            sound = 0
        yield [pyRTOS.timeout(0.5)]  # Delay in seconds (Other task can run)
コード例 #30
0
def ReadDHT11(self):
    dhtDevice = adafruit_dht.DHT11(board.GP5)  # Setup DHTT11 on pin GP5
    global temp  # Use the global variables
    global humidity
    yield

    while True:
        try:
            temp = dhtDevice.temperature  # Update the global variables
            humidity = dhtDevice.humidity
        except RuntimeError as error:
            # Errors happen fairly often,
            # DHT's are hard to read,
            # just keep going
            print(error.args[0])
            continue
        except Exception as error:
            dhtDevice.exit()
            raise error
        yield [pyRTOS.timeout(1)]  # Delay in seconds (Other task can run)