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