GPS3 Click
GPS3 Click
* Description:
This is a simple project which demonstrates the use of Accel2 click board.
Measured coordinates (X,Y,Z) are being sent to the GLCD where you can track
their changes.
*/
#include "Accel2_click.h"
#include "Accel2_driver.h" //added by me
#include "Accel2_driver.c" //added by me
#include "resources.h"
#include "built_in.h"
/
***********************************************************************************
**************
* Draw Accel Screen function
***********************************************************************************
***************/
void DrawAccelScr() {
Glcd_Init(); // Initialize GLCD
Glcd_Fill(0x00); // Clear display
//GLCD_Set_Font(&HandelGothic_BT21x22_Regular, 5,7,32);
GLCD_Write_Text("ACCEL2 Click Demo", 0,1,1);
// GLCD_Set_Font(&Verdana12x13_Regular, 5,7,32);
GLCD_Write_Text("EasyMx PRO v7", 0,2, 1);
// GLCD_Set_Font(&Verdana12x13_Regular, 5,7,32);
GLCD_Write_Text("Draw Accel.com", 0,3,1);
Delay_ms(2000);
}
void InitMCU(){
// Init TFT
Glcd_Init(); // Initialize GLCD
Glcd_Fill(0x00); // Clear display
Delay_ms(1000);
GLCD_Write_Text("InitMCU", 0,2,1);
Delay_ms(2000);
}
/
***********************************************************************************
***************
* Function Accel_Average()
*
-----------------------------------------------------------------------------------
--------------
* Overview: Function calculate the average values of the X, Y and Z axis reads
* Input: Nothing
* Output: X,Y and Z values are stored in readings[] buffer
***********************************************************************************
***************/
void Accel_Average() {
int i ;
int sx, sy, sz;
int sxarray[16], syarray[16], szarray[16], temparray;
// sum
sy = sz = 0;
sx = 0;
sxarray[i] = Accel_ReadX();
delay_ms(5);
syarray[i] = Accel_ReadY();
delay_ms(5);
szarray[i] = Accel_ReadZ();
delay_ms(5);
}
/
***********************************************************************************
***************
* Function Display_X_Value()
*
-----------------------------------------------------------------------------------
--------------
* Overview: Function display average X-axis read value on TFT
* Input: value stored in readings[0] buffer
* Output: Nothing
***********************************************************************************
***************/
void Display_X_Value() {
/
***********************************************************************************
***************
* Function Display_Y_Value()
*
-----------------------------------------------------------------------------------
--------------
* Overview: Function display average Y-axis read value on TFT
* Input: value stored in readings[1] buffer
* Output: Nothing
***********************************************************************************
***************/
void Display_Y_Value() {
// Glcd_Rectangle(80,65, 120, 75);
Glcd_Write_Text("Y: ", 0,4,1);
readings[1] = readings[1] - 1;
IntToStr(readings[1], out);
Glcd_Write_Text(out, 50, 4,1);
}
/
***********************************************************************************
***************
* Function Display_Z_Value()
*
-----------------------------------------------------------------------------------
--------------
* Overview: Function display average Z-axis read value on TFT
* Input: value stored in readings[2] buffer
* Output: Nothing
***********************************************************************************
***************/
void Display_Z_Value() {
//Glcd_Rectangle(80, 80, 120, 80);
Glcd_Write_Text("Z: ", 0,5,1);
readings[2] = readings[2] - 1;
IntToStr(readings[2], out);
Glcd_Write_Text(out, 50,5,1);
}
/
***********************************************************************************
***************
* Function ACCEL_Start()
*
-----------------------------------------------------------------------------------
--------------
* Overview: Function Initialize I2C bus and accel module
* Input: Nothing
* Output: Nothing
***********************************************************************************
***************/
void ACCEL_Start() {
// Initialize I2C communication
/
***********************************************************************************
***************
* Function ACCEL_Test()
*
-----------------------------------------------------------------------------------
--------------
* Overview: Function run the accel test
* Input: Nothing
* Output: Nothing
***********************************************************************************
***************/
void ACCEL_Test(void) {
Glcd_Write_Text("Reading axis values :", 3,3,1);
Accel_Average(); // Calculate average X, Y and Z reads
Display_X_Value(); // Display average X value read
Display_Y_Value(); // Display average Y value read
Display_Z_Value(); // Display average Z value read
Delay_ms(100);
}
void main() {
InitMCU();
DrawAccelScr();
ACCEL_Start();
while (1){
ACCEL_Test();
delay_ms(50);
}
}