Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Dependencies: MMA8452 N5110 PowerControl mbed
Acceloro.cpp
- Committer:
- MrMavriks
- Date:
- 2015-05-11
- Revision:
- 0:39bc90f27661
- Child:
- 1:8359e6982b30
File content as of revision 0:39bc90f27661:
/**
@file main.h
@Header file contains code for displaying acceleration, defines and global variables.
@Revision 1.0
@Author Mario Quartey Papafio
@Date May 2015
*/
#include "mbed.h"
#include "N5110.h"
#include "MMA8452.h"
#include "PowerControl/PowerControl.h"
#include "PowerControl/EthernetPowerControl.h"
/**
//@to powerdown the usb
*/
char buffer[14]; // to store array character takes 6 pixels
char buffer1[14];
char buffer2[14];
char buffer3[14];
#define USR_POWERDOWN (0X104)
int semihost_powerdown()
{
uint32_t arg;
return __semihost (USR_POWERDOWN, &arg);
}
DigitalOut myled(LED1);
N5110 lcd(p7,p8,p9,p10,p11,p13,p26);
MMA8452 mma8452(p28,p27); // SDA, SCL
Serial serial(USBTX,USBRX);
int multiplication (int length, int reg)
{
int m;
m=length*reg;
return m;
}
int main() {
/**
@Powers Down Ethernet
@Powers Down USB interface
*/
PHY_PowerDown();
semihost_powerdown();
/**
@Initialises lcd and accelerometer
*/
// lcd.initSPI();
lcd.init();
lcd.printString("Hello World!", 0,0);
lcd.refresh();
wait(1);
lcd.clear();
mma8452.init(); // 100 Hz update rate, ±4g scale
Acceleration acceleration; // Accleration structure declared in MMA8452 class
while (1) {
lcd.printString("X Y Z Values", 0,0);
acceleration = mma8452.readValues(); // read current values and print over serial port
int xx = sprintf(buffer, "x = %.2f", acceleration.x); // figure eout the length of chars
int yy = sprintf(buffer1, "y = %.2f", acceleration.y);
int zz = sprintf(buffer2, "z = %.2f", acceleration.z);
serial.printf("x = %.2f g y = %.2f g z = %.2f g\n",acceleration.x,acceleration.y,acceleration.z);
wait(0.1); // short delay until next reading
if (xx <= 14){ // if the length is smaller than 14 chars. it prints
lcd.printString(buffer, 10, 1);
if (yy <= 14){ // if the length is smaller than 14 chars. it prints
lcd.printString(buffer1, 10, 2);
if (zz <= 14){ // if the length is smaller than 14 chars. it prints
lcd.printString(buffer2, 10, 3);
float mag = sqrt((acceleration.x*acceleration.x + acceleration.y*acceleration.y + acceleration.z*acceleration.z));
int ff = sprintf(buffer3, "Mag = %.2f", mag);
if (mag <= 14){ // if the length is smaller than 14 chars. it prints
lcd.printString(buffer3, 10, 4);
}
}
}
}
lcd.refresh();
}
}