prog
Dependencies: mbed Servo mbed-rtos beep hcsr04 TextLCD
main.cpp@1:13556d8b4a34, 2019-03-26 (annotated)
- Committer:
- altoimperatore
- Date:
- Tue Mar 26 11:09:02 2019 +0000
- Revision:
- 1:13556d8b4a34
- Parent:
- 0:650a24681467
- Child:
- 2:33e2a092cab6
progetto
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
huntR | 0:650a24681467 | 1 | #include "mbed.h" |
huntR | 0:650a24681467 | 2 | #include "rtos.h" |
huntR | 0:650a24681467 | 3 | #include "hcsr04.h" |
huntR | 0:650a24681467 | 4 | #include "beep.h" |
huntR | 0:650a24681467 | 5 | /******************************/ |
huntR | 0:650a24681467 | 6 | //bluetooth |
huntR | 0:650a24681467 | 7 | Serial blue(D10,D2);//tx e rx |
huntR | 0:650a24681467 | 8 | /******************************/ |
huntR | 0:650a24681467 | 9 | //sensori ad ultrasuoni |
altoimperatore | 1:13556d8b4a34 | 10 | HCSR04 sensor1(D15, D14); //istanza oggetti "sensori" |
huntR | 0:650a24681467 | 11 | HCSR04 sensor2(D12, D13); |
huntR | 0:650a24681467 | 12 | HCSR04 sensor3(D11, D9); |
huntR | 0:650a24681467 | 13 | /******************************/ |
huntR | 0:650a24681467 | 14 | //dichiarazioni led |
huntR | 0:650a24681467 | 15 | //Led per le macchine |
altoimperatore | 1:13556d8b4a34 | 16 | DigitalOut rossoC(PA_0); //istanza oggetti "led" |
huntR | 0:650a24681467 | 17 | DigitalOut gialloC(D5); |
huntR | 0:650a24681467 | 18 | DigitalOut verdeC(D3); |
huntR | 0:650a24681467 | 19 | /******************************/ |
huntR | 0:650a24681467 | 20 | //led per i pedoni |
altoimperatore | 1:13556d8b4a34 | 21 | DigitalOut rossoP(D6); //istanza oggetti "led specifici per i pedoni" |
huntR | 0:650a24681467 | 22 | DigitalOut gialloP(D7); |
huntR | 0:650a24681467 | 23 | DigitalOut verdeP(D8); |
huntR | 0:650a24681467 | 24 | /******************************/ |
huntR | 0:650a24681467 | 25 | //buzzer |
altoimperatore | 1:13556d8b4a34 | 26 | Beep buzzer(D4); //istanza oggetti "buzzer" |
huntR | 0:650a24681467 | 27 | /******************************/ |
huntR | 0:650a24681467 | 28 | /******************************/ |
altoimperatore | 1:13556d8b4a34 | 29 | |
altoimperatore | 1:13556d8b4a34 | 30 | Thread thread_sensori; // istanzia oggetto thread |
altoimperatore | 1:13556d8b4a34 | 31 | |
altoimperatore | 1:13556d8b4a34 | 32 | bool occupata = false; |
huntR | 0:650a24681467 | 33 | /******************************/ |
huntR | 0:650a24681467 | 34 | |
huntR | 0:650a24681467 | 35 | //sensore semaforo 1 |
huntR | 0:650a24681467 | 36 | /******************************/ |
huntR | 0:650a24681467 | 37 | void sensori(){ |
huntR | 0:650a24681467 | 38 | sensor1.start(); |
huntR | 0:650a24681467 | 39 | wait_ms(100); |
altoimperatore | 1:13556d8b4a34 | 40 | sensor2.start(); //partono i sensori |
huntR | 0:650a24681467 | 41 | wait_ms(100); |
altoimperatore | 1:13556d8b4a34 | 42 | if(sensor1.get_dist_cm() < 5 && occupata[0] = false){ //se uno dei sensori capta una distanza minore 10 |
altoimperatore | 1:13556d8b4a34 | 43 | occupata[0] = true; |
altoimperatore | 1:13556d8b4a34 | 44 | else |
altoimperatore | 1:13556d8b4a34 | 45 | occupata[0] = false; |
altoimperatore | 1:13556d8b4a34 | 46 | if(sensor2.get_dist_cm() < 5 && occupata[1] = false){ //se uno dei sensori capta una distanza minore a 10 e gianello è false |
altoimperatore | 1:13556d8b4a34 | 47 | occupata[1] = true; |
altoimperatore | 1:13556d8b4a34 | 48 | else |
altoimperatore | 1:13556d8b4a34 | 49 | occupata[1] = false; |
huntR | 0:650a24681467 | 50 | } |
altoimperatore | 1:13556d8b4a34 | 51 | |
huntR | 0:650a24681467 | 52 | int main(){ |
altoimperatore | 1:13556d8b4a34 | 53 | int i; |
altoimperatore | 1:13556d8b4a34 | 54 | while(true) { |
altoimperatore | 1:13556d8b4a34 | 55 | //if (mybutton) { |
altoimperatore | 1:13556d8b4a34 | 56 | for (int i = 0; i < 2; i++) |
altoimperatore | 1:13556d8b4a34 | 57 | pc.printf("%d", occupata[i]); |
altoimperatore | 1:13556d8b4a34 | 58 | |
altoimperatore | 1:13556d8b4a34 | 59 | |
altoimperatore | 1:13556d8b4a34 | 60 | |
altoimperatore | 1:13556d8b4a34 | 61 | |
altoimperatore | 1:13556d8b4a34 | 62 | |
altoimperatore | 1:13556d8b4a34 | 63 | |
huntR | 0:650a24681467 | 64 | } |
altoimperatore | 1:13556d8b4a34 | 65 | |
altoimperatore | 1:13556d8b4a34 | 66 | |
altoimperatore | 1:13556d8b4a34 | 67 | void thread_sensori() { |
altoimperatore | 1:13556d8b4a34 | 68 | |
huntR | 0:650a24681467 | 69 | } |