Kirill Vanin
/
2-3-5-Vanin
Case 2.5 for Samsung IoT.
Revision 107:6057ba53c368, committed 2021-11-23
- Comitter:
- kirborg
- Date:
- Tue Nov 23 23:26:04 2021 +0000
- Parent:
- 106:d323dd088ba2
- Commit message:
- Case 2.5 for Samsung IoT. Made by Vanin Kirill.
Changed in this revision
Sht31.lib | Show annotated file Show diff for this revision Revisions of this file |
main.cpp | Show annotated file Show diff for this revision Revisions of this file |
diff -r d323dd088ba2 -r 6057ba53c368 Sht31.lib --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/Sht31.lib Tue Nov 23 23:26:04 2021 +0000 @@ -0,0 +1,1 @@ +http://os.mbed.com/users/andcor02/code/Sht31/#c84a60326ecf
diff -r d323dd088ba2 -r 6057ba53c368 main.cpp --- 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); }