Simple Electronic Angle Meter and Spirit Level.

Dependencies:   MMA8452 mbed

Embed: (wiki syntax)

« Back to documentation index

main.cpp File Reference

main.cpp File Reference

Electronic Angle Meter and Spirit Level. More...

Go to the source code of this file.

Functions

void Switch (int functoion)
 Function prototypes.
void AngleMeter ()
 Display angles in two dimensions and indicate directions using arrows.
void SpiritLevel ()
 Indicate the gradient in all directions by showing.
void fun1 ()
 Display the function name of Angle Meter for 1 second before calling it.
void fun2 ()
 Display the function name of Spirit Level for 1 second before calling it.
int main ()
 Main function.
void PHY_PowerDown ()
 Power down the Ethernet interface to save power.

Variables

N5110 lcd (p7, p8, p9, p10, p11, p13, p26)
 Connect all components to mbed LPC1768.
float frequency1 = 1046.5
 Different frequencies of buzzer.

Detailed Description

Electronic Angle Meter and Spirit Level.

Revision 1.0.

Author:
Shengyuan Chu
Date:
May 2015

Definition in file main.cpp.


Function Documentation

void AngleMeter (  )

Display angles in two dimensions and indicate directions using arrows.

Initialise the accelerometer.

Lower down the brightness of LCD to 0.5.

When button is not pushed, main features of Angle Meter will be run.

Display 'degree' in the last line of LCD.

Read value of acceleration.

Calculate the angles in X and Y dimensions.

Print formatted data to buffer.

Display values if string will fit on display.

LED C will be turned on if the angle in X dimension is larger than 20 degree.

LED A will be turned on if the angle in X dimension is smaller than -20 degree.

LED D will be turned on if the angle in Y dimension is larger than 20 degree.

LED B will be turned on if the angle in Y dimension is smaller than -20 degree.

Draw lines of the body of arrows.

Pixes will be set if the angle in Y dimension is larger than 0 degree.

Pixes will be set if the angle in Y dimension is smaller than 0 degree.

Pixes will be set if the angle in X dimension is larger than 0 degree.

Pixes will be set if the angle in X dimension is smaller than 0 degree.

Decrease the fluctuation of values.

Buzzer will beep in frequency 2 if the angle is between 50 and 75 degree.

Buzzer will beep in frequency 3 if the angle is beyond 75 degree.

Buzzer will not beep.

When button is pushed, main features will stop.

Definition at line 117 of file main.cpp.

void fun1 (  )

Display the function name of Angle Meter for 1 second before calling it.

Initialise the LCD and set brightness to 0.8.

Display the function name of Angle Meter.

Turn LED A and LED C on.

Call function of Angle Meter after 1 second delay.

Definition at line 385 of file main.cpp.

void fun2 (  )

Display the function name of Spirit Level for 1 second before calling it.

Turn off the buzzer.

Initialise the LCD and set brightness to 0.8.

Display the function name of Spirit Level.

Turn LED B and LED D on.

Call function of Spirit Level after 1 second delay.

Definition at line 410 of file main.cpp.

int main (  )

Main function.

Call function of Angle Meter without pushing button when power is initally turned on.

Power down Ethernet interface to save power.

Initialise LCD and set brightness to 0.8.

Display the name of Angle Meter function after the initialization of LCD.

Call function of Angle Meter after 2 seconds' delay.

Turn all the LEDs on when the power is initially turned on.

Set button to PullDown mode.

Change the integer between 1 and 2 when button is pressed and send it to Switch function.

Allow 0.2 second for button debounce.

Definition at line 56 of file main.cpp.

void PHY_PowerDown ( void   )

Power down the Ethernet interface to save power.

Acknowledgements to Michael Wei's code.

Definition at line 439 of file main.cpp.

void SpiritLevel (  )

Indicate the gradient in all directions by showing.

the position of a group of pixes.

Initialise all the LEDs to be off.

Set the LCD to inverse mode and lower down the brightness to 0.5.

Initialise the accelerometer.

When button is not pushed, main features of Spirit Level will be run.

Read value of acceleration.

Draw three circles and two lines.

Pixes will be displayed if acceleration values are within -0.4 and 0.4.

Displayed pixes will be cleared after 0.2 second.

All LEDs will be turned on if acceleration values are within -0.05 and 0.05.

All LEDs will be turned off if acceleration values go beyond this range.

Definition at line 274 of file main.cpp.

void Switch ( int  function )

Function prototypes.

Switch functions between Angle Meter and Spirit Level.

Parameters:
function- integer to change between 1 and 2.
Returns:
Call fun1() when function=2, call fun2() when function=1.

Definition at line 102 of file main.cpp.


Variable Documentation

float frequency1 = 1046.5

Different frequencies of buzzer.

Definition at line 47 of file main.cpp.

N5110 lcd(p7, p8, p9, p10, p11, p13, p26)

Connect all components to mbed LPC1768.

Connect LCD to pin 7,8,9,10,11,13,26. Connect Accelerometer to pin 27,28. Connect buzzer to pin 21. Connect button to pin 17. Connect LEDs to pin 22,23,24,25.