sicaklik mesafe okuma
Dependencies: mbed mbed-rtos TextLCD DHT11
main.cpp@3:90c2a3485cf6, 2019-10-23 (annotated)
- Committer:
- marvas
- Date:
- Wed Oct 23 08:50:28 2019 +0000
- Revision:
- 3:90c2a3485cf6
- Parent:
- 2:f6e831d1901e
en son
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
marvas | 0:2988d5981310 | 1 | |
marvas | 0:2988d5981310 | 2 | #include "mbed.h" |
marvas | 3:90c2a3485cf6 | 3 | |
marvas | 0:2988d5981310 | 4 | #include "TextLCD.h" |
marvas | 0:2988d5981310 | 5 | #include "rtos.h" |
marvas | 0:2988d5981310 | 6 | #include "DHT11.h" |
marvas | 2:f6e831d1901e | 7 | #include <iostream> |
marvas | 3:90c2a3485cf6 | 8 | Timer sure; |
marvas | 1:9ae75feba103 | 9 | TextLCD lcd(D11, D12, D7, D8, D9, D10); // rs, e, d4-d7 |
marvas | 1:9ae75feba103 | 10 | DigitalOut buzzer(A0); |
marvas | 3:90c2a3485cf6 | 11 | DigitalIn echo(D6); |
marvas | 3:90c2a3485cf6 | 12 | DigitalOut trig(D5); |
marvas | 0:2988d5981310 | 13 | Thread msf,dht_11; |
marvas | 0:2988d5981310 | 14 | DHT11 t(D3); |
marvas | 3:90c2a3485cf6 | 15 | long mesafe; |
marvas | 2:f6e831d1901e | 16 | volatile long x;//bu değişken bütün threadlerde çalışır |
marvas | 0:2988d5981310 | 17 | volatile char sicaklik,nem; |
marvas | 0:2988d5981310 | 18 | void sicaklikmetodu() |
marvas | 0:2988d5981310 | 19 | { |
marvas | 0:2988d5981310 | 20 | while(1) |
marvas | 0:2988d5981310 | 21 | { |
marvas | 0:2988d5981310 | 22 | t.readData(); |
marvas | 0:2988d5981310 | 23 | sicaklik= t.readTemperature(); |
marvas | 0:2988d5981310 | 24 | nem=t.readHumidity(); |
marvas | 0:2988d5981310 | 25 | cout<<"Sicaklik:"<<t.readTemperature()<<" Nem:%"<<t.readHumidity()<<endl; |
marvas | 0:2988d5981310 | 26 | lcd.locate(0,1); |
marvas | 3:90c2a3485cf6 | 27 | lcd.printf("S:%d N:%d", sicaklik,nem); |
marvas | 0:2988d5981310 | 28 | wait(2); |
marvas | 0:2988d5981310 | 29 | |
marvas | 0:2988d5981310 | 30 | } |
marvas | 0:2988d5981310 | 31 | } |
marvas | 0:2988d5981310 | 32 | void mesafemetodu() |
marvas | 0:2988d5981310 | 33 | { |
marvas | 0:2988d5981310 | 34 | while(1) |
marvas | 0:2988d5981310 | 35 | { |
marvas | 2:f6e831d1901e | 36 | if(x<50) |
marvas | 0:2988d5981310 | 37 | { |
marvas | 0:2988d5981310 | 38 | buzzer=1; |
marvas | 0:2988d5981310 | 39 | wait(300); |
marvas | 0:2988d5981310 | 40 | buzzer=0; |
marvas | 0:2988d5981310 | 41 | wait(300); |
marvas | 0:2988d5981310 | 42 | } |
marvas | 0:2988d5981310 | 43 | else |
marvas | 0:2988d5981310 | 44 | { |
marvas | 0:2988d5981310 | 45 | buzzer=0; |
marvas | 0:2988d5981310 | 46 | } |
marvas | 0:2988d5981310 | 47 | |
marvas | 0:2988d5981310 | 48 | } |
marvas | 0:2988d5981310 | 49 | } |
marvas | 1:9ae75feba103 | 50 | |
marvas | 0:2988d5981310 | 51 | int main() { |
marvas | 2:f6e831d1901e | 52 | |
marvas | 0:2988d5981310 | 53 | msf.start(mesafemetodu); |
marvas | 0:2988d5981310 | 54 | dht_11.start(sicaklikmetodu); |
marvas | 0:2988d5981310 | 55 | while(1) { |
marvas | 3:90c2a3485cf6 | 56 | sure.reset(); |
marvas | 3:90c2a3485cf6 | 57 | trig=0; |
marvas | 3:90c2a3485cf6 | 58 | wait_us(5); |
marvas | 3:90c2a3485cf6 | 59 | trig=1; |
marvas | 3:90c2a3485cf6 | 60 | wait_us(10); |
marvas | 3:90c2a3485cf6 | 61 | sure.start(); |
marvas | 3:90c2a3485cf6 | 62 | trig=0; |
marvas | 3:90c2a3485cf6 | 63 | while(!echo); // start pulseIN |
marvas | 3:90c2a3485cf6 | 64 | sure.start(); |
marvas | 3:90c2a3485cf6 | 65 | while(echo); |
marvas | 3:90c2a3485cf6 | 66 | sure.stop(); |
marvas | 3:90c2a3485cf6 | 67 | mesafe=sure.read_us()/58.2; |
marvas | 3:90c2a3485cf6 | 68 | printf("%f cm \n",mesafe); |
marvas | 3:90c2a3485cf6 | 69 | x=mesafe; |
marvas | 3:90c2a3485cf6 | 70 | if( mesafe<200) |
marvas | 0:2988d5981310 | 71 | { |
marvas | 3:90c2a3485cf6 | 72 | printf("Mesafe %d \n",mesafe); |
marvas | 0:2988d5981310 | 73 | lcd.locate(0,0); |
marvas | 3:90c2a3485cf6 | 74 | lcd.printf("Mesafe %d cm",mesafe); |
marvas | 0:2988d5981310 | 75 | lcd.printf(" "); |
marvas | 0:2988d5981310 | 76 | } |
marvas | 0:2988d5981310 | 77 | wait_ms(200); // 1 sec |
marvas | 0:2988d5981310 | 78 | |
marvas | 0:2988d5981310 | 79 | } |
marvas | 0:2988d5981310 | 80 | } |
marvas | 0:2988d5981310 | 81 | /* |
marvas | 0:2988d5981310 | 82 | |
marvas | 0:2988d5981310 | 83 | |
marvas | 0:2988d5981310 | 84 | #include "mbed.h" |
marvas | 0:2988d5981310 | 85 | |
marvas | 0:2988d5981310 | 86 | DigitalOut trig(D5); |
marvas | 0:2988d5981310 | 87 | DigitalIn echo(D6); |
marvas | 0:2988d5981310 | 88 | Timer sure; |
marvas | 0:2988d5981310 | 89 | float mesafe; |
marvas | 0:2988d5981310 | 90 | |
marvas | 0:2988d5981310 | 91 | int main() |
marvas | 0:2988d5981310 | 92 | { |
marvas | 0:2988d5981310 | 93 | while(1) |
marvas | 0:2988d5981310 | 94 | { |
marvas | 0:2988d5981310 | 95 | trig=0; |
marvas | 0:2988d5981310 | 96 | wait_us(5); |
marvas | 0:2988d5981310 | 97 | trig=1; |
marvas | 0:2988d5981310 | 98 | wait_us(10); |
marvas | 0:2988d5981310 | 99 | sure.start(); |
marvas | 0:2988d5981310 | 100 | trig=0; |
marvas | 0:2988d5981310 | 101 | while(1) |
marvas | 0:2988d5981310 | 102 | { |
marvas | 0:2988d5981310 | 103 | if(echo==1) |
marvas | 0:2988d5981310 | 104 | { |
marvas | 0:2988d5981310 | 105 | sure.stop(); |
marvas | 0:2988d5981310 | 106 | break; |
marvas | 0:2988d5981310 | 107 | } |
marvas | 0:2988d5981310 | 108 | } |
marvas | 0:2988d5981310 | 109 | mesafe=sure.read()/58.2; |
marvas | 0:2988d5981310 | 110 | printf("%f cm \n",mesafe); |
marvas | 0:2988d5981310 | 111 | sure.reset(); |
marvas | 0:2988d5981310 | 112 | |
marvas | 0:2988d5981310 | 113 | } |
marvas | 0:2988d5981310 | 114 | } |
marvas | 0:2988d5981310 | 115 | */ |