h

Dependencies:   MMA7660 USBDevice mbed

Fork of lecture2_demo2 by Colin Johnson

Revision:
7:23de08e003ec
Parent:
5:03a4211d593a
Child:
8:d79a78d6b922
diff -r 17871da2a7e4 -r 23de08e003ec main.cpp
--- a/main.cpp	Fri Mar 01 13:23:58 2013 +0000
+++ b/main.cpp	Wed Oct 28 03:32:05 2015 +0000
@@ -1,21 +1,24 @@
 #include "mbed.h"
 #include "USBKeyboard.h"
- 
-//LED1: NUM_LOCK
-//LED2: CAPS_LOCK
-//LED3: SCROLL_LOCK
-BusOut leds(LED1, LED2, LED3);
- 
-//USBKeyboard
+#include "MMA7660.h" /* for the accelerometer */
+
 USBKeyboard keyboard;
- 
-int main(void) {
+MMA7660 MMA(D14, D15); /* accelerometer */
+
+int main(void)
+{
+    float x,y,countdown;
+    countdown = 0.0;
     while (1) {
-        keyboard.mediaControl(KEY_VOLUME_DOWN);
-        keyboard.printf("Hello World from Mbed\r\n");
-        keyboard.keyCode('s', KEY_CTRL);
-        keyboard.keyCode(KEY_CAPS_LOCK);
-        wait(1);
-        leds = keyboard.lockStatus();
+        x = MMA.x();
+        y = MMA.y();
+        if (y>0.6f) { keyboard.mediaControl(KEY_VOLUME_DOWN); }
+        if (y<-0.6f) { keyboard.mediaControl(KEY_VOLUME_UP); }
+        if ((abs(x)>0.6f)&&(countdown<=0.0f)) {
+            keyboard.mediaControl(KEY_PLAY_PAUSE); 
+            countdown = 10.0f;
+            }
+        countdown -= 1.0f;
+        wait (0.1);
     }
 }
\ No newline at end of file