Build upon MMA7660_HelloWorld to pull out x, y, z axes from device and print to LCD on mbed Application Board

Dependencies:   C12832_lcd MMA7660 mbed

Fork of MMA7660_HelloWorld by Erik -

Here reside bits and pieces of coding that is mostly derivative of the work of others. Mostly extensions and other modifications.

The proprioception board project.

Board design images follow.

/media/uploads/chapfohn/260px-sphere-and-ring_balance_board_underside.jpg /media/uploads/chapfohn/obroc2.gif

/media/uploads/chapfohn/coolboard-balance-board-ultimate-package-medium-bot02-03-w450.png

Committer:
chapfohn
Date:
Tue Jun 04 04:10:17 2013 +0000
Revision:
3:0d76aaff55b8
Parent:
2:b0a8d3b7a6dd
Child:
4:10426f54d388
Program reads x, y axis data into array, toatals and averages.
; Display on LCD.

Who changed what in which revision?

UserRevisionLine numberNew contents of line
chapfohn 1:0a7a84edc8e5 1 //Iteration for 3 axis, ...
Sissors 0:bd0546063b0a 2
Sissors 0:bd0546063b0a 3 #include "mbed.h"
Sissors 0:bd0546063b0a 4 #include "MMA7660.h"
chapfohn 1:0a7a84edc8e5 5 #include "C12832_lcd.h"
Sissors 0:bd0546063b0a 6
chapfohn 1:0a7a84edc8e5 7 C12832_LCD lcd;
Sissors 0:bd0546063b0a 8 MMA7660 MMA(p28, p27);
Sissors 0:bd0546063b0a 9
chapfohn 2:b0a8d3b7a6dd 10 DigitalOut connectionLed(LED1);//for later debug
Sissors 0:bd0546063b0a 11
chapfohn 3:0d76aaff55b8 12 const int n = 10; //number of readings to be averaged, change globally here
chapfohn 3:0d76aaff55b8 13 int score = 0; //reserved for later
chapfohn 3:0d76aaff55b8 14 int angle = 0; //reserved for later
chapfohn 3:0d76aaff55b8 15 float pulseXT =0, pulseYT = 0; //Total holders for summation from axis arrays
chapfohn 3:0d76aaff55b8 16
chapfohn 3:0d76aaff55b8 17 float pulseXa, pulseYa; //averaged values for each axis over n
chapfohn 3:0d76aaff55b8 18 float pulseX[n], pulseY[n]; //arrays to hold n readings for each axis
chapfohn 3:0d76aaff55b8 19 int i, j; //indexing variables
chapfohn 3:0d76aaff55b8 20
chapfohn 3:0d76aaff55b8 21 int main()
chapfohn 3:0d76aaff55b8 22 {
chapfohn 3:0d76aaff55b8 23
Sissors 0:bd0546063b0a 24 while(1) {
chapfohn 3:0d76aaff55b8 25
chapfohn 3:0d76aaff55b8 26 for (i = 0; i < n; i = i + 1) { //read n values into each axis array
chapfohn 3:0d76aaff55b8 27 pulseX[i] = MMA.x();
chapfohn 3:0d76aaff55b8 28 pulseY[i] = MMA.y();
chapfohn 3:0d76aaff55b8 29 //wait (1);
chapfohn 3:0d76aaff55b8 30 }
chapfohn 3:0d76aaff55b8 31 pulseXT = 0; //reset Totala
chapfohn 3:0d76aaff55b8 32 pulseYT = 0; //reset Totala
chapfohn 3:0d76aaff55b8 33 for (j = 0; j < n; j = j + 1) { //summation of the contents of each array into axis Totals
chapfohn 3:0d76aaff55b8 34 pulseXT = pulseXT+pulseX[j];
chapfohn 3:0d76aaff55b8 35 pulseYT = pulseYT+pulseY[j];
chapfohn 3:0d76aaff55b8 36 //wait (1);
chapfohn 3:0d76aaff55b8 37 }
chapfohn 3:0d76aaff55b8 38 pulseXa = pulseXT/n; //axis average over n
chapfohn 3:0d76aaff55b8 39
chapfohn 3:0d76aaff55b8 40 pulseYa = pulseYT/n; //axis average over n
chapfohn 3:0d76aaff55b8 41
chapfohn 3:0d76aaff55b8 42 if (MMA.testConnection())
chapfohn 3:0d76aaff55b8 43 connectionLed = 1;
chapfohn 3:0d76aaff55b8 44
chapfohn 3:0d76aaff55b8 45
chapfohn 1:0a7a84edc8e5 46 lcd.cls();//clear LCD for next reading round
chapfohn 2:b0a8d3b7a6dd 47 lcd.locate(3,3);//first LCD column label
chapfohn 2:b0a8d3b7a6dd 48 lcd.printf("x-axis | ");//label column
chapfohn 2:b0a8d3b7a6dd 49 lcd.locate(3,14);//xdata location
chapfohn 3:0d76aaff55b8 50 lcd.printf("%.2f\n",pulseXa);//print x to LCD
chapfohn 2:b0a8d3b7a6dd 51 lcd.locate(40,3);//second LCD column label
chapfohn 2:b0a8d3b7a6dd 52 lcd.printf("y-axis | ");//label column
chapfohn 2:b0a8d3b7a6dd 53 lcd.locate(40,14);//ydata location
chapfohn 3:0d76aaff55b8 54 lcd.printf("%.2f\n",pulseYa);//print y to LCD
chapfohn 2:b0a8d3b7a6dd 55 lcd.locate(77,3);//initial LCD location
chapfohn 2:b0a8d3b7a6dd 56 lcd.printf("z-axis");//label column
chapfohn 2:b0a8d3b7a6dd 57 lcd.locate(77,14);//zdata location
chapfohn 1:0a7a84edc8e5 58 lcd.printf("%.2f\n",MMA.z());//print z to LCD
chapfohn 3:0d76aaff55b8 59 //wait(0.5);//update after 0.5 s
Sissors 0:bd0546063b0a 60 }
chapfohn 3:0d76aaff55b8 61 }