tes ir atas semua

Dependencies:   mbed ADS1115 StepperMotor SRF05 TPA81new

Committer:
hisyamfs
Date:
Wed Jan 23 14:44:45 2019 +0000
Revision:
27:4d79aba70fe8
Parent:
26:9c7f39e21df4
Child:
28:528c2fbd6a54
test all tanpa stepper, servo, kompas

Who changed what in which revision?

UserRevisionLine numberNew 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 16:771d84a80e3d 5
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 27:4d79aba70fe8 53 float call_depan(uint16_t x){
hisyamfs 27:4d79aba70fe8 54 float side_distance = a_depan/pow(x,b_depan)+1;
hisyamfs 27:4d79aba70fe8 55 return side_distance;
hisyamfs 27:4d79aba70fe8 56 }
hisyamfs 27:4d79aba70fe8 57
dmgongora 0:79e2a8171b16 58 int main()
hisyamfs 12:1e3227a6fcd7 59 {
hisyamfs 15:da7a15289893 60 //tpax.changeaddress(0xDC,0xDE);
hisyamfs 26:9c7f39e21df4 61 while(sound.read()){}
hisyamfs 26:9c7f39e21df4 62 pc.printf("Sound Detected\n");
hisyamfs 15:da7a15289893 63 while(1) {
hisyamfs 15:da7a15289893 64 pc.printf("%d", tpay.getTemp(0));
hisyamfs 15:da7a15289893 65 int i;
hisyamfs 15:da7a15289893 66 pc.printf("\nTPA Y \n");
hisyamfs 15:da7a15289893 67 tpay.Read();
hisyamfs 15:da7a15289893 68 for (i=2; i<=9; i++) {
hisyamfs 15:da7a15289893 69 pc.printf("%d ",tpay.getTemp(i));
Ezeuz 8:5e1854c119ba 70 }
hisyamfs 15:da7a15289893 71
hisyamfs 15:da7a15289893 72 pc.printf("\nTPA X \n");
hisyamfs 15:da7a15289893 73 tpax.Read();
hisyamfs 15:da7a15289893 74 for (i=2; i<=9; i++) {
hisyamfs 15:da7a15289893 75 pc.printf("%d ",tpax.getTemp(i));
hisyamfs 15:da7a15289893 76 }
hisyamfs 15:da7a15289893 77 pc.printf("\n");
hisyamfs 15:da7a15289893 78
hisyamfs 16:771d84a80e3d 79 pc.printf("us 1: %.2f\tus 2:%.2f\n", srf1.read(), srf2.read());
hisyamfs 17:fd06e8104835 80
hisyamfs 17:fd06e8104835 81 uv.Read();
hisyamfs 17:fd06e8104835 82 int read = uv.Flag;
hisyamfs 17:fd06e8104835 83 if (read) pc.printf("FIRE DETECTED\n");
hisyamfs 17:fd06e8104835 84 else pc.printf("NOT DETECTED\n");
hisyamfs 15:da7a15289893 85 wait(0.5); // 200 ms
hisyamfs 15:da7a15289893 86
hisyamfs 18:f3b23331090f 87 relay = 1;
hisyamfs 21:bfb064f77f88 88 pc.printf("RELAY ON\n");
hisyamfs 18:f3b23331090f 89 wait(0.5);
hisyamfs 18:f3b23331090f 90 relay = 0;
hisyamfs 21:bfb064f77f88 91 pc.printf("RELAY OFF\n");
hisyamfs 21:bfb064f77f88 92
hisyamfs 21:bfb064f77f88 93 pc.printf("Line = %.2f\n", 3300*line.read());
hisyamfs 27:4d79aba70fe8 94
hisyamfs 27:4d79aba70fe8 95 uint16_t raw_a1 = ira1.read_u16();
hisyamfs 27:4d79aba70fe8 96 uint16_t raw_a2 = ira2.read_u16();
hisyamfs 27:4d79aba70fe8 97 uint16_t raw_a3 = ira3.read_u16();
hisyamfs 27:4d79aba70fe8 98 uint16_t raw_a4 = ira4.read_u16();
hisyamfs 27:4d79aba70fe8 99 uint16_t raw_a5 = ira5.read_u16();
hisyamfs 27:4d79aba70fe8 100 uint16_t raw_a6 = ira6.read_u16();
hisyamfs 27:4d79aba70fe8 101 uint16_t raw_a7 = ira7.read_u16();
hisyamfs 27:4d79aba70fe8 102 uint16_t raw_a8 = ira8.read_u16();
hisyamfs 27:4d79aba70fe8 103
hisyamfs 27:4d79aba70fe8 104 uint16_t raw_b1 = irb1.read_u16();
hisyamfs 27:4d79aba70fe8 105 uint16_t raw_b2 = irb2.read_u16();
hisyamfs 27:4d79aba70fe8 106 uint16_t raw_b3 = irb3.read_u16();
hisyamfs 27:4d79aba70fe8 107 uint16_t raw_b4 = irb4.read_u16();
hisyamfs 27:4d79aba70fe8 108
hisyamfs 27:4d79aba70fe8 109 float dist_a1 = call_depan(raw_a1);
hisyamfs 27:4d79aba70fe8 110 float dist_a2 = call_depan(raw_a2);
hisyamfs 27:4d79aba70fe8 111 float dist_a3 = call_depan(raw_a3);
hisyamfs 27:4d79aba70fe8 112 float dist_a4 = call_depan(raw_a4);
hisyamfs 27:4d79aba70fe8 113 float dist_a5 = call_depan(raw_a5);
hisyamfs 27:4d79aba70fe8 114 float dist_a6 = call_depan(raw_a6);
hisyamfs 27:4d79aba70fe8 115 float dist_a7 = call_depan(raw_a7);
hisyamfs 27:4d79aba70fe8 116 float dist_a8 = call_depan(raw_a8);
hisyamfs 27:4d79aba70fe8 117
hisyamfs 27:4d79aba70fe8 118 float dist_b1 = call_depan(raw_b1);
hisyamfs 27:4d79aba70fe8 119 float dist_b2 = call_depan(raw_b2);
hisyamfs 27:4d79aba70fe8 120 float dist_b3 = call_depan(raw_b3);
hisyamfs 27:4d79aba70fe8 121 float dist_b4 = call_depan(raw_b4);
hisyamfs 27:4d79aba70fe8 122
hisyamfs 27:4d79aba70fe8 123 pc.printf("ir atas\n");
hisyamfs 27:4d79aba70fe8 124 pc.printf("%.2f %.2f\n", dist_a2, dist_a1);
hisyamfs 27:4d79aba70fe8 125 pc.printf("%.2f %.2f\n", dist_a3, dist_a7);
hisyamfs 27:4d79aba70fe8 126 pc.printf("%.2f %.2f\n", dist_a4, dist_a8);
hisyamfs 27:4d79aba70fe8 127 pc.printf("%.2f %.2f\n", dist_a6, dist_a5);
hisyamfs 27:4d79aba70fe8 128
hisyamfs 27:4d79aba70fe8 129 pc.printf("ir bawah\n");
hisyamfs 27:4d79aba70fe8 130 pc.printf("%.2f\n", dist_b1);
hisyamfs 27:4d79aba70fe8 131 pc.printf("%.2f %.2f\n", dist_b2, dist_b3);
hisyamfs 27:4d79aba70fe8 132 pc.printf("%.2f\n", dist_b4);
hisyamfs 14:207770fefedf 133 }
hisyamfs 15:da7a15289893 134 }