A program designed to get the distance from an SRF02 distance sensor and create an audible and visual indication of that distance with data logging capabilities.

Dependencies:   N5110 PowerControl SRF02 mbed

main.h

Committer:
el13sr
Date:
2015-04-08
Revision:
2:ebcfecb68cca
Parent:
1:387d5e6fa05f
Child:
4:0bd5c189f2f3

File content as of revision 2:ebcfecb68cca:

// Distance Sensor Project
// Header File "main.h"
// Designed By Sam Russell (200773195)
// Date: 07/04/2015 || Version: 0.1

#include "mbed.h"
#include "SRF02.h"
#include "N5110.h"

//Inputs
SRF02 SRF02(p28,p27); // SDA, SCL
AnalogIn Switch(p16); //Power Control Switch
InterruptIn Button(p17); //Logging Data? (Saving to mbed)

//Outputs
AnalogOut logLED(p18); // Logging To Disk Indicator
//            vcc,sce,rst,dc,mosi,clk,led
N5110 display(p7,p8,p9,p10,p11,p13,p26);
PwmOut Buzzer(p21); //Alert Buzzer
PwmOut backlight(p26); //Backlight output pin.
BusOut leds (LED1,LED2,LED3,LED4); //MBED onboard LEDs.
Serial pc(USBTX,USBRX);

LocalFileSystem local("local"); // create local filesystem
void writeDataToFile(char* data, float Distancedata); //Creates the void which takes the two types of data into the function.

Ticker timer;

int timerflag = 0; //initialise timer flag to equal 0.
int distance = 0;
int buttonFlag = 0; //initialise buttonFlag to be 0, which defines the state of the data logger.
char rxString[16]; // buffer to store received string
int light =0;
int setTimeFlag = 0;

void modeSwitch();
void error(int code);
void timerExpired();
float avgDist();
void buttonISR();