useful

Dependencies:   Useless SB TSI mbed

Files at this revision

API Documentation at this revision

Comitter:
bmdlh
Date:
Sat Feb 08 22:23:55 2014 +0000
Commit message:
uesless

Changed in this revision

MAG3110.lib Show annotated file Show diff for this revision Revisions of this file
MMA8451Q.lib Show annotated file Show diff for this revision Revisions of this file
TSI.lib Show annotated file Show diff for this revision Revisions of this file
main.cpp Show annotated file Show diff for this revision Revisions of this file
mbed.lib Show annotated file Show diff for this revision Revisions of this file
diff -r 000000000000 -r c8a7071d8692 MAG3110.lib
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/MAG3110.lib	Sat Feb 08 22:23:55 2014 +0000
@@ -0,0 +1,1 @@
+http://mbed.org/users/bmdlh/code/Useless/#34cf17e4dbf5
diff -r 000000000000 -r c8a7071d8692 MMA8451Q.lib
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/MMA8451Q.lib	Sat Feb 08 22:23:55 2014 +0000
@@ -0,0 +1,1 @@
+http://mbed.org/users/bmdlh/code/SB/#f834bd401ef2
diff -r 000000000000 -r c8a7071d8692 TSI.lib
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/TSI.lib	Sat Feb 08 22:23:55 2014 +0000
@@ -0,0 +1,1 @@
+http://mbed.org/users/bmdlh/code/TSI/#a192baf6250c
diff -r 000000000000 -r c8a7071d8692 main.cpp
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/main.cpp	Sat Feb 08 22:23:55 2014 +0000
@@ -0,0 +1,122 @@
+//KL46Z try out
+#include "mbed.h"
+#include "TSISensor.h"
+#include "MMA8451Q.h"
+#include "MAG3110.h"
+#include <cstdlib>
+#include <iostream>
+#define OFF 0;
+#define ON 1;
+
+Serial pc(USBTX, USBRX);
+
+TSISensor tsi;
+MMA8451Q acc51(PTE25, PTE24, 0x1D<<1);
+MAG3110 mag(PTE25, PTE24);
+
+PwmOut rled(PTE29);
+PwmOut gled(PTD5);
+AnalogIn lightSensor(PTE22);
+DigitalIn SW12(PTC3);
+DigitalIn SW32(PTC12);
+//AnalogOut lcd03(PTB23);
+//PwmOut lcd07(PTB7);
+
+void calXY() //magnetometer calibration: finding max and min of X, Y axis
+{
+    int tempXmax, tempXmin, tempYmax, tempYmin, newX, newY;
+
+    rled = ON;
+
+    printf("Waiting for initial press\n");
+    // Wait for slider to be pressed
+    while( tsi.readDistance() == 0 ) {
+        rled = ON;
+        wait(0.2);
+        rled = OFF;
+        wait(0.2);
+    }
+
+    printf("Waiting for release\n");
+
+    // Wait for release
+    while( tsi.readDistance() != 0 ) {
+        rled = OFF;
+        wait(0.2);
+        rled = ON;
+        wait(0.2);
+    }
+    rled = OFF;
+    wait(0.5);
+
+    printf("Rotate\n");
+
+    tempXmax = tempXmin = mag.readVal(MAG_OUT_X_MSB);
+    tempYmax = tempYmin = mag.readVal(MAG_OUT_Y_MSB);
+
+    while(tsi.readDistance() == 0) {
+        gled = ON;
+        wait(0.1);
+        gled = OFF;
+        wait(0.1);
+        newX = mag.readVal(MAG_OUT_X_MSB);
+        newY = mag.readVal(MAG_OUT_Y_MSB);
+        if (newX > tempXmax) tempXmax = newX;
+        if (newX < tempXmin) tempXmin = newX;
+        if (newY > tempYmax) tempYmax = newY;
+        if (newY < tempYmin) tempYmin = newY;
+    }
+   
+    mag.setCalibration( tempXmin, tempXmax, tempYmin, tempYmax );
+
+    // Wait for release
+    while( tsi.readDistance() != 0 ) {
+        gled = OFF;
+        wait(0.2);
+        gled = ON;
+        wait(0.2);
+    }
+    gled = OFF;
+    wait(1.0);
+}
+
+int main()
+{
+    using namespace std;
+    
+    float onTime = 1.0;
+    float offTime = 0.0;
+    float holdTime = 3.0;
+    bool on = true;
+    bool off = false;
+    int magX = 0, magY = 0, magZ = 0;
+    //lcd03.write(0.33);
+    //lcd07.write(0.25);
+    //lcd07.period_ms(10);
+    pc.baud(9600);
+    calXY();
+    mag.Overwrite_dr_osr(40,16);
+    acc51.Overwrite_dr(200);
+    tsi.Overwrite_ps_nscn(5,5);
+    while(true) {
+                
+        rled = onTime - abs(acc51.getAccX());
+        gled = onTime - abs(acc51.getAccY());
+        mag.getValues(&magX, &magY, &magZ);
+        
+        cout << "MMA8451: " << acc51.getAccX() << "\t" << acc51.getAccY() << "\t" << acc51.getAccZ() << "\n\r" << endl;
+        cout << "MAG3110: " << magX << "\t" << magY << "\t" << magZ << "\n\r" << endl;
+        cout << "MAG3110: " << mag.getHeading() << "\n\r" << endl;
+        wait(holdTime);
+        
+        rled = tsi.readPercentage();
+        gled = tsi.readPercentage();
+        
+        cout << "Touch: " << tsi.readPercentage() << "\n\r" << endl;
+        cout << "SW12: " << SW12 << "\n\r" << endl;
+        cout << "SW32: " << SW32 << "\n\r" << endl;
+        cout << "Light Sensor: " << lightSensor << "\n\r" << endl;
+        wait(holdTime);
+    }
+    return 0;
+}
diff -r 000000000000 -r c8a7071d8692 mbed.lib
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/mbed.lib	Sat Feb 08 22:23:55 2014 +0000
@@ -0,0 +1,1 @@
+http://mbed.org/users/mbed_official/code/mbed/#824293ae5e43