You are viewing an older revision! See the latest version
Compiler Error 13
maybe you forgot the quotaion marks?
- include "mbed.h"
- include "MobileLCD.h“ MobileLCD (p11, p12, p13, p15, p16); mosi,miso,clk,cs,rst SPI acc(p11,p12,p13); setup SPI interface on pins 11,12,13 DigitalOut cs(p14); use pin 14 as chip select DigitalIn switchinput(p7);button push DigitalOut myled(LED1); Serial pc(USBTX, USBRX); setup USB interface to host terminal
float sum_x, sum_y, sum_z; char buffer[6]; raw data array type char signed short data[3]; acc data is signed 16 bit from -32,768 to +32,767 float x, y, z; floating point data float R,AccelX,AccelY, AccelZ; float a, b, A,B; float asmooth[50]; float bsmooth[50]; float xsmooth[100]; float ysmooth[100]; float zsmooth[100]; float avg_x,avg_y,avg_z;
float X_disp; X when button pushed (offset for calibration) float Y_disp; float X_cal; float Y_cal;
void LCD_screen_setup(void); tting up the LCD frame and backround colour void ADXL_setting_up(void); ADXL setup
float Smoothing_xyz(float); smoothing funcations for xyz
int main() {
ADXL_setting_up(); ADXL setup
LCD_screen_setup();
while (1) { infinite loop
wait(0.25); cs=0; acc.write(0x80|0x40|0x32); RW bit high, MB bit high, plus address for (int i= 0;i<=10;i++) { buffer[i]=acc.write(0x00); read back 6 data bytes
} cs=1; for (int o= 0;o<=10;o++) { data[0] = buffer[1]<<8 | buffer[0]; combine MSB and LSB data[1] = buffer[3]<<8 | buffer[2]; data[2] = buffer[5]<<8 | buffer[4]; x=0.004*data[0]; y=0.004*data[1]; z=0.004*data[2]; convert to floating point
} float sum_x=0.0; float avg_x=0.0;
for (int m=0;m<100;m++) {
xsmooth[m]=x;
sum_x = sum_x + xsmooth[m]; }
float sum_y=0.0; float avg_y=0.0;
for (int k=0;k<100;k++) {
ysmooth[k]=y;
sum_y = sum_y + ysmooth[k];
}
float sum_z=0.0; float avg_z=0.0;
for (int j=0;j<100;j++) { zsmooth[j]=z;
sum_z = sum_z + zsmooth[j];
}
avg_x=sum_x/(float)100;
avg_y=sum_y/(float)100; avg_z=sum_z/(float)100;
AccelX = atan(avg_x/(avg_z))*(180/3.14); AccelY = atan(avg_y/(avg_z))*(180/3.14);
if (switchinput==0) {
X_disp=0; Y_disp=0;
}
else {
X_disp = AccelX ; previous Accel X is storing x at that specific moment Y_disp = AccelY ;
}
X_cal = AccelX - X_disp; Y_cal = AccelY- Y_disp;
lcd.locate(0,0); lcd.printf("X= %1.2f",X_cal); print to screen
lcd.locate(8,0); lcd.printf("Y= %1.2f",Y_cal); print to screen
a=((avg_x*128)*0.4)+60; (0.4 to narrow the pixel spreading) + 60 for the offset calibration ( so it starts from the centre) b=((avg_y*128)*0.4)+60;
float sum_a=0.0; float avg_a=0.0;
for (int p=0;p<50;p++) {
asmooth[p]=a;
sum_a= sum_a + asmooth[p]; }
float sum_b=0.0; float avg_b=0.0;
for (int q=0;q<50;q++) {
bsmooth[q]=b;
sum_b= sum_b + bsmooth[q]; }
avg_a=(sum_a/(float)50); avg_b=(sum_b/(float)50);
if (avg_b>=110) limit the pixel on the background fill area for b (y) edges { avg_b=109; }
else if (avg_b<=12) { avg_b=11; }
if (avg_a>=110) limit the pixel on the background fill area for a (x) edges { avg_a=109; } else if (avg_a<=12) { avg_a=11; }
lcd.fill(avg_b,avg_a,10,10,0x00CC00);background fill for pixel to erase drawing lcd.fill(avg_b+3,avg_a+3,4,4,0xffffff);main pixel offset +3 to stay in the center of the background fill*/
}
}
void LCD_screen_setup(void) {
lcd.fill(10,10,1,110,0xFFFFFF); left vertical line lcd.fill(10,10,110,1,0xFFFFFF); upper horizontal line lcd.fill(10,120,110,1,0xFFFFFF);lower horizontal line lcd.fill(120,10,1,110,0xFFFFFF);right vertical line lcd.fill(11,11,109,109,0x00CC00);frame background colour (green)
}
void ADXL_setting_up(void) { cs=1; acc.format(8,3); 8 bit data, Mode3 acc.frequency(2000000); 2MHz clock rate
cs=0; acc.write(0x31); data format register acc.write(0x0B); format +/-16g, 0.004g/LSB (0x02) cs=1; was commented
cs=0; acc.write(0x2C); setting up the data format register acc.write(0x07); data rate is 25Hz cs=1;
cs=0; acc.write(0x2D); power ctrl register acc.write(0x08); measure mode
cs=1;
}