kL46Z-Lab1-lodz

Dependencies:   MMA8451Q USBDevice mbed

Files at this revision

API Documentation at this revision

Comitter:
wue
Date:
Wed Apr 16 13:15:31 2014 +0000
Commit message:
kL46Z-Lab1-lodz

Changed in this revision

MMA8451Q.lib Show annotated file Show diff for this revision Revisions of this file
USBDevice.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.bld Show annotated file Show diff for this revision Revisions of this file
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/MMA8451Q.lib	Wed Apr 16 13:15:31 2014 +0000
@@ -0,0 +1,1 @@
+http://mbed.org/users/JoKer/code/MMA8451Q/#2d14600116fc
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/USBDevice.lib	Wed Apr 16 13:15:31 2014 +0000
@@ -0,0 +1,1 @@
+http://mbed.org/users/mbed_official/code/USBDevice/#5b7d31d9d3f3
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/main.cpp	Wed Apr 16 13:15:31 2014 +0000
@@ -0,0 +1,60 @@
+#include "mbed.h"
+#include "USBMouse.h"
+#include "MMA8451Q.h"
+
+#define LED_ON  0 //outON, pwmON
+#define LED_OFF 1 //outOFF,pwmOFF
+#define PRESS_ON  0
+#define PRESS_OFF 1
+
+#define LED_PERIOD 150      //[ms]
+
+#define MMA8451_I2C_ADDRESS (0x1d<<1)
+
+
+struct KL46_SENSOR_DATA {
+    int     sw1state;
+    int     sw2state;
+    float   accValX;
+    float   accValY;
+    float   accValZ;
+} sensorData;
+
+
+
+int main(void)
+{
+    USBMouse mouse;
+    MMA8451Q acc(PTE25, PTE24, MMA8451_I2C_ADDRESS);
+    DigitalOut gLED(LED_GREEN); //PTD5
+    PwmOut rLED(LED_RED);       //PTE29
+    DigitalIn  sw1(PTC3);  //if(sw1) Release else Press
+    DigitalIn  sw2(PTC12); //while(sw3); wait for Press
+
+    sw1.mode(PullUp);
+    sw2.mode(PullUp);
+    
+    gLED = LED_ON;
+    rLED = LED_OFF;
+    rLED.period(LED_PERIOD);
+    
+    while (1) {
+        sensorData.accValX = acc.getAccX();
+        sensorData.accValY = acc.getAccY();
+        sensorData.accValZ = acc.getAccZ();
+        sensorData.sw1state = sw1;
+        sensorData.sw2state = sw2;
+    
+        
+        rLED = abs(sensorData.accValZ);
+        mouse.move(sensorData.accValX*16.0, sensorData.accValY*16.0);
+
+        if(sensorData.sw1state == PRESS_ON) mouse.press(MOUSE_LEFT);
+        else mouse.release(MOUSE_LEFT);
+
+        if(sensorData.sw2state == PRESS_ON) mouse.press(MOUSE_RIGHT);
+        else mouse.release(MOUSE_RIGHT);
+        
+        wait(0.05);
+    }   
+}
\ No newline at end of file
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/mbed.bld	Wed Apr 16 13:15:31 2014 +0000
@@ -0,0 +1,1 @@
+http://mbed.org/users/mbed_official/code/mbed/builds/6473597d706e
\ No newline at end of file