Prueba ascensor Tiempo Real
Dependencies: DebouncedIn Door Elevator HCSR04 mbed-os mbed
main.cpp@0:aa20c789c4c0, 2018-06-07 (annotated)
- Committer:
- Hedizxom
- Date:
- Thu Jun 07 02:14:31 2018 +0000
- Revision:
- 0:aa20c789c4c0
check ascensor;
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
Hedizxom | 0:aa20c789c4c0 | 1 | |
Hedizxom | 0:aa20c789c4c0 | 2 | #include "mbed.h" |
Hedizxom | 0:aa20c789c4c0 | 3 | #include "door.h" |
Hedizxom | 0:aa20c789c4c0 | 4 | #include "elevator.h" |
Hedizxom | 0:aa20c789c4c0 | 5 | #include "hcsr04.h" |
Hedizxom | 0:aa20c789c4c0 | 6 | #include "DebouncedIn.h" |
Hedizxom | 0:aa20c789c4c0 | 7 | |
Hedizxom | 0:aa20c789c4c0 | 8 | #define LEVEL_1 46 |
Hedizxom | 0:aa20c789c4c0 | 9 | #define LEVEL_2 26 |
Hedizxom | 0:aa20c789c4c0 | 10 | #define LEVEL_3 6 |
Hedizxom | 0:aa20c789c4c0 | 11 | #define ID_DOORS 1 |
Hedizxom | 0:aa20c789c4c0 | 12 | #define ID_ELEVATOR 2 |
Hedizxom | 0:aa20c789c4c0 | 13 | |
Hedizxom | 0:aa20c789c4c0 | 14 | Door door_1(PTD2); |
Hedizxom | 0:aa20c789c4c0 | 15 | Door door_2(PTD0); |
Hedizxom | 0:aa20c789c4c0 | 16 | Door door_3(PTD5); |
Hedizxom | 0:aa20c789c4c0 | 17 | |
Hedizxom | 0:aa20c789c4c0 | 18 | Elevator elevator1(PTA12, PTD4, PTA4); |
Hedizxom | 0:aa20c789c4c0 | 19 | |
Hedizxom | 0:aa20c789c4c0 | 20 | HCSR04 sensor(PTD3, PTD1); |
Hedizxom | 0:aa20c789c4c0 | 21 | |
Hedizxom | 0:aa20c789c4c0 | 22 | DigitalIn floor1(PTB2); |
Hedizxom | 0:aa20c789c4c0 | 23 | DigitalIn floor2up(PTB3); |
Hedizxom | 0:aa20c789c4c0 | 24 | DigitalIn floor2down(PTC2); |
Hedizxom | 0:aa20c789c4c0 | 25 | DigitalIn floor3(PTC1); |
Hedizxom | 0:aa20c789c4c0 | 26 | DigitalIn floor1int(PTB1); |
Hedizxom | 0:aa20c789c4c0 | 27 | DigitalIn floor2int(PTB0); |
Hedizxom | 0:aa20c789c4c0 | 28 | DigitalIn floor3int(PTA5); |
Hedizxom | 0:aa20c789c4c0 | 29 | DigitalIn stop(PTC8); |
Hedizxom | 0:aa20c789c4c0 | 30 | DigitalIn open_door(PTA13); |
Hedizxom | 0:aa20c789c4c0 | 31 | DigitalIn close_door(PTC9); |
Hedizxom | 0:aa20c789c4c0 | 32 | |
Hedizxom | 0:aa20c789c4c0 | 33 | |
Hedizxom | 0:aa20c789c4c0 | 34 | Serial pc(PTA2, PTA1); |
Hedizxom | 0:aa20c789c4c0 | 35 | |
Hedizxom | 0:aa20c789c4c0 | 36 | int level_ = LEVEL_1; |
Hedizxom | 0:aa20c789c4c0 | 37 | int pos_sensor = 0, flag = 0; |
Hedizxom | 0:aa20c789c4c0 | 38 | |
Hedizxom | 0:aa20c789c4c0 | 39 | |
Hedizxom | 0:aa20c789c4c0 | 40 | int main() |
Hedizxom | 0:aa20c789c4c0 | 41 | { |
Hedizxom | 0:aa20c789c4c0 | 42 | while(true) |
Hedizxom | 0:aa20c789c4c0 | 43 | { |
Hedizxom | 0:aa20c789c4c0 | 44 | |
Hedizxom | 0:aa20c789c4c0 | 45 | if((floor3 == 0) || (floor3int == 0)) |
Hedizxom | 0:aa20c789c4c0 | 46 | { |
Hedizxom | 0:aa20c789c4c0 | 47 | pc.printf("3"); |
Hedizxom | 0:aa20c789c4c0 | 48 | level_ = LEVEL_3; |
Hedizxom | 0:aa20c789c4c0 | 49 | wait(2); |
Hedizxom | 0:aa20c789c4c0 | 50 | } |
Hedizxom | 0:aa20c789c4c0 | 51 | if(floor2int == 0) |
Hedizxom | 0:aa20c789c4c0 | 52 | { |
Hedizxom | 0:aa20c789c4c0 | 53 | pc.printf("2"); |
Hedizxom | 0:aa20c789c4c0 | 54 | level_ = LEVEL_2; |
Hedizxom | 0:aa20c789c4c0 | 55 | wait(2); |
Hedizxom | 0:aa20c789c4c0 | 56 | } |
Hedizxom | 0:aa20c789c4c0 | 57 | if((floor1 == 0) || (floor1int == 0)) |
Hedizxom | 0:aa20c789c4c0 | 58 | { |
Hedizxom | 0:aa20c789c4c0 | 59 | pc.printf("1"); |
Hedizxom | 0:aa20c789c4c0 | 60 | level_ = LEVEL_1; |
Hedizxom | 0:aa20c789c4c0 | 61 | wait(2); |
Hedizxom | 0:aa20c789c4c0 | 62 | } |
Hedizxom | 0:aa20c789c4c0 | 63 | if(stop == 0) |
Hedizxom | 0:aa20c789c4c0 | 64 | { |
Hedizxom | 0:aa20c789c4c0 | 65 | pc.printf("e"); |
Hedizxom | 0:aa20c789c4c0 | 66 | } |
Hedizxom | 0:aa20c789c4c0 | 67 | if(open_door == 0) |
Hedizxom | 0:aa20c789c4c0 | 68 | { |
Hedizxom | 0:aa20c789c4c0 | 69 | switch(level_) |
Hedizxom | 0:aa20c789c4c0 | 70 | { |
Hedizxom | 0:aa20c789c4c0 | 71 | case LEVEL_1: |
Hedizxom | 0:aa20c789c4c0 | 72 | door_1.open(); |
Hedizxom | 0:aa20c789c4c0 | 73 | break; |
Hedizxom | 0:aa20c789c4c0 | 74 | case LEVEL_2: |
Hedizxom | 0:aa20c789c4c0 | 75 | door_2.open(); |
Hedizxom | 0:aa20c789c4c0 | 76 | break; |
Hedizxom | 0:aa20c789c4c0 | 77 | case LEVEL_3: |
Hedizxom | 0:aa20c789c4c0 | 78 | door_3.open(); |
Hedizxom | 0:aa20c789c4c0 | 79 | break; |
Hedizxom | 0:aa20c789c4c0 | 80 | } |
Hedizxom | 0:aa20c789c4c0 | 81 | wait(2); |
Hedizxom | 0:aa20c789c4c0 | 82 | } |
Hedizxom | 0:aa20c789c4c0 | 83 | |
Hedizxom | 0:aa20c789c4c0 | 84 | if(close_door == 0) |
Hedizxom | 0:aa20c789c4c0 | 85 | { |
Hedizxom | 0:aa20c789c4c0 | 86 | switch(level_) |
Hedizxom | 0:aa20c789c4c0 | 87 | { |
Hedizxom | 0:aa20c789c4c0 | 88 | case LEVEL_1: |
Hedizxom | 0:aa20c789c4c0 | 89 | door_1.close(); |
Hedizxom | 0:aa20c789c4c0 | 90 | break; |
Hedizxom | 0:aa20c789c4c0 | 91 | case LEVEL_2: |
Hedizxom | 0:aa20c789c4c0 | 92 | door_2.close(); |
Hedizxom | 0:aa20c789c4c0 | 93 | break; |
Hedizxom | 0:aa20c789c4c0 | 94 | case LEVEL_3: |
Hedizxom | 0:aa20c789c4c0 | 95 | door_3.close(); |
Hedizxom | 0:aa20c789c4c0 | 96 | break; |
Hedizxom | 0:aa20c789c4c0 | 97 | } |
Hedizxom | 0:aa20c789c4c0 | 98 | wait(2); |
Hedizxom | 0:aa20c789c4c0 | 99 | } |
Hedizxom | 0:aa20c789c4c0 | 100 | while(floor2down == 0) |
Hedizxom | 0:aa20c789c4c0 | 101 | { |
Hedizxom | 0:aa20c789c4c0 | 102 | pc.printf("d"); |
Hedizxom | 0:aa20c789c4c0 | 103 | elevator1.go_down(); |
Hedizxom | 0:aa20c789c4c0 | 104 | flag = 1; |
Hedizxom | 0:aa20c789c4c0 | 105 | } |
Hedizxom | 0:aa20c789c4c0 | 106 | while(floor2up == 0) |
Hedizxom | 0:aa20c789c4c0 | 107 | { |
Hedizxom | 0:aa20c789c4c0 | 108 | pc.printf("u"); |
Hedizxom | 0:aa20c789c4c0 | 109 | elevator1.go_up(); |
Hedizxom | 0:aa20c789c4c0 | 110 | flag = 1; |
Hedizxom | 0:aa20c789c4c0 | 111 | } |
Hedizxom | 0:aa20c789c4c0 | 112 | if(flag == 1) |
Hedizxom | 0:aa20c789c4c0 | 113 | { |
Hedizxom | 0:aa20c789c4c0 | 114 | elevator1.off(); |
Hedizxom | 0:aa20c789c4c0 | 115 | pc.printf("p"); |
Hedizxom | 0:aa20c789c4c0 | 116 | flag = 0; |
Hedizxom | 0:aa20c789c4c0 | 117 | } |
Hedizxom | 0:aa20c789c4c0 | 118 | } |
Hedizxom | 0:aa20c789c4c0 | 119 | } |