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-21
- Revision:
- 3:00933efbe463
- Parent:
- 2:a1eaa4d74b63
- Child:
- 4:2e9aa626a02c
File content as of revision 3:00933efbe463:
/** @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 */ const char *units ="cm"; /*!< string of characters that stores the unit */ int visual =0;/*!< integer that stores the visual display mode */ // ---- 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(); /** changes the visual display */ void visToggle(); /** 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 @brief The error message show is up to 14. IF 15 shown it is a ack bit error for the SRF02 @param E - Error Code @returns flashing Mbed LEDs signifying the error */ void error(int E); /** */ void logButtonPressed(); /** */ void logging(char* data,float data1); /** ISR for the serial port */ void serialISR(); /** function to set the UNIX time */ void setTime(); /** Plays a set of frequencies through the buzzer creating a tune */ void introTune(); /** sets every other pixel on, creating a checkerboard like effect */ void checkerBoard(); /** sets the parameters for the first visual mode */ void LCDVis0(); /** sets the parameters for the second visual mode */ void LCDVis1(); /** sets the parameters for the third visual mode */ void LCDVis2(); 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 */ typedef const struct VState VSTyp; /*!< defines the struct type */ /** Sets the struct */ struct VState { int visual; /*!< integer that stores the visual mode */ int nextState[2]; /*!< array of next states */ }; /** @brief sets the Finite State Machine for the Visual toggle. */ VSTyp Vfsm[3] = { {0,{0,1}}, /*!< State 0: stays in the current state unless input is recieved */ {1,{1,2}}, /*!< State 1: stays in the current state unless input is recieved */ {2,{2,0}} /*!< State 2: stays in the current state unless input is recieved */ }; int Vstate=0;/*!< sets the initial state */ #endif