tes ir atas semua
Dependencies: mbed ADS1115 StepperMotor SRF05 TPA81new
main.cpp@41:71c6f608fd2b, 2019-02-11 (annotated)
- Committer:
- hisyamfs
- Date:
- Mon Feb 11 12:38:54 2019 +0000
- Revision:
- 41:71c6f608fd2b
- Parent:
- 40:1c29f33d54d7
- Child:
- 42:3b682b7d0388
last
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
hisyamfs | 12:1e3227a6fcd7 | 1 | #include "mbed.h" |
hisyamfs | 12:1e3227a6fcd7 | 2 | #include "TPA81new.h" |
hisyamfs | 16:771d84a80e3d | 3 | #include "SRF05.h" |
hisyamfs | 19:9a7b34bedc6c | 4 | #include "Uvtron.h" |
hisyamfs | 41:71c6f608fd2b | 5 | #include "Stepper.h" |
hisyamfs | 16:771d84a80e3d | 6 | #define LCD_D4_DIG PA_15 |
hisyamfs | 16:771d84a80e3d | 7 | #define LCD_D5_DIG PA_14 |
hisyamfs | 16:771d84a80e3d | 8 | #define LCD_E_DIG PC_15 |
hisyamfs | 16:771d84a80e3d | 9 | #define LCD_RS_DIG PB_7 |
hisyamfs | 14:207770fefedf | 10 | |
hisyamfs | 15:da7a15289893 | 11 | Serial pc(USBTX,USBRX); |
hisyamfs | 17:fd06e8104835 | 12 | |
hisyamfs | 17:fd06e8104835 | 13 | // TPA |
hisyamfs | 15:da7a15289893 | 14 | TPA81 tpax(PB_9, PB_8, 0xDC); |
hisyamfs | 26:9c7f39e21df4 | 15 | TPA81 tpay(PB_9, PB_8, 0xDE); |
dmgongora | 0:79e2a8171b16 | 16 | |
hisyamfs | 17:fd06e8104835 | 17 | // Ultrasonik |
hisyamfs | 25:a75d6875cb55 | 18 | //SRF05 srf1(PC_13, PA_14); // trigger, echo |
hisyamfs | 25:a75d6875cb55 | 19 | //SRF05 srf1(PA_11, PB_12); |
hisyamfs | 25:a75d6875cb55 | 20 | //SRF05 srf1(PB_12, PA_11); |
hisyamfs | 25:a75d6875cb55 | 21 | SRF05 srf1(PB_3, PB_10); |
hisyamfs | 16:771d84a80e3d | 22 | SRF05 srf2(PA_15, PB_7); // trigger, echo |
hisyamfs | 16:771d84a80e3d | 23 | |
hisyamfs | 18:f3b23331090f | 24 | DigitalOut relay(PB_2); |
hisyamfs | 18:f3b23331090f | 25 | |
hisyamfs | 17:fd06e8104835 | 26 | // UVTron |
hisyamfs | 17:fd06e8104835 | 27 | Uvtron uv(PC_12); |
hisyamfs | 17:fd06e8104835 | 28 | |
hisyamfs | 19:9a7b34bedc6c | 29 | // Sound |
hisyamfs | 26:9c7f39e21df4 | 30 | DigitalIn sound(PA_9); |
hisyamfs | 19:9a7b34bedc6c | 31 | |
hisyamfs | 21:bfb064f77f88 | 32 | // Line |
hisyamfs | 21:bfb064f77f88 | 33 | AnalogIn line(PC_1); |
hisyamfs | 21:bfb064f77f88 | 34 | |
hisyamfs | 27:4d79aba70fe8 | 35 | // infrared |
hisyamfs | 27:4d79aba70fe8 | 36 | #define a_depan 5000000 |
hisyamfs | 27:4d79aba70fe8 | 37 | #define b_depan 1.229 |
hisyamfs | 27:4d79aba70fe8 | 38 | // atas |
hisyamfs | 27:4d79aba70fe8 | 39 | AnalogIn ira1(PC_5); |
hisyamfs | 27:4d79aba70fe8 | 40 | AnalogIn ira2(PA_5); |
hisyamfs | 27:4d79aba70fe8 | 41 | AnalogIn ira3(PC_2); |
hisyamfs | 27:4d79aba70fe8 | 42 | AnalogIn ira4(PC_3); |
hisyamfs | 27:4d79aba70fe8 | 43 | AnalogIn ira5(PB_1); |
hisyamfs | 27:4d79aba70fe8 | 44 | AnalogIn ira6(PC_4); |
hisyamfs | 27:4d79aba70fe8 | 45 | AnalogIn ira7(PA_6); |
hisyamfs | 27:4d79aba70fe8 | 46 | AnalogIn ira8(PA_7); |
hisyamfs | 27:4d79aba70fe8 | 47 | // bawah |
hisyamfs | 27:4d79aba70fe8 | 48 | AnalogIn irb1(PA_0); |
hisyamfs | 27:4d79aba70fe8 | 49 | AnalogIn irb2(PA_1); |
hisyamfs | 27:4d79aba70fe8 | 50 | AnalogIn irb3(PA_4); |
hisyamfs | 27:4d79aba70fe8 | 51 | AnalogIn irb4(PB_0); |
hisyamfs | 27:4d79aba70fe8 | 52 | |
hisyamfs | 40:1c29f33d54d7 | 53 | #define WAIT_TIME 0.02 |
hisyamfs | 40:1c29f33d54d7 | 54 | |
hisyamfs | 40:1c29f33d54d7 | 55 | // stepper(PinName _en, PinName ms1, PinName ms2, PinName ms3, PinName _stepPin, PinName dir); |
hisyamfs | 40:1c29f33d54d7 | 56 | stepper s(PC_6, PC_8, PA_12, PC_7, PA_11, PB_12); |
hisyamfs | 40:1c29f33d54d7 | 57 | |
hisyamfs | 41:71c6f608fd2b | 58 | DigitalOut led_api(PC_14); |
hisyamfs | 37:f0b535131cbf | 59 | DigitalOut led_sound(PH_1); |
hisyamfs | 37:f0b535131cbf | 60 | |
hisyamfs | 27:4d79aba70fe8 | 61 | float call_depan(uint16_t x){ |
hisyamfs | 27:4d79aba70fe8 | 62 | float side_distance = a_depan/pow(x,b_depan)+1; |
hisyamfs | 27:4d79aba70fe8 | 63 | return side_distance; |
hisyamfs | 27:4d79aba70fe8 | 64 | } |
hisyamfs | 27:4d79aba70fe8 | 65 | |
dmgongora | 0:79e2a8171b16 | 66 | int main() |
hisyamfs | 12:1e3227a6fcd7 | 67 | { |
hisyamfs | 15:da7a15289893 | 68 | //tpax.changeaddress(0xDC,0xDE); |
hisyamfs | 41:71c6f608fd2b | 69 | relay = 1; |
hisyamfs | 37:f0b535131cbf | 70 | // while(sound.read()){} |
hisyamfs | 37:f0b535131cbf | 71 | led_api = 0; |
hisyamfs | 37:f0b535131cbf | 72 | led_sound = 0; |
hisyamfs | 26:9c7f39e21df4 | 73 | pc.printf("Sound Detected\n"); |
hisyamfs | 15:da7a15289893 | 74 | while(1) { |
hisyamfs | 15:da7a15289893 | 75 | pc.printf("%d", tpay.getTemp(0)); |
hisyamfs | 15:da7a15289893 | 76 | int i; |
hisyamfs | 15:da7a15289893 | 77 | pc.printf("\nTPA Y \n"); |
hisyamfs | 15:da7a15289893 | 78 | tpay.Read(); |
hisyamfs | 15:da7a15289893 | 79 | for (i=2; i<=9; i++) { |
hisyamfs | 15:da7a15289893 | 80 | pc.printf("%d ",tpay.getTemp(i)); |
Ezeuz | 8:5e1854c119ba | 81 | } |
hisyamfs | 15:da7a15289893 | 82 | |
hisyamfs | 15:da7a15289893 | 83 | pc.printf("\nTPA X \n"); |
hisyamfs | 15:da7a15289893 | 84 | tpax.Read(); |
hisyamfs | 15:da7a15289893 | 85 | for (i=2; i<=9; i++) { |
hisyamfs | 15:da7a15289893 | 86 | pc.printf("%d ",tpax.getTemp(i)); |
hisyamfs | 15:da7a15289893 | 87 | } |
hisyamfs | 15:da7a15289893 | 88 | pc.printf("\n"); |
hisyamfs | 15:da7a15289893 | 89 | |
hisyamfs | 16:771d84a80e3d | 90 | pc.printf("us 1: %.2f\tus 2:%.2f\n", srf1.read(), srf2.read()); |
hisyamfs | 17:fd06e8104835 | 91 | |
hisyamfs | 17:fd06e8104835 | 92 | uv.Read(); |
hisyamfs | 17:fd06e8104835 | 93 | int read = uv.Flag; |
hisyamfs | 17:fd06e8104835 | 94 | if (read) pc.printf("FIRE DETECTED\n"); |
hisyamfs | 17:fd06e8104835 | 95 | else pc.printf("NOT DETECTED\n"); |
hisyamfs | 15:da7a15289893 | 96 | wait(0.5); // 200 ms |
hisyamfs | 15:da7a15289893 | 97 | |
hisyamfs | 41:71c6f608fd2b | 98 | relay = 0; |
hisyamfs | 21:bfb064f77f88 | 99 | pc.printf("RELAY ON\n"); |
hisyamfs | 18:f3b23331090f | 100 | wait(0.5); |
hisyamfs | 41:71c6f608fd2b | 101 | relay = 1; |
hisyamfs | 21:bfb064f77f88 | 102 | pc.printf("RELAY OFF\n"); |
hisyamfs | 21:bfb064f77f88 | 103 | |
hisyamfs | 21:bfb064f77f88 | 104 | pc.printf("Line = %.2f\n", 3300*line.read()); |
hisyamfs | 27:4d79aba70fe8 | 105 | |
hisyamfs | 27:4d79aba70fe8 | 106 | uint16_t raw_a1 = ira1.read_u16(); |
hisyamfs | 27:4d79aba70fe8 | 107 | uint16_t raw_a2 = ira2.read_u16(); |
hisyamfs | 27:4d79aba70fe8 | 108 | uint16_t raw_a3 = ira3.read_u16(); |
hisyamfs | 27:4d79aba70fe8 | 109 | uint16_t raw_a4 = ira4.read_u16(); |
hisyamfs | 27:4d79aba70fe8 | 110 | uint16_t raw_a5 = ira5.read_u16(); |
hisyamfs | 27:4d79aba70fe8 | 111 | uint16_t raw_a6 = ira6.read_u16(); |
hisyamfs | 27:4d79aba70fe8 | 112 | uint16_t raw_a7 = ira7.read_u16(); |
hisyamfs | 27:4d79aba70fe8 | 113 | uint16_t raw_a8 = ira8.read_u16(); |
hisyamfs | 27:4d79aba70fe8 | 114 | |
hisyamfs | 27:4d79aba70fe8 | 115 | uint16_t raw_b1 = irb1.read_u16(); |
hisyamfs | 27:4d79aba70fe8 | 116 | uint16_t raw_b2 = irb2.read_u16(); |
hisyamfs | 27:4d79aba70fe8 | 117 | uint16_t raw_b3 = irb3.read_u16(); |
hisyamfs | 27:4d79aba70fe8 | 118 | uint16_t raw_b4 = irb4.read_u16(); |
hisyamfs | 27:4d79aba70fe8 | 119 | |
hisyamfs | 27:4d79aba70fe8 | 120 | float dist_a1 = call_depan(raw_a1); |
hisyamfs | 27:4d79aba70fe8 | 121 | float dist_a2 = call_depan(raw_a2); |
hisyamfs | 27:4d79aba70fe8 | 122 | float dist_a3 = call_depan(raw_a3); |
hisyamfs | 27:4d79aba70fe8 | 123 | float dist_a4 = call_depan(raw_a4); |
hisyamfs | 27:4d79aba70fe8 | 124 | float dist_a5 = call_depan(raw_a5); |
hisyamfs | 27:4d79aba70fe8 | 125 | float dist_a6 = call_depan(raw_a6); |
hisyamfs | 27:4d79aba70fe8 | 126 | float dist_a7 = call_depan(raw_a7); |
hisyamfs | 27:4d79aba70fe8 | 127 | float dist_a8 = call_depan(raw_a8); |
hisyamfs | 27:4d79aba70fe8 | 128 | |
hisyamfs | 27:4d79aba70fe8 | 129 | float dist_b1 = call_depan(raw_b1); |
hisyamfs | 27:4d79aba70fe8 | 130 | float dist_b2 = call_depan(raw_b2); |
hisyamfs | 27:4d79aba70fe8 | 131 | float dist_b3 = call_depan(raw_b3); |
hisyamfs | 27:4d79aba70fe8 | 132 | float dist_b4 = call_depan(raw_b4); |
hisyamfs | 27:4d79aba70fe8 | 133 | |
hisyamfs | 27:4d79aba70fe8 | 134 | pc.printf("ir atas\n"); |
hisyamfs | 28:528c2fbd6a54 | 135 | pc.printf(" %.2f %.2f\n", dist_a2, dist_a1); |
hisyamfs | 28:528c2fbd6a54 | 136 | pc.printf("%.2f %.2f\n", dist_a3, dist_a7); |
hisyamfs | 28:528c2fbd6a54 | 137 | pc.printf("%.2f %.2f\n", dist_a4, dist_a8); |
hisyamfs | 28:528c2fbd6a54 | 138 | pc.printf(" %.2f %.2f\n", dist_a6, dist_a5); |
hisyamfs | 27:4d79aba70fe8 | 139 | |
hisyamfs | 27:4d79aba70fe8 | 140 | pc.printf("ir bawah\n"); |
hisyamfs | 28:528c2fbd6a54 | 141 | pc.printf(" %.2f\n", dist_b1); |
hisyamfs | 28:528c2fbd6a54 | 142 | pc.printf("%.2f %.2f\n", dist_b2, dist_b3); |
hisyamfs | 28:528c2fbd6a54 | 143 | pc.printf(" %.2f\n", dist_b4); |
hisyamfs | 37:f0b535131cbf | 144 | |
hisyamfs | 37:f0b535131cbf | 145 | wait(1); |
hisyamfs | 37:f0b535131cbf | 146 | |
hisyamfs | 40:1c29f33d54d7 | 147 | pc.printf("Stepper \n"); |
hisyamfs | 40:1c29f33d54d7 | 148 | for (int i = 0; i < 200; i++) { |
hisyamfs | 40:1c29f33d54d7 | 149 | s.step(1, 1, 1/WAIT_TIME); |
hisyamfs | 40:1c29f33d54d7 | 150 | // pc.printf("%d\n", i); |
hisyamfs | 40:1c29f33d54d7 | 151 | } |
hisyamfs | 40:1c29f33d54d7 | 152 | |
hisyamfs | 37:f0b535131cbf | 153 | led_api = 1; |
hisyamfs | 38:fea0806e214a | 154 | pc.printf("led api on\n"); |
hisyamfs | 39:1c067e2e2820 | 155 | wait(0.5); |
hisyamfs | 37:f0b535131cbf | 156 | led_api = 0; |
hisyamfs | 38:fea0806e214a | 157 | pc.printf("led api off\n"); |
hisyamfs | 37:f0b535131cbf | 158 | |
hisyamfs | 37:f0b535131cbf | 159 | led_sound = 1; |
hisyamfs | 38:fea0806e214a | 160 | pc.printf("led sound on\n"); |
hisyamfs | 39:1c067e2e2820 | 161 | wait(0.5); |
hisyamfs | 37:f0b535131cbf | 162 | led_sound = 0; |
hisyamfs | 38:fea0806e214a | 163 | pc.printf("led sound off\n"); |
hisyamfs | 38:fea0806e214a | 164 | wait(0.5); |
hisyamfs | 37:f0b535131cbf | 165 | pc.printf("\033[2J\033[H"); |
hisyamfs | 14:207770fefedf | 166 | } |
hisyamfs | 15:da7a15289893 | 167 | } |