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@7:65bdd2d0d6ad, 2015-04-11 (annotated)
- Committer:
- el13sr
- Date:
- Sat Apr 11 15:55:42 2015 +0000
- Revision:
- 7:65bdd2d0d6ad
- Parent:
- 6:d6afc4026a1d
- Child:
- 10:b61013738793
Reformatted documentation for Doxygen [WARNING: untested Version]
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
el13sr | 7:65bdd2d0d6ad | 1 | /** |
el13sr | 7:65bdd2d0d6ad | 2 | * @file main.h |
el13sr | 7:65bdd2d0d6ad | 3 | * @brief Distance Sensor Project |
el13sr | 7:65bdd2d0d6ad | 4 | * @brief Header file containing functions, definitions and global variables. |
el13sr | 7:65bdd2d0d6ad | 5 | * @brief Version: 0.6 |
el13sr | 7:65bdd2d0d6ad | 6 | * @author Sam Russell |
el13sr | 7:65bdd2d0d6ad | 7 | * @date March 2015 |
el13sr | 7:65bdd2d0d6ad | 8 | */ |
el13sr | 7:65bdd2d0d6ad | 9 | |
el13sr | 7:65bdd2d0d6ad | 10 | /********************************************//** |
el13sr | 7:65bdd2d0d6ad | 11 | * Libraries and Definitions |
el13sr | 7:65bdd2d0d6ad | 12 | ***********************************************/ |
el13sr | 0:7d01de89a1ff | 13 | |
el13sr | 0:7d01de89a1ff | 14 | #include "mbed.h" |
el13sr | 0:7d01de89a1ff | 15 | #include "SRF02.h" |
el13sr | 0:7d01de89a1ff | 16 | #include "N5110.h" |
el13sr | 6:d6afc4026a1d | 17 | #include "PowerControl/PowerControl.h" |
el13sr | 6:d6afc4026a1d | 18 | #include "PowerControl/EthernetPowerControl.h" |
el13sr | 7:65bdd2d0d6ad | 19 | #define USR_POWERDOWN (0x104) |
el13sr | 7:65bdd2d0d6ad | 20 | LocalFileSystem local("local"); /*!<Creates local filesystem */ |
el13sr | 7:65bdd2d0d6ad | 21 | Ticker timer; /*!<defines the timer */ |
el13sr | 0:7d01de89a1ff | 22 | |
el13sr | 7:65bdd2d0d6ad | 23 | /********************************************//** |
el13sr | 7:65bdd2d0d6ad | 24 | * Inputs |
el13sr | 7:65bdd2d0d6ad | 25 | ***********************************************/ |
el13sr | 7:65bdd2d0d6ad | 26 | /** |
el13sr | 7:65bdd2d0d6ad | 27 | * @namespace SRF02 |
el13sr | 7:65bdd2d0d6ad | 28 | * @brief Data (SDA) and clock (SCL) for the sensor. |
el13sr | 7:65bdd2d0d6ad | 29 | */ |
el13sr | 7:65bdd2d0d6ad | 30 | SRF02 SRF02(p28,p27); |
el13sr | 7:65bdd2d0d6ad | 31 | /** |
el13sr | 7:65bdd2d0d6ad | 32 | * @namespace Switch |
el13sr | 7:65bdd2d0d6ad | 33 | * @brief On/Off (BOOLEAN) states, OFF: Does not log data to file ON: Dos Log Data to file. |
el13sr | 7:65bdd2d0d6ad | 34 | */ |
el13sr | 7:65bdd2d0d6ad | 35 | AnalogIn Switch(p16); |
el13sr | 7:65bdd2d0d6ad | 36 | /** |
el13sr | 7:65bdd2d0d6ad | 37 | * @namespace Button |
el13sr | 7:65bdd2d0d6ad | 38 | * @brief Three states, Toggles between Normal, Quiet and Power Saving modes. |
el13sr | 7:65bdd2d0d6ad | 39 | */ |
el13sr | 7:65bdd2d0d6ad | 40 | InterruptIn Button(p17); |
el13sr | 0:7d01de89a1ff | 41 | |
el13sr | 7:65bdd2d0d6ad | 42 | /********************************************//** |
el13sr | 7:65bdd2d0d6ad | 43 | * Outputs |
el13sr | 7:65bdd2d0d6ad | 44 | ***********************************************/ |
el13sr | 7:65bdd2d0d6ad | 45 | /** |
el13sr | 7:65bdd2d0d6ad | 46 | * @namespace log LED |
el13sr | 7:65bdd2d0d6ad | 47 | * @brief Indicates if the data recorded is being logged to file or not. |
el13sr | 7:65bdd2d0d6ad | 48 | */ |
el13sr | 7:65bdd2d0d6ad | 49 | AnalogOut logLED(p18); |
el13sr | 7:65bdd2d0d6ad | 50 | /** |
el13sr | 7:65bdd2d0d6ad | 51 | * @namespace Display |
el13sr | 7:65bdd2d0d6ad | 52 | * @brief Defines the Nokia N5110 as the output display and all the corresponding pins. |
el13sr | 7:65bdd2d0d6ad | 53 | */ |
el13sr | 7:65bdd2d0d6ad | 54 | /// vcc,sce,rst,dc,mosi,clk,led |
el13sr | 0:7d01de89a1ff | 55 | N5110 display(p7,p8,p9,p10,p11,p13,p26); |
el13sr | 7:65bdd2d0d6ad | 56 | /** |
el13sr | 7:65bdd2d0d6ad | 57 | * @namespace Buzzer |
el13sr | 7:65bdd2d0d6ad | 58 | * @brief defines the buzzer pulse width modulation output. |
el13sr | 7:65bdd2d0d6ad | 59 | */ |
el13sr | 7:65bdd2d0d6ad | 60 | PwmOut buzzer(p21); |
el13sr | 7:65bdd2d0d6ad | 61 | /** |
el13sr | 7:65bdd2d0d6ad | 62 | * @namespace Baclight |
el13sr | 7:65bdd2d0d6ad | 63 | * @brief defines the baclight of the display pulse width modulation output. |
el13sr | 7:65bdd2d0d6ad | 64 | */ |
el13sr | 7:65bdd2d0d6ad | 65 | PwmOut backlight(p26); |
el13sr | 7:65bdd2d0d6ad | 66 | /** |
el13sr | 7:65bdd2d0d6ad | 67 | * @namespace LEDs |
el13sr | 7:65bdd2d0d6ad | 68 | * @brief Defines the set of on board LEDs. |
el13sr | 7:65bdd2d0d6ad | 69 | */ |
el13sr | 0:7d01de89a1ff | 70 | BusOut leds (LED1,LED2,LED3,LED4); //MBED onboard LEDs. |
el13sr | 7:65bdd2d0d6ad | 71 | /** |
el13sr | 7:65bdd2d0d6ad | 72 | * @namespace PC |
el13sr | 7:65bdd2d0d6ad | 73 | * @brief Used to transmit serial data to the PC via USB. |
el13sr | 7:65bdd2d0d6ad | 74 | */ |
el13sr | 0:7d01de89a1ff | 75 | Serial pc(USBTX,USBRX); |
el13sr | 0:7d01de89a1ff | 76 | |
el13sr | 7:65bdd2d0d6ad | 77 | /********************************************//** |
el13sr | 7:65bdd2d0d6ad | 78 | * Flags/Variables/Buffers |
el13sr | 7:65bdd2d0d6ad | 79 | ***********************************************/ |
el13sr | 0:7d01de89a1ff | 80 | |
el13sr | 7:65bdd2d0d6ad | 81 | int timerflag = 0; /*!<initialise timer flag to equal 0. */ |
el13sr | 7:65bdd2d0d6ad | 82 | int distance = 0; /*!<initialise distance to equal 0. */ |
el13sr | 7:65bdd2d0d6ad | 83 | int buttonFlag = 0; /*!<initialise buttonFlag to be 0, which defines the state of the data logger. */ |
el13sr | 7:65bdd2d0d6ad | 84 | int setTimeFlag = 0; /*!<initialise setTimeFlag to equal 0. */ |
el13sr | 7:65bdd2d0d6ad | 85 | int mode = 0; /*!<initialise mode to equal 0 (normal mode). */ |
el13sr | 7:65bdd2d0d6ad | 86 | |
el13sr | 7:65bdd2d0d6ad | 87 | char rxString[16]; /*!< buffer to store received string */ |
el13sr | 0:7d01de89a1ff | 88 | |
el13sr | 7:65bdd2d0d6ad | 89 | /********************************************//** |
el13sr | 7:65bdd2d0d6ad | 90 | * Functions |
el13sr | 7:65bdd2d0d6ad | 91 | ***********************************************/ |
el13sr | 4:0bd5c189f2f3 | 92 | |
el13sr | 7:65bdd2d0d6ad | 93 | void writeDataToFile(char* data, float Distancedata); /*!<Creates the void which takes the two types of data into the function. */ |
el13sr | 7:65bdd2d0d6ad | 94 | void welcomeScreen(); /*!<Function that generates and clears the welcome screen */ |
el13sr | 7:65bdd2d0d6ad | 95 | void barChart(); /*!<Function to update the bar chart on the display. */ |
el13sr | 7:65bdd2d0d6ad | 96 | void error(int code); /*!<DEBUG: Error Function */ |
el13sr | 7:65bdd2d0d6ad | 97 | void timerExpired(); /*!<Function for when the timer expires. */ |
el13sr | 7:65bdd2d0d6ad | 98 | float avgDist(); /*!<Function to get the average distance. */ |
el13sr | 7:65bdd2d0d6ad | 99 | void buttonPressed(); /*!<Function to change mode once button is pressed.*/ |