Mobile Security System - Revision 1.0
Dependencies: FXOS8700Q N5110 SDFileSystem SRF02 mbed
Diff: main.cpp
- Revision:
- 0:12ae42019e9f
- Child:
- 1:3ae4192d0c25
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/main.cpp Fri Mar 04 12:15:28 2016 +0000 @@ -0,0 +1,84 @@ +/* ELEC2645 Project + +Week 19 - Take distance readings from the sensor +Week 20 - +Week 21 - +Week Easter - +Week 22 - +Week 23 - +Week 24 - + +*/ + +#include "mbed.h" +#include "N5110.h" +#include "SRF02.h" + + +SRF02 srf02(I2C_SDA,I2C_SCL); + +// UART connection for PC +Serial pc(USBTX,USBRX); + +// K64F on-board LEDs +DigitalOut r_led(LED_RED); +DigitalOut g_led(LED_GREEN); +DigitalOut b_led(LED_BLUE); +// K64F on-board switches +InterruptIn sw2(SW2); +InterruptIn sw3(SW3); + +int distance; + +// error function hangs flashing an LED +void error(); +// setup serial port +void init_serial(); +// set-up the on-board LEDs and switches +void init_K64F(); + + + +int main() +{ + // initialise the board and serial port + init_K64F(); + init_serial(); + + while (1) { + + + for (int i = 1; i < 11; i++) { + // read sensor and accelerometer + distance = srf02.getDistanceCm(); + } + + // print over serial port + pc.printf("Distance = %d cm\n",distance); + + // short delay before next measurement + wait(0.5); + + } + +} + +void init_serial() +{ + // set to highest baud - ensure terminal software matches + pc.baud(115200); +} + +void init_K64F() +{ + // on-board LEDs are active-low, so set pin high to turn them off. + r_led = 1; + g_led = 1; + b_led = 1; + + // since the on-board switches have external pull-ups, we should disable the internal pull-down + // resistors that are enabled by default using InterruptIn + sw2.mode(PullNone); + sw3.mode(PullNone); + +}