Uses the SRF02 UDS and displays distance in a variety of ways on the N5110 LCD.

Dependencies:   N5110WN PowerControl SRF02 mbed

main.h

Committer:
JakBlackburn
Date:
2015-03-20
Revision:
2:a1eaa4d74b63
Parent:
1:7f151ab172cb
Child:
3:00933efbe463

File content as of revision 2:a1eaa4d74b63:

/**
@file main.h
@brief Header file containng function prototypes, defines and global variables.
@brief Shows a Ultra-sonic Distance Sensor
@author Jakobi Blackburn
@date 13 March 2015
*/
#ifndef MAIN_H
#define MAIN_H

#define PI 3.14159265359

#include "mbed.h"
#include "PowerControl/PowerControl.h"
#include "PowerControl/EthernetPowerControl.h"
#include "Speaker.h"
#include "N5110.h"
#include "SRF02/SRF02.h"

// Inputs
/**
@namespace UnitTog
@brief An Interrupt button that toggles the Unit
*/
InterruptIn UnitTog(p14);
/**
@namespace LCDTog
@brief A SPDT switch that turns the LCD Screen on/off
*/
AnalogIn LCDTog(p15);
/**
@namespace LogTog
@brief An Interrupt button that toggles the Logging Capabilities
*/
InterruptIn LogTog(p16);
/**
@namespace VisTog
@brief An Interrupt button that changes the visual representation of the data
*/
InterruptIn VisTog(p17);
/**
@namespace BuzVol
@brief An Analogue input (Potentiometer) that is used to change the volume of the buzzer
*/
AnalogIn BuzVol(p19);
/**
@namespace BLEDLevel
@brief An Analogue input (Potentiometer) that is used to change the backlight of the LCD screen
*/
AnalogIn BLEDLevel(p20);
/**
@namespace sensor
@brief Ultra-Sonic distance sensor requires SDA and SCL lines
*/
SRF02 sensor(p28,p27);//SDA SCL

// Outputs
/**
@namespace N5110 LCD
@brief An LCD screen that requires
@brief Pinout VCC,SCE,RST,D/C,MOSI,SCLK,LED
*/     
N5110 lcd(p7,p8,p9,p10,p11,p13,p26);
/**
@namespace Buzzer
@brief A buzzer that can produce different notes dependant on the frquency of the signal inputted to it. Used as an
*/  
Speaker Buzzer(p18);
/**
@namespace BLED
@brief The backlight of the LCD screen. Brightness can be changed via Pulse Width Modulation
*/  
PwmOut BLED(p26);
/**
@namespace WLED
@brief A LED used as visual warning
*/ 
DigitalOut WLED(p21);
/**
@namespace LLED
@brief A LED used to show Logging is off/on
*/ 
DigitalOut LLED(p29);
/**
@namespace pc
@brief Serial output used mainly for debugging.
@brief Pinout TX, RX
*/ 
Serial pc(USBTX,USBRX);// the tx and rx respectively
/**
@namespace leds
@brief leds used to display error messages and when the file is being written too
*/ 
BusOut leds(LED4,LED3,LED2,LED1);


// ---- Variables ----

float scanSpeed=1; /*!< float that changes the speed that the distance is taken */
float volume=1; /*!< float used to vary the volume */
int distance; /*!< integer that stores the distance */
float unitX=1; /*!< Float that stores the unit multiple if 1 unit is cm, 0.01 = m, 10 = mm */
int U=0;  /*!< integer used to define the units. if 0 cm, 1 is m, 2 is mm */
const char *units ="cm";

// ---- Flags ----
int timerFlag=0; /*!< flag used to trigger the timer ISR   */
int setTimeFlag = 0; /*!< flag for ISR for setting time  */
int logButtonFlag = 0; /*!<flag for button toggle  */

// ---- MISC ----
char rxString[16]; // buffer to store received string
LocalFileSystem local("local"); // create local filesystem

Ticker timer;

//  ---- functions ----
/**
deals with the visual and audiable alerts.
*/
void warnings();  
/**
takes 10 distances and averages them.
@returns The distance between the Sensor and the nearest object infront of it
*/
float getDistance(); 
/**
changes the units cm/m/mm
*/
void unitToggle();  
/**
ISR used for the timer
*/
void timerExpired(); 
/**
sets the speed of the scanning, dependant on the distance
*/
void setScanSpeed();
/**
Displays an error message on the Mbed LEDs
@param E - Error Code
*/
void error(int E);


void logButtonPressed();

void logging(char* data,float data1);

void serialISR();

void setTime(); // function to set the UNIX time

void introTune();

void checkerBoard();

typedef const struct State STyp; /*!< defines the struct type */
/**
Sets the struct
*/
struct State { 
 float unitMultiple; /*!< float that stores the unit mulitple */
 const char *Unit; /*!<stores the sting value of the unit */
 int nextState[2]; /*!< array of next states */
};

/**
@brief sets the Finite State Machine for the Unit toggle.
*/
STyp fsm[3] = {
 {1,"cm",{0,1}}, /*!< State 0: stays in the current state unless input is recieved */ 
 {0.01,"m",{1,2}},  /*!< State 1: stays in the current state unless input is recieved  */ 
 {10,"mm",{2,0}} /*!< State 2: stays in the current state unless input is recieved  */ 
}; 
int state=0;/*!< sets the initial state */



#endif