test

Dependencies:   MMA8451Q RN42 mbed-rtos mbed

Revision:
0:6152f4e4c841
diff -r 000000000000 -r 6152f4e4c841 main.cpp
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/main.cpp	Mon Dec 16 10:26:46 2013 +0000
@@ -0,0 +1,77 @@
+#include "mbed.h"
+#include "rtos.h"
+#define MMA8451_I2C_ADDRESS (0x1d<<1)
+#include "MMA8451Q.h"
+#include "RN42.h"
+#define PI 3.14159265
+
+PwmOut led1(LED1);
+MMA8451Q acc(PTE25, PTE24, MMA8451_I2C_ADDRESS);
+AnalogIn ain(PTC2);
+Serial pc(USBTX, USBRX);
+//USBMouseKeyboard key_mouse;
+Mutex BT_mutex;
+//USBHID key_mouse;
+
+void click_thread(void const *args)
+{
+    int press;
+    while(true) {
+        if( (ain.read()>0.3) && (press == 0) ) {
+            press = 1;
+            led1 != led1;
+            pc.printf("%i\n", press);
+            BT_mutex.lock();
+            //key_mouse.press(MOUSE_LEFT);
+            BT_mutex.unlock();
+        } else if ( (ain.read()<0.3) && (press == 1) ) {
+            press = 0;
+            pc.printf("%i\n", press);
+            BT_mutex.lock();
+           // key_mouse.release(MOUSE_LEFT);
+            BT_mutex.unlock();
+        }
+        Thread::wait(100);
+    }
+}
+
+void mouse_thread(void const *args)
+{
+    while(true) {
+
+        BT_mutex.lock();
+        RN42_mouse(-acc.getAccX()*100, acc.getAccY()*100);
+        BT_mutex.unlock();
+        Thread::wait(10);
+    }
+}
+
+void heartbeat_thread(void const *args)
+{
+    int i;
+    led1.period(0.001);
+    while(true) {
+        for(i=0; i<180; i++) {
+            led1 = sin(i*PI/180);
+            Thread::wait(10);
+        }
+    }
+
+}
+
+int main()
+{
+    pc.baud(115200);
+    RN42_init();
+    //RN42_HID();
+    //RN42_connect();
+
+    //Thread click(click_thread);
+    Thread mouse(mouse_thread);
+    Thread heartbeat(heartbeat_thread);
+
+    led1 = 1.0;
+
+    while (true) {
+    }
+}