tes ir atas semua

Dependencies:   mbed ADS1115 StepperMotor SRF05 TPA81new

Revision:
49:d23d76689933
Parent:
48:c8c9c624d46d
--- a/main.cpp	Tue Mar 05 13:17:16 2019 +0000
+++ b/main.cpp	Wed Mar 06 13:17:10 2019 +0000
@@ -7,14 +7,15 @@
 #include "Adafruit_ADS1015.h"
 
 // Konstanta
-#define WAIT_TIME 0.05
+#define WAIT_TIME 0.02
 // infrared
 #define a_depan 5000000
 #define b_depan 1.229
 #define a_ads 500000
 #define b_ads 1.184
+#define I2C_ADDR 0xC0
 
-Serial pc(USBTX,USBRX);
+Serial pc(USBTX,USBRX, 115200);
 
 // AMG
 Adafruit_AMG88xx amg(PB_3, PB_10); // sda, scl
@@ -44,8 +45,14 @@
 I2C ads_i2c(PB_9, PB_8); // sda, scl
 Adafruit_ADS1015 ads(&ads_i2c);
 
+// kompas
+I2C cmps12(PB_4, PA_8); //sda, scl
+
+// stepper(PinName _en, PinName ms1, PinName ms2, PinName ms3, PinName _stepPin, PinName dir);
 stepper s(PC_8, PC_6, PA_12, PA_11, PB_12, PC_7);
-// stepper(PinName _en, PinName ms1, PinName ms2, PinName ms3, PinName _stepPin, PinName dir);
+
+// sound
+//DigitalIn sound(PA_9);
 
 DigitalOut led_api(PB_6);
 DigitalOut led_sound(PH_1);
@@ -66,7 +73,20 @@
 int main()
 {
     uint16_t ads_raw[4] = {};
+    int status = amg.begin(AMG88xx_ADDRESS);
+    amg.setMovingAverageMode(1);
+    if (!status) {
+        pc.printf("Could not find a valid AMG88xx sensor, check wiring! \n");
+        while (1);
+    }
+    relay = 1;
+    wait_ms(100);
+    while (sound.read() == 1){
+        wait_ms(100);    
+    };
+    pc.printf("Sound detected\n");
     while (1) {
+        led_sound = 1;
         // IR
         for (uint8_t i=0; i < 4; i++) {
             ads_raw[i] = ads.readADC_SingleEnded(i);
@@ -113,8 +133,60 @@
         pc.printf("      %.2f\n", dist_b1);
         pc.printf("%.2f            %.2f\n", dist_b2, dist_b3);
         pc.printf("      %.2f\n", dist_b4);
-
+        
+        // baca amg
+        float therm_temp = amg.readThermistor();
+        amg.readPixels(pixels);
+        pc.printf("%.2f\n", therm_temp);
+        float max_temp = pixels[0];
+        int max_i = 0;
+        float sum_temp = 0;
+        for (int i = 1; i <= AMG88xx_PIXEL_ARRAY_SIZE; i++) {
+//            pc.printf("%.2f ", pixels[i-1]);   
+//            if (i % 8 == 0) pc.printf("\n");
+            if (pixels[i-1] > max_temp) {
+                max_temp = pixels[i-1];
+                max_i = i;
+            }
+            sum_temp += pixels[i-1];
+        }
+        
+        // uvtron
+        uv.Read();
+        int read = uv.Flag;
+        if (read) pc.printf("FIRE DETECTED\n");
+        else pc.printf("NOT DETECTED\n");
+        
+        pc.printf("temp max= %.2f at %d\n", max_temp, max_i);
+        pc.printf("temp rata2 = %.2f\n", sum_temp/AMG88xx_PIXEL_ARRAY_SIZE);
+        
+        // baca kompas
+        char data[2] = {0x1, 0xFF};
+        int nack;
+        nack = cmps12.write(I2C_ADDR, data, 1);   
+        nack = cmps12.read(I2C_ADDR, data+1, 1);
+        pc.printf("Bearing kompas = %.2f\n", (float) data[1]/255*360);
+        
+        // stepper
+        pc.printf("Stepper \n");
+        for (int i = 0; i < 50; i++) {
+            s.step(1, 1, 1/WAIT_TIME); // CCW
+        }
+        
+        for (int i = 0; i < 50; i++) {
+            s.step(1, 0, 1/WAIT_TIME); // CW
+        }
+        
+        // pompa 
+        relay = 0; // active low
+        pc.printf("Pompa on!\n");
+        wait(1);
+        relay = 1;
+        pc.printf("Pompa off\n");
+        wait(1);
+        
         wait_ms(200);
+        
         pc.printf("\033[2J\033[H");
     }
 }