Alyson Castiblanco
/
PARQUEADERO_VERTICAL
Codigo donde falta la comunicacion serial
princilap.cpp@5:342e6640b61e, 2018-11-22 (annotated)
- Committer:
- acastiblancoc
- Date:
- Thu Nov 22 09:48:47 2018 +0000
- Revision:
- 5:342e6640b61e
Codigo parqueadero
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
acastiblancoc | 5:342e6640b61e | 1 | #include "mbed.h" |
acastiblancoc | 5:342e6640b61e | 2 | Serial pc(SERIAL_TX, SERIAL_RX); |
acastiblancoc | 5:342e6640b61e | 3 | AnalogIn sensoras1(A0); |
acastiblancoc | 5:342e6640b61e | 4 | AnalogIn sensoras2(A1); |
acastiblancoc | 5:342e6640b61e | 5 | AnalogIn sensoras3(A2); |
acastiblancoc | 5:342e6640b61e | 6 | DigitalIn sensorc1(D15); |
acastiblancoc | 5:342e6640b61e | 7 | DigitalIn sensorc2(D14); |
acastiblancoc | 5:342e6640b61e | 8 | DigitalIn sensorc3(D13); |
acastiblancoc | 5:342e6640b61e | 9 | DigitalIn sensorc4(D12); |
acastiblancoc | 5:342e6640b61e | 10 | DigitalIn sensorc5(D11); |
acastiblancoc | 5:342e6640b61e | 11 | DigitalIn sensorc6(D10); |
acastiblancoc | 5:342e6640b61e | 12 | BusOut myleds(LED1, LED2, LED3, LED4); |
acastiblancoc | 5:342e6640b61e | 13 | BusOut motor(D4, D5, D6, D7); |
acastiblancoc | 5:342e6640b61e | 14 | |
acastiblancoc | 5:342e6640b61e | 15 | int tiempo = 12000; |
acastiblancoc | 5:342e6640b61e | 16 | void ADCC() |
acastiblancoc | 5:342e6640b61e | 17 | { |
acastiblancoc | 5:342e6640b61e | 18 | float s1=sensoras1.read(); |
acastiblancoc | 5:342e6640b61e | 19 | float s2=sensoras2.read(); |
acastiblancoc | 5:342e6640b61e | 20 | float s3=sensoras3.read(); |
acastiblancoc | 5:342e6640b61e | 21 | /*printf("sensor 1 = %f\n", s1); |
acastiblancoc | 5:342e6640b61e | 22 | printf("sensor 2 = %f\n", s2); |
acastiblancoc | 5:342e6640b61e | 23 | printf("sensor 3 = %f\n", s3);*/ |
acastiblancoc | 5:342e6640b61e | 24 | if(s1>0.8 && s2<0.1 && s3>0.8) |
acastiblancoc | 5:342e6640b61e | 25 | printf("piso 1\n"); |
acastiblancoc | 5:342e6640b61e | 26 | if(s1<0.1 && s2>0.8 && s3<0.1) |
acastiblancoc | 5:342e6640b61e | 27 | printf("piso 2\n"); |
acastiblancoc | 5:342e6640b61e | 28 | if(s1>0.8 && s2<0.1 && s3<0.1) |
acastiblancoc | 5:342e6640b61e | 29 | printf("piso 3\n"); |
acastiblancoc | 5:342e6640b61e | 30 | if(s1<0.1 && s2<0.1 && s3>0.8) |
acastiblancoc | 5:342e6640b61e | 31 | printf("piso 4\n"); |
acastiblancoc | 5:342e6640b61e | 32 | if(s1<0.1 && s2>0.8 && s3>0.8) |
acastiblancoc | 5:342e6640b61e | 33 | printf("piso 5\n"); |
acastiblancoc | 5:342e6640b61e | 34 | if(s1>0.8 && s2>0.8 && s3<0.1) |
acastiblancoc | 5:342e6640b61e | 35 | printf("piso 6\n"); |
acastiblancoc | 5:342e6640b61e | 36 | else |
acastiblancoc | 5:342e6640b61e | 37 | printf("no piso\n"); |
acastiblancoc | 5:342e6640b61e | 38 | } |
acastiblancoc | 5:342e6640b61e | 39 | |
acastiblancoc | 5:342e6640b61e | 40 | void carro1() |
acastiblancoc | 5:342e6640b61e | 41 | {int c=sensorc1.read(); |
acastiblancoc | 5:342e6640b61e | 42 | //printf("sensor piso 1 = %i\n", c); |
acastiblancoc | 5:342e6640b61e | 43 | if(c==1) |
acastiblancoc | 5:342e6640b61e | 44 | printf("Hay carro en piso 1 \n"); |
acastiblancoc | 5:342e6640b61e | 45 | } |
acastiblancoc | 5:342e6640b61e | 46 | void carro2() |
acastiblancoc | 5:342e6640b61e | 47 | {int c1=sensorc2.read(); |
acastiblancoc | 5:342e6640b61e | 48 | //printf("sensor piso 1 = %i\n", c); |
acastiblancoc | 5:342e6640b61e | 49 | if(c1==1) |
acastiblancoc | 5:342e6640b61e | 50 | printf("Hay carro en piso 2 \n"); |
acastiblancoc | 5:342e6640b61e | 51 | } |
acastiblancoc | 5:342e6640b61e | 52 | void carro3() |
acastiblancoc | 5:342e6640b61e | 53 | {int c2=sensorc3.read(); |
acastiblancoc | 5:342e6640b61e | 54 | //printf("sensor piso 1 = %i\n", c); |
acastiblancoc | 5:342e6640b61e | 55 | if(c2==1) |
acastiblancoc | 5:342e6640b61e | 56 | printf("Hay carro en piso 3 \n"); |
acastiblancoc | 5:342e6640b61e | 57 | } |
acastiblancoc | 5:342e6640b61e | 58 | void carro4() |
acastiblancoc | 5:342e6640b61e | 59 | {int c3=sensorc4.read(); |
acastiblancoc | 5:342e6640b61e | 60 | //printf("sensor piso 1 = %i\n", c); |
acastiblancoc | 5:342e6640b61e | 61 | if(c3==1) |
acastiblancoc | 5:342e6640b61e | 62 | printf("Hay carro en piso 4 \n"); |
acastiblancoc | 5:342e6640b61e | 63 | } |
acastiblancoc | 5:342e6640b61e | 64 | void carro5() |
acastiblancoc | 5:342e6640b61e | 65 | {int c4=sensorc5.read(); |
acastiblancoc | 5:342e6640b61e | 66 | //printf("sensor piso 1 = %i\n", c); |
acastiblancoc | 5:342e6640b61e | 67 | if(c4==1) |
acastiblancoc | 5:342e6640b61e | 68 | printf("Hay carro en piso 1 \n"); |
acastiblancoc | 5:342e6640b61e | 69 | } |
acastiblancoc | 5:342e6640b61e | 70 | void carro6() |
acastiblancoc | 5:342e6640b61e | 71 | {int c5=sensorc6.read(); |
acastiblancoc | 5:342e6640b61e | 72 | //printf("sensor piso 1 = %i\n", c); |
acastiblancoc | 5:342e6640b61e | 73 | if(c5==1) |
acastiblancoc | 5:342e6640b61e | 74 | printf("Hay carro en piso 1 \n"); |
acastiblancoc | 5:342e6640b61e | 75 | } |
acastiblancoc | 5:342e6640b61e | 76 | void detectarcarro() |
acastiblancoc | 5:342e6640b61e | 77 | { |
acastiblancoc | 5:342e6640b61e | 78 | //int c=sensorc.read(); |
acastiblancoc | 5:342e6640b61e | 79 | //printf("sensor piso 1 = %i\n", c); |
acastiblancoc | 5:342e6640b61e | 80 | /*if(c==1) |
acastiblancoc | 5:342e6640b61e | 81 | printf("Hay carro en piso 1 \n");*/ |
acastiblancoc | 5:342e6640b61e | 82 | carro1(); |
acastiblancoc | 5:342e6640b61e | 83 | wait_ms(200); |
acastiblancoc | 5:342e6640b61e | 84 | carro2(); |
acastiblancoc | 5:342e6640b61e | 85 | wait_ms(200); |
acastiblancoc | 5:342e6640b61e | 86 | carro3(); |
acastiblancoc | 5:342e6640b61e | 87 | wait_ms(200); |
acastiblancoc | 5:342e6640b61e | 88 | carro4(); |
acastiblancoc | 5:342e6640b61e | 89 | wait_ms(200); |
acastiblancoc | 5:342e6640b61e | 90 | carro5(); |
acastiblancoc | 5:342e6640b61e | 91 | wait_ms(200); |
acastiblancoc | 5:342e6640b61e | 92 | carro6(); |
acastiblancoc | 5:342e6640b61e | 93 | wait_ms(200); |
acastiblancoc | 5:342e6640b61e | 94 | } |
acastiblancoc | 5:342e6640b61e | 95 | |
acastiblancoc | 5:342e6640b61e | 96 | void pasoapaso() |
acastiblancoc | 5:342e6640b61e | 97 | { |
acastiblancoc | 5:342e6640b61e | 98 | for (int s = 0; s < 120 ; s +=1) { |
acastiblancoc | 5:342e6640b61e | 99 | motor = (0xA); //1010 |
acastiblancoc | 5:342e6640b61e | 100 | wait_us(tiempo); |
acastiblancoc | 5:342e6640b61e | 101 | motor = (0x6);//0110 |
acastiblancoc | 5:342e6640b61e | 102 | wait_us(tiempo); |
acastiblancoc | 5:342e6640b61e | 103 | motor = (0x5);//0101 |
acastiblancoc | 5:342e6640b61e | 104 | wait_us(tiempo); |
acastiblancoc | 5:342e6640b61e | 105 | motor = (0x9);//1001 |
acastiblancoc | 5:342e6640b61e | 106 | wait_us(tiempo); |
acastiblancoc | 5:342e6640b61e | 107 | } |
acastiblancoc | 5:342e6640b61e | 108 | wait(2); |
acastiblancoc | 5:342e6640b61e | 109 | for (int s = 0; s < 120 ; s +=1) {//ahora en sentido contrario |
acastiblancoc | 5:342e6640b61e | 110 | motor = (0x9);//1001 |
acastiblancoc | 5:342e6640b61e | 111 | wait_us(tiempo); |
acastiblancoc | 5:342e6640b61e | 112 | motor = (0x5);//0101 |
acastiblancoc | 5:342e6640b61e | 113 | wait_us(tiempo); |
acastiblancoc | 5:342e6640b61e | 114 | motor = (0x6);//0110 |
acastiblancoc | 5:342e6640b61e | 115 | wait_us(tiempo); |
acastiblancoc | 5:342e6640b61e | 116 | motor = (0xA);//1010 |
acastiblancoc | 5:342e6640b61e | 117 | wait_us(tiempo); |
acastiblancoc | 5:342e6640b61e | 118 | } |
acastiblancoc | 5:342e6640b61e | 119 | wait(2); |
acastiblancoc | 5:342e6640b61e | 120 | } |
acastiblancoc | 5:342e6640b61e | 121 | |
acastiblancoc | 5:342e6640b61e | 122 | int main() { |
acastiblancoc | 5:342e6640b61e | 123 | |
acastiblancoc | 5:342e6640b61e | 124 | while(1) { |
acastiblancoc | 5:342e6640b61e | 125 | //ADCC(); |
acastiblancoc | 5:342e6640b61e | 126 | detectarcarro(); |
acastiblancoc | 5:342e6640b61e | 127 | //wait(0.5); |
acastiblancoc | 5:342e6640b61e | 128 | //pasoapaso(); |
acastiblancoc | 5:342e6640b61e | 129 | } |
acastiblancoc | 5:342e6640b61e | 130 | } |