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

Files at this revision

API Documentation at this revision

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

Changed in this revision

main.cpp Show annotated file Show diff for this revision Revisions of this file
--- a/main.cpp	Mon May 06 02:10:12 2013 +0000
+++ b/main.cpp	Tue Jun 04 04:10:17 2013 +0000
@@ -9,25 +9,53 @@
 
 DigitalOut connectionLed(LED1);//for later debug
 
-int main() {  
-    if (MMA.testConnection())
-        connectionLed = 1;
-        
+const   int n = 10;                         //number of readings to be averaged, change globally here
+int         score = 0;                      //reserved for later
+int         angle = 0;                      //reserved for later
+float       pulseXT =0, pulseYT = 0;        //Total holders for summation from axis arrays
+
+float       pulseXa, pulseYa;               //averaged values for each axis over n
+float       pulseX[n], pulseY[n];           //arrays to hold n readings for each axis
+int         i, j;                           //indexing variables
+
+int main()
+{
+
     while(1) {
+
+        for (i = 0; i < n; i = i + 1) {     //read n values into each axis array
+            pulseX[i] = MMA.x();
+            pulseY[i] = MMA.y();
+            //wait (1);
+        }
+        pulseXT = 0;                        //reset Totala
+        pulseYT = 0;                        //reset Totala
+        for (j = 0; j < n; j = j + 1) {     //summation of the contents of each array into axis Totals
+            pulseXT = pulseXT+pulseX[j];
+            pulseYT = pulseYT+pulseY[j];
+            //wait (1);
+        }
+        pulseXa = pulseXT/n;                //axis average over n
+
+        pulseYa = pulseYT/n;                //axis average over n
+
+        if (MMA.testConnection())
+            connectionLed = 1;
+
+
         lcd.cls();//clear LCD for next reading round
         lcd.locate(3,3);//first LCD column label
         lcd.printf("x-axis | ");//label column
         lcd.locate(3,14);//xdata location
-        lcd.printf("%.2f\n",MMA.x());//print x to LCD
+        lcd.printf("%.2f\n",pulseXa);//print x to LCD
         lcd.locate(40,3);//second LCD column label
         lcd.printf("y-axis | ");//label column
         lcd.locate(40,14);//ydata location
-        lcd.printf("%.2f\n",MMA.y());//print y to LCD
+        lcd.printf("%.2f\n",pulseYa);//print y to LCD
         lcd.locate(77,3);//initial LCD location
         lcd.printf("z-axis");//label column
         lcd.locate(77,14);//zdata location
         lcd.printf("%.2f\n",MMA.z());//print z to LCD
-        wait(0.5);//update after 0.5 s
+        //wait(0.5);//update after 0.5 s
     }
-
-}
+}
\ No newline at end of file