Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Dependencies: mbed ADS1115 StepperMotor SRF05 TPA81new
main.cpp
- Committer:
- hisyamfs
- Date:
- 2019-02-07
- Revision:
- 40:1c29f33d54d7
- Parent:
- 39:1c067e2e2820
- Child:
- 41:71c6f608fd2b
File content as of revision 40:1c29f33d54d7:
#include "mbed.h"
#include "TPA81new.h"
#include "SRF05.h"
#include "Uvtron.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
Serial pc(USBTX,USBRX);
// TPA
TPA81 tpax(PB_9, PB_8, 0xDC);
TPA81 tpay(PB_9, PB_8, 0xDE);
// 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
DigitalOut relay(PB_2);
// UVTron
Uvtron uv(PC_12);
// Sound
DigitalIn sound(PA_9);
// Line
AnalogIn line(PC_1);
// infrared
#define a_depan 5000000
#define b_depan 1.229
// atas
AnalogIn ira1(PC_5);
AnalogIn ira2(PA_5);
AnalogIn ira3(PC_2);
AnalogIn ira4(PC_3);
AnalogIn ira5(PB_1);
AnalogIn ira6(PC_4);
AnalogIn ira7(PA_6);
AnalogIn ira8(PA_7);
// bawah
AnalogIn irb1(PA_0);
AnalogIn irb2(PA_1);
AnalogIn irb3(PA_4);
AnalogIn irb4(PB_0);
#define WAIT_TIME 0.02
// 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);
DigitalOut led_api(PH_0);
DigitalOut led_sound(PH_1);
float call_depan(uint16_t x){
float side_distance = a_depan/pow(x,b_depan)+1;
return side_distance;
}
int main()
{
//tpax.changeaddress(0xDC,0xDE);
// while(sound.read()){}
led_api = 0;
led_sound = 0;
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));
}
pc.printf("\nTPA X \n");
tpax.Read();
for (i=2; i<=9; i++) {
pc.printf("%d ",tpax.getTemp(i));
}
pc.printf("\n");
pc.printf("us 1: %.2f\tus 2:%.2f\n", srf1.read(), srf2.read());
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 = 1;
pc.printf("RELAY ON\n");
wait(0.5);
relay = 0;
pc.printf("RELAY OFF\n");
pc.printf("Line = %.2f\n", 3300*line.read());
uint16_t raw_a1 = ira1.read_u16();
uint16_t raw_a2 = ira2.read_u16();
uint16_t raw_a3 = ira3.read_u16();
uint16_t raw_a4 = ira4.read_u16();
uint16_t raw_a5 = ira5.read_u16();
uint16_t raw_a6 = ira6.read_u16();
uint16_t raw_a7 = ira7.read_u16();
uint16_t raw_a8 = ira8.read_u16();
uint16_t raw_b1 = irb1.read_u16();
uint16_t raw_b2 = irb2.read_u16();
uint16_t raw_b3 = irb3.read_u16();
uint16_t raw_b4 = irb4.read_u16();
float dist_a1 = call_depan(raw_a1);
float dist_a2 = call_depan(raw_a2);
float dist_a3 = call_depan(raw_a3);
float dist_a4 = call_depan(raw_a4);
float dist_a5 = call_depan(raw_a5);
float dist_a6 = call_depan(raw_a6);
float dist_a7 = call_depan(raw_a7);
float dist_a8 = call_depan(raw_a8);
float dist_b1 = call_depan(raw_b1);
float dist_b2 = call_depan(raw_b2);
float dist_b3 = call_depan(raw_b3);
float dist_b4 = call_depan(raw_b4);
pc.printf("ir atas\n");
pc.printf(" %.2f %.2f\n", dist_a2, dist_a1);
pc.printf("%.2f %.2f\n", dist_a3, dist_a7);
pc.printf("%.2f %.2f\n", dist_a4, dist_a8);
pc.printf(" %.2f %.2f\n", dist_a6, dist_a5);
pc.printf("ir bawah\n");
pc.printf(" %.2f\n", dist_b1);
pc.printf("%.2f %.2f\n", dist_b2, dist_b3);
pc.printf(" %.2f\n", dist_b4);
wait(1);
pc.printf("Stepper \n");
for (int i = 0; i < 200; i++) {
s.step(1, 1, 1/WAIT_TIME);
// pc.printf("%d\n", i);
}
led_api = 1;
pc.printf("led api on\n");
wait(0.5);
led_api = 0;
pc.printf("led api off\n");
led_sound = 1;
pc.printf("led sound on\n");
wait(0.5);
led_sound = 0;
pc.printf("led sound off\n");
wait(0.5);
pc.printf("\033[2J\033[H");
}
}