Mobile Security System - Revision 1.0

Dependencies:   FXOS8700Q N5110 SDFileSystem SRF02 mbed

Committer:
el14dg
Date:
Fri Mar 04 12:15:28 2016 +0000
Revision:
0:12ae42019e9f
Child:
1:3ae4192d0c25
Distance readings taken from sensor and then read from the PC

Who changed what in which revision?

UserRevisionLine numberNew contents of line
el14dg 0:12ae42019e9f 1 /* ELEC2645 Project
el14dg 0:12ae42019e9f 2
el14dg 0:12ae42019e9f 3 Week 19 - Take distance readings from the sensor
el14dg 0:12ae42019e9f 4 Week 20 -
el14dg 0:12ae42019e9f 5 Week 21 -
el14dg 0:12ae42019e9f 6 Week Easter -
el14dg 0:12ae42019e9f 7 Week 22 -
el14dg 0:12ae42019e9f 8 Week 23 -
el14dg 0:12ae42019e9f 9 Week 24 -
el14dg 0:12ae42019e9f 10
el14dg 0:12ae42019e9f 11 */
el14dg 0:12ae42019e9f 12
el14dg 0:12ae42019e9f 13 #include "mbed.h"
el14dg 0:12ae42019e9f 14 #include "N5110.h"
el14dg 0:12ae42019e9f 15 #include "SRF02.h"
el14dg 0:12ae42019e9f 16
el14dg 0:12ae42019e9f 17
el14dg 0:12ae42019e9f 18 SRF02 srf02(I2C_SDA,I2C_SCL);
el14dg 0:12ae42019e9f 19
el14dg 0:12ae42019e9f 20 // UART connection for PC
el14dg 0:12ae42019e9f 21 Serial pc(USBTX,USBRX);
el14dg 0:12ae42019e9f 22
el14dg 0:12ae42019e9f 23 // K64F on-board LEDs
el14dg 0:12ae42019e9f 24 DigitalOut r_led(LED_RED);
el14dg 0:12ae42019e9f 25 DigitalOut g_led(LED_GREEN);
el14dg 0:12ae42019e9f 26 DigitalOut b_led(LED_BLUE);
el14dg 0:12ae42019e9f 27 // K64F on-board switches
el14dg 0:12ae42019e9f 28 InterruptIn sw2(SW2);
el14dg 0:12ae42019e9f 29 InterruptIn sw3(SW3);
el14dg 0:12ae42019e9f 30
el14dg 0:12ae42019e9f 31 int distance;
el14dg 0:12ae42019e9f 32
el14dg 0:12ae42019e9f 33 // error function hangs flashing an LED
el14dg 0:12ae42019e9f 34 void error();
el14dg 0:12ae42019e9f 35 // setup serial port
el14dg 0:12ae42019e9f 36 void init_serial();
el14dg 0:12ae42019e9f 37 // set-up the on-board LEDs and switches
el14dg 0:12ae42019e9f 38 void init_K64F();
el14dg 0:12ae42019e9f 39
el14dg 0:12ae42019e9f 40
el14dg 0:12ae42019e9f 41
el14dg 0:12ae42019e9f 42 int main()
el14dg 0:12ae42019e9f 43 {
el14dg 0:12ae42019e9f 44 // initialise the board and serial port
el14dg 0:12ae42019e9f 45 init_K64F();
el14dg 0:12ae42019e9f 46 init_serial();
el14dg 0:12ae42019e9f 47
el14dg 0:12ae42019e9f 48 while (1) {
el14dg 0:12ae42019e9f 49
el14dg 0:12ae42019e9f 50
el14dg 0:12ae42019e9f 51 for (int i = 1; i < 11; i++) {
el14dg 0:12ae42019e9f 52 // read sensor and accelerometer
el14dg 0:12ae42019e9f 53 distance = srf02.getDistanceCm();
el14dg 0:12ae42019e9f 54 }
el14dg 0:12ae42019e9f 55
el14dg 0:12ae42019e9f 56 // print over serial port
el14dg 0:12ae42019e9f 57 pc.printf("Distance = %d cm\n",distance);
el14dg 0:12ae42019e9f 58
el14dg 0:12ae42019e9f 59 // short delay before next measurement
el14dg 0:12ae42019e9f 60 wait(0.5);
el14dg 0:12ae42019e9f 61
el14dg 0:12ae42019e9f 62 }
el14dg 0:12ae42019e9f 63
el14dg 0:12ae42019e9f 64 }
el14dg 0:12ae42019e9f 65
el14dg 0:12ae42019e9f 66 void init_serial()
el14dg 0:12ae42019e9f 67 {
el14dg 0:12ae42019e9f 68 // set to highest baud - ensure terminal software matches
el14dg 0:12ae42019e9f 69 pc.baud(115200);
el14dg 0:12ae42019e9f 70 }
el14dg 0:12ae42019e9f 71
el14dg 0:12ae42019e9f 72 void init_K64F()
el14dg 0:12ae42019e9f 73 {
el14dg 0:12ae42019e9f 74 // on-board LEDs are active-low, so set pin high to turn them off.
el14dg 0:12ae42019e9f 75 r_led = 1;
el14dg 0:12ae42019e9f 76 g_led = 1;
el14dg 0:12ae42019e9f 77 b_led = 1;
el14dg 0:12ae42019e9f 78
el14dg 0:12ae42019e9f 79 // since the on-board switches have external pull-ups, we should disable the internal pull-down
el14dg 0:12ae42019e9f 80 // resistors that are enabled by default using InterruptIn
el14dg 0:12ae42019e9f 81 sw2.mode(PullNone);
el14dg 0:12ae42019e9f 82 sw3.mode(PullNone);
el14dg 0:12ae42019e9f 83
el14dg 0:12ae42019e9f 84 }