Kirill Vanin
/
2-3-5-Vanin
Case 2.5 for Samsung IoT.
Diff: main.cpp
- Revision:
- 107:6057ba53c368
- Parent:
- 105:ed03c03b353e
--- a/main.cpp Fri Nov 22 16:00:04 2019 +0000 +++ b/main.cpp Tue Nov 23 23:26:04 2021 +0000 @@ -1,23 +1,47 @@ -/* mbed Microcontroller Library - * Copyright (c) 2019 ARM Limited - * SPDX-License-Identifier: Apache-2.0 - */ +#include "mbed.h" +#include "Sht31.h" -#include "mbed.h" -#include "platform/mbed_thread.h" +DigitalOut led1(LED1); + +//sda, scl +Sht31 temp_sensor(I2C_SDA, I2C_SCL); -// Blinking rate in milliseconds -#define BLINKING_RATE_MS 500 +Thread thread, thread1; + +bool alarm = false; +int extreme_humidity = 40; + +void blink() +{ + while (true) + { + led1 = !led1; + wait_ms (alarm ? 100 : 1000); + } +} +void sensor_thread() +{ + float h; + while (true) { + h = temp_sensor.readHumidity(); + printf(" %f\n\r", h); + wait_ms (1000); + if (h >= extreme_humidity) + { + printf("ALARM ALARM ALARM \n\r"); + alarm = true; + } + else + { + alarm = false; + } + } +} int main() { - // Initialise the digital pin LED1 as an output - DigitalOut led(LED1); - - while (true) { - led = !led; - thread_sleep_for(BLINKING_RATE_MS); - } + thread.start(sensor_thread); + thread1.start(blink); }