tes ir atas semua
Dependencies: mbed ADS1115 StepperMotor SRF05 TPA81new
Diff: main.cpp
- Revision:
- 42:3b682b7d0388
- Parent:
- 41:71c6f608fd2b
- Child:
- 43:b82c19d0c6a9
--- a/main.cpp Mon Feb 11 12:38:54 2019 +0000 +++ b/main.cpp Mon Feb 11 12:49:36 2019 +0000 @@ -3,23 +3,24 @@ #include "SRF05.h" #include "Uvtron.h" #include "Stepper.h" -#define LCD_D4_DIG PA_15 -#define LCD_D5_DIG PA_14 -#define LCD_E_DIG PC_15 -#define LCD_RS_DIG PB_7 +#include "AMG8833.h" Serial pc(USBTX,USBRX); // TPA -TPA81 tpax(PB_9, PB_8, 0xDC); -TPA81 tpay(PB_9, PB_8, 0xDE); +//TPA81 tpax(PB_9, PB_8, 0xDC); +//TPA81 tpay(PB_9, PB_8, 0xDE); + +// AMG +Adafruit_AMG88xx amg(PB_9, PB_8); +float pixels[AMG88xx_PIXEL_ARRAY_SIZE]; // Ultrasonik //SRF05 srf1(PC_13, PA_14); // trigger, echo //SRF05 srf1(PA_11, PB_12); //SRF05 srf1(PB_12, PA_11); -SRF05 srf1(PB_3, PB_10); -SRF05 srf2(PA_15, PB_7); // trigger, echo +//SRF05 srf1(PB_3, PB_10); +//SRF05 srf2(PA_15, PB_7); // trigger, echo DigitalOut relay(PB_2); @@ -50,7 +51,7 @@ AnalogIn irb3(PA_4); AnalogIn irb4(PB_0); -#define WAIT_TIME 0.02 +#define WAIT_TIME 0.05 // stepper(PinName _en, PinName ms1, PinName ms2, PinName ms3, PinName _stepPin, PinName dir); stepper s(PC_6, PC_8, PA_12, PC_7, PA_11, PB_12); @@ -65,44 +66,59 @@ int main() { - //tpax.changeaddress(0xDC,0xDE); relay = 1; -// while(sound.read()){} led_api = 0; led_sound = 0; + amg.begin(AMG88xx_ADDRESS); + amg.setMovingAverageMode(1); + + while(sound.read()){ + wait(0.2); + } + pc.printf("Sound Detected\n"); + while(1) { - pc.printf("%d", tpay.getTemp(0)); - int i; - pc.printf("\nTPA Y \n"); - tpay.Read(); - for (i=2; i<=9; i++) { - pc.printf("%d ",tpay.getTemp(i)); + // AMG + amg.readPixels(pixels); + float max_temp = pixels[0]; + int max_i = 0; + float sum_temp = 0; + for (int i = 1; i <= AMG88xx_PIXEL_ARRAY_SIZE; i++) { + if (pixels[i-1] > max_temp) { + max_temp = pixels[i-1]; + max_i = i; + } + sum_temp += pixels[i-1]; } - - pc.printf("\nTPA X \n"); - tpax.Read(); - for (i=2; i<=9; i++) { - pc.printf("%d ",tpax.getTemp(i)); + for (int i = 1; i <= AMG88xx_PIXEL_ARRAY_SIZE; i++) { + pc.printf("%.2f", pixels[i-1]); + if (i == max_i) { + pc.printf("_ "); + } + if (i % 8 == 0) pc.printf("\n"); } - pc.printf("\n"); - - pc.printf("us 1: %.2f\tus 2:%.2f\n", srf1.read(), srf2.read()); + pc.printf("temp max= %.2f at %d\n", max_temp, max_i); + pc.printf("temp rata2 = %.2f", sum_temp/AMG88xx_PIXEL_ARRAY_SIZE); + // UVTron uv.Read(); int read = uv.Flag; if (read) pc.printf("FIRE DETECTED\n"); else pc.printf("NOT DETECTED\n"); wait(0.5); // 200 ms + // Relay relay = 0; pc.printf("RELAY ON\n"); wait(0.5); relay = 1; pc.printf("RELAY OFF\n"); + // Line pc.printf("Line = %.2f\n", 3300*line.read()); + // IR uint16_t raw_a1 = ira1.read_u16(); uint16_t raw_a2 = ira2.read_u16(); uint16_t raw_a3 = ira3.read_u16(); @@ -144,12 +160,18 @@ wait(1); + // Stepper pc.printf("Stepper \n"); - for (int i = 0; i < 200; i++) { + for (int i = 0; i < 50; i++) { s.step(1, 1, 1/WAIT_TIME); // pc.printf("%d\n", i); } + for (int i = 0; i < 50; i++) { + s.step(1, -1, 1/WAIT_TIME); + } + + // LED led_api = 1; pc.printf("led api on\n"); wait(0.5); @@ -162,6 +184,7 @@ led_sound = 0; pc.printf("led sound off\n"); wait(0.5); + pc.printf("\033[2J\033[H"); } }