Program očitava temperaturu i vlažnost zraka u prostoriji pomoću senzora DHT11. Očitane vrijednosti ispisuje na računalu u programu Tera Term. Za vlažnost zraka manju od 60% svijetli zelena LED, a za vlažnost zraka veću od 60% pali se crvena LED. Pritiskom na tipkalo prekida se rad programa na 5sekundi. Odbrojavanje se prikazuje na 7-segmentnom displey-u. Za to vrijeme ugašene su sve LED. Nakon isteka 5 sekundi program nastavlja sa radom tamo di je prethodno stao. Žuta LED predstavlja ticker i blinka svake 0,2 sekunde i time pokazuje da se program izvršava.

Dependencies:   mbed Konstrukcijski Ledica

Committer:
MarioBlazevic
Date:
Tue Apr 06 12:14:24 2021 +0000
Revision:
0:2bff2d7980f2

        

Who changed what in which revision?

UserRevisionLine numberNew contents of line
MarioBlazevic 0:2bff2d7980f2 1 #include "mbed.h"
MarioBlazevic 0:2bff2d7980f2 2 #include "dht11.h"
MarioBlazevic 0:2bff2d7980f2 3 #include "Ledica.h"
MarioBlazevic 0:2bff2d7980f2 4
MarioBlazevic 0:2bff2d7980f2 5 InterruptIn Button(D7);
MarioBlazevic 0:2bff2d7980f2 6 Timer debounce;
MarioBlazevic 0:2bff2d7980f2 7 Ticker flipper;
MarioBlazevic 0:2bff2d7980f2 8 Serial pc(USBTX, USBRX);
MarioBlazevic 0:2bff2d7980f2 9 Dht11 sensor(D8);
MarioBlazevic 0:2bff2d7980f2 10 Ledica zutaled(D2);
MarioBlazevic 0:2bff2d7980f2 11 Ledica zelenaled(D14);
MarioBlazevic 0:2bff2d7980f2 12 Ledica crvenaled(D13);
MarioBlazevic 0:2bff2d7980f2 13 DigitalOut A(D4);
MarioBlazevic 0:2bff2d7980f2 14 DigitalOut B(D3);
MarioBlazevic 0:2bff2d7980f2 15 DigitalOut C(D11);
MarioBlazevic 0:2bff2d7980f2 16 DigitalOut D(D10);
MarioBlazevic 0:2bff2d7980f2 17 DigitalOut E(D9);
MarioBlazevic 0:2bff2d7980f2 18 DigitalOut F(D5);
MarioBlazevic 0:2bff2d7980f2 19 DigitalOut G(D6);
MarioBlazevic 0:2bff2d7980f2 20 DigitalOut DP(D12);
MarioBlazevic 0:2bff2d7980f2 21
MarioBlazevic 0:2bff2d7980f2 22 void prekid(){
MarioBlazevic 0:2bff2d7980f2 23
MarioBlazevic 0:2bff2d7980f2 24 if (debounce.read_ms()>300)
MarioBlazevic 0:2bff2d7980f2 25
MarioBlazevic 0:2bff2d7980f2 26
MarioBlazevic 0:2bff2d7980f2 27 zutaled.status(0);
MarioBlazevic 0:2bff2d7980f2 28 crvenaled.status(0);
MarioBlazevic 0:2bff2d7980f2 29 zelenaled.status(0);
MarioBlazevic 0:2bff2d7980f2 30
MarioBlazevic 0:2bff2d7980f2 31 A=1; B=0; C=1; D=1; E=0; F=1; G=1; DP=0; // set LEDs '5'
MarioBlazevic 0:2bff2d7980f2 32 wait(1);
MarioBlazevic 0:2bff2d7980f2 33
MarioBlazevic 0:2bff2d7980f2 34 A=0; B=1; C=1; D=0; E=0; F=1; G=1; DP=0; // set LEDs '4'
MarioBlazevic 0:2bff2d7980f2 35 wait(1);
MarioBlazevic 0:2bff2d7980f2 36
MarioBlazevic 0:2bff2d7980f2 37 A=1; B=1; C=1; D=1; E=0; F=0; G=1; DP=0; // set LEDs '3'
MarioBlazevic 0:2bff2d7980f2 38 wait(1);
MarioBlazevic 0:2bff2d7980f2 39
MarioBlazevic 0:2bff2d7980f2 40 A=1; B=1; C=0; D=1; E=1; F=0; G=1; DP=0; // set LEDs '2'
MarioBlazevic 0:2bff2d7980f2 41 wait(1);
MarioBlazevic 0:2bff2d7980f2 42
MarioBlazevic 0:2bff2d7980f2 43 A=0; B=1; C=1; D=0; E=0; F=0; G=0; DP=0; // set LEDs '1'
MarioBlazevic 0:2bff2d7980f2 44 wait(1);
MarioBlazevic 0:2bff2d7980f2 45
MarioBlazevic 0:2bff2d7980f2 46
MarioBlazevic 0:2bff2d7980f2 47 A=0; B=0; C=0; D=0; E=0; F=0; G=0; DP=0; // set LEDs '0'
MarioBlazevic 0:2bff2d7980f2 48
MarioBlazevic 0:2bff2d7980f2 49 debounce.reset();
MarioBlazevic 0:2bff2d7980f2 50 }
MarioBlazevic 0:2bff2d7980f2 51
MarioBlazevic 0:2bff2d7980f2 52
MarioBlazevic 0:2bff2d7980f2 53 void flip(){
MarioBlazevic 0:2bff2d7980f2 54
MarioBlazevic 0:2bff2d7980f2 55 zutaled.flipp();
MarioBlazevic 0:2bff2d7980f2 56
MarioBlazevic 0:2bff2d7980f2 57 }
MarioBlazevic 0:2bff2d7980f2 58
MarioBlazevic 0:2bff2d7980f2 59
MarioBlazevic 0:2bff2d7980f2 60 int main() {
MarioBlazevic 0:2bff2d7980f2 61
MarioBlazevic 0:2bff2d7980f2 62 zutaled.status(0);
MarioBlazevic 0:2bff2d7980f2 63 crvenaled.status(0);
MarioBlazevic 0:2bff2d7980f2 64 zelenaled.status(0);
MarioBlazevic 0:2bff2d7980f2 65
MarioBlazevic 0:2bff2d7980f2 66 debounce.start();
MarioBlazevic 0:2bff2d7980f2 67 Button.rise(&prekid);
MarioBlazevic 0:2bff2d7980f2 68 flipper.attach(&flip,0.2);
MarioBlazevic 0:2bff2d7980f2 69
MarioBlazevic 0:2bff2d7980f2 70
MarioBlazevic 0:2bff2d7980f2 71
MarioBlazevic 0:2bff2d7980f2 72
MarioBlazevic 0:2bff2d7980f2 73 while(1){
MarioBlazevic 0:2bff2d7980f2 74
MarioBlazevic 0:2bff2d7980f2 75 sensor.read();
MarioBlazevic 0:2bff2d7980f2 76 pc.printf("Temperatura: %d, Vlaznost: %d\r\n", sensor.getCelsius(), sensor.getHumidity());
MarioBlazevic 0:2bff2d7980f2 77 wait(1);
MarioBlazevic 0:2bff2d7980f2 78
MarioBlazevic 0:2bff2d7980f2 79 if (sensor.getHumidity()<60){
MarioBlazevic 0:2bff2d7980f2 80
MarioBlazevic 0:2bff2d7980f2 81 zelenaled.status(1);
MarioBlazevic 0:2bff2d7980f2 82 crvenaled.status(0);
MarioBlazevic 0:2bff2d7980f2 83
MarioBlazevic 0:2bff2d7980f2 84 } else{
MarioBlazevic 0:2bff2d7980f2 85
MarioBlazevic 0:2bff2d7980f2 86 zelenaled.status(0);
MarioBlazevic 0:2bff2d7980f2 87 crvenaled.status(1);
MarioBlazevic 0:2bff2d7980f2 88
MarioBlazevic 0:2bff2d7980f2 89 }
MarioBlazevic 0:2bff2d7980f2 90 }
MarioBlazevic 0:2bff2d7980f2 91 }