0% found this document useful (0 votes)
86 views5 pages

GPS3 Click

Uploaded by

Marius Paulet
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
86 views5 pages

GPS3 Click

Uploaded by

Marius Paulet
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
You are on page 1/ 5

/* Project name:

Accel2 click - Accelerometer Test


* Copyright:

* 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"

#define BAUD_RATE 9600

/
***********************************************************************************
**************
* 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;

// Get 16 readings from accelerometer


for (i=0; i<16; i++) {

sxarray[i] = Accel_ReadX();
delay_ms(5);
syarray[i] = Accel_ReadY();
delay_ms(5);
szarray[i] = Accel_ReadZ();
delay_ms(5);
}

// Sort them by size


for(i=0; i<16; i++) {
if(sxarray[i]>sxarray[i+1]) {
temparray = sxarray[i];
sxarray[i] = sxarray[i+1];
sxarray[i+1] = temparray;
temparray = 0;
}
if(syarray[i]>syarray[i+1]) {
temparray = syarray[i];
syarray[i] = syarray[i+1];
syarray[i+1] = temparray;
temparray = 0;
}
if(szarray[i]>szarray[i+1]) {
temparray = szarray[i];
szarray[i] = szarray[i+1];
szarray[i+1] = temparray;
temparray = 0;
}
}

// Choose the lowest 4 values ( to avoid spiking ) and add them up


for(i=0; i<4; i++) {
sx += sxarray[i];
sy += syarray[i];
sz += szarray[i];
}

// Average values of those 4 values


readings[0] = sx / 4;
readings[1] = sy / 4;
readings[2] = sz / 4;
}

/
***********************************************************************************
***************
* 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() {

// TFT_Write_Text("X: ", 70, 50);


readings[0] = readings[0] - 1;
IntToStr(readings[0], out);
Glcd_Write_Text(out, 0,5,1);
}

/
***********************************************************************************
***************
* 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

// Glcd_Set_Font(TFT_defaultFont, CL_BLACK, FO_HORIZONTAL);


//Glcd_Set_Pen(CL_WHITE, 1);
//Glcd_Set_Brush(1, CL_WHITE, 0, 0, 0, 0);
Glcd_Fill(0x00); // Clear display
Glcd_Write_Text("Starting Accel test...", 2,2,1);
Delay_ms(1000);
// Glcd_Rectangle(35, 35, 120, 65);

// Initialize ADXL345 accelerometer


if (LIS3DSH_Init() == 0) {
Glcd_Fill(0x00); // Clear display
Glcd_Write_Text("Accel module initia", 2,2,1);
Delay_ms(1000);
}
else {
Glcd_Fill(0x00); // Clear display
Glcd_Write_Text("Error during Accel module init.", 1,1,1);
Delay_ms(1000);
}

// Glcd_Rectangle(35, 35, 120, 65);


}

/
***********************************************************************************
***************
* 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);
}
}

You might also like