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
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.
main.cpp@4:10426f54d388, 2013-06-04 (annotated)
- Committer:
- chapfohn
- Date:
- Tue Jun 04 04:16:34 2013 +0000
- Revision:
- 4:10426f54d388
- Parent:
- 3:0d76aaff55b8
- Child:
- 5:ba17585f3a2a
Program reads x, y axis data into array, totals and averages.
; Removed Debug wait artefacts.
Who changed what in which revision?
User | Revision | Line number | New 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 | } |
chapfohn | 3:0d76aaff55b8 | 30 | pulseXT = 0; //reset Totala |
chapfohn | 3:0d76aaff55b8 | 31 | pulseYT = 0; //reset Totala |
chapfohn | 3:0d76aaff55b8 | 32 | for (j = 0; j < n; j = j + 1) { //summation of the contents of each array into axis Totals |
chapfohn | 3:0d76aaff55b8 | 33 | pulseXT = pulseXT+pulseX[j]; |
chapfohn | 3:0d76aaff55b8 | 34 | pulseYT = pulseYT+pulseY[j]; |
chapfohn | 3:0d76aaff55b8 | 35 | } |
chapfohn | 3:0d76aaff55b8 | 36 | pulseXa = pulseXT/n; //axis average over n |
chapfohn | 3:0d76aaff55b8 | 37 | |
chapfohn | 3:0d76aaff55b8 | 38 | pulseYa = pulseYT/n; //axis average over n |
chapfohn | 3:0d76aaff55b8 | 39 | |
chapfohn | 3:0d76aaff55b8 | 40 | if (MMA.testConnection()) |
chapfohn | 3:0d76aaff55b8 | 41 | connectionLed = 1; |
chapfohn | 3:0d76aaff55b8 | 42 | |
chapfohn | 3:0d76aaff55b8 | 43 | |
chapfohn | 1:0a7a84edc8e5 | 44 | lcd.cls();//clear LCD for next reading round |
chapfohn | 2:b0a8d3b7a6dd | 45 | lcd.locate(3,3);//first LCD column label |
chapfohn | 2:b0a8d3b7a6dd | 46 | lcd.printf("x-axis | ");//label column |
chapfohn | 2:b0a8d3b7a6dd | 47 | lcd.locate(3,14);//xdata location |
chapfohn | 3:0d76aaff55b8 | 48 | lcd.printf("%.2f\n",pulseXa);//print x to LCD |
chapfohn | 2:b0a8d3b7a6dd | 49 | lcd.locate(40,3);//second LCD column label |
chapfohn | 2:b0a8d3b7a6dd | 50 | lcd.printf("y-axis | ");//label column |
chapfohn | 2:b0a8d3b7a6dd | 51 | lcd.locate(40,14);//ydata location |
chapfohn | 3:0d76aaff55b8 | 52 | lcd.printf("%.2f\n",pulseYa);//print y to LCD |
chapfohn | 2:b0a8d3b7a6dd | 53 | lcd.locate(77,3);//initial LCD location |
chapfohn | 2:b0a8d3b7a6dd | 54 | lcd.printf("z-axis");//label column |
chapfohn | 2:b0a8d3b7a6dd | 55 | lcd.locate(77,14);//zdata location |
chapfohn | 1:0a7a84edc8e5 | 56 | lcd.printf("%.2f\n",MMA.z());//print z to LCD |
Sissors | 0:bd0546063b0a | 57 | } |
chapfohn | 3:0d76aaff55b8 | 58 | } |