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-23
Revision:
10:b61013738793
Parent:
7:65bdd2d0d6ad
Child:
11:41052065c916

File content as of revision 10:b61013738793:

/**
* @file main.h
* @brief Distance Sensor Project
* @brief Header file containing functions, definitions and global variables.
* @brief Version: 0.6
* @author Sam Russell
* @date March 2015
*/

/********************************************//**
 *  Libraries and Definitions
 ***********************************************/

#include "mbed.h"
#include "SRF02.h"
#include "N5110.h"
#include "PowerControl/PowerControl.h"
#include "PowerControl/EthernetPowerControl.h"
#define USR_POWERDOWN (0x104)
LocalFileSystem local("local"); /*!<Creates local filesystem */
Ticker timer; /*!<defines the timer */

/**
* @namespace PC
* @brief Used to transmit serial data to the PC via USB.
*/
Serial pc(USBTX,USBRX);

/********************************************//**
 *  Inputs
 ***********************************************/
/**
* @namespace SRF02
* @brief Data (SDA) and clock (SCL) for the sensor.
*/
SRF02 SRF02(p28,p27); 
/**
* @namespace Switch
* @brief On/Off (BOOLEAN) states, OFF: Does not log data to file ON: Dos Log Data to file.
*/
AnalogIn Switch(p16);
/**
* @namespace Button
* @brief Three states, Toggles between Normal, Quiet and Power Saving modes.
*/
InterruptIn Button(p17);

/********************************************//**
 *  Outputs
 ***********************************************/
/**
* @namespace logLED
* @brief Indicates if the data recorded is being logged to file or not.
*/
AnalogOut logLED(p18);
/**
* @namespace Display
* @brief Defines the Nokia N5110 as the output display and all the corresponding pins.
*/
///          vcc,sce,rst,dc,mosi,clk,led
N5110 display(p7,p8,p9,p10,p11,p13,p26);
/**
* @namespace Buzzer
* @brief defines the buzzer pulse width modulation output.
*/
PwmOut buzzer(p21); 
/**
* @namespace Baclight
* @brief defines the baclight of the display pulse width modulation output.
*/
PwmOut backlight(p26);
/**
* @namespace LEDs
* @brief Defines the set of on board LEDs.
*/
BusOut leds (LED1,LED2,LED3,LED4); //MBED onboard LEDs.

/********************************************//**
 *  Flags/Variables/Buffers
 ***********************************************/

int timerflag = 0; /*!<initialise timer flag to equal 0. */
int distance = 0; /*!<initialise distance to equal 0. */
int buttonFlag = 0; /*!<initialise buttonFlag to be 0, which defines the state of the data logger. */
int setTimeFlag = 0; /*!<initialise setTimeFlag to equal 0. */
int mode = 0; /*!<initialise mode to equal 0 (normal mode). */

char rxString[16]; /*!< buffer to store received string */

/********************************************//**
 *  Functions
 ***********************************************/

void writeDataToFile(char* data, float Distancedata); /*!<Creates the void which takes the two types of data into the function. */
void welcomeScreen(); /*!<Function that generates and clears the welcome screen */
void barChart(); /*!<Function to update the bar chart on the display. */
void error(int code); /*!<DEBUG: Error Function */
void timerExpired(); /*!<Function for when the timer expires. */
float avgDist(); /*!<Function to get the average distance. */
void buttonPressed(); /*!<Function to change mode once button is pressed.*/