game

Dependencies:   DebounceIn MMA8451Q USBDevice mbed

Committer:
psddtgb
Date:
Wed Sep 16 00:06:41 2015 +0000
Revision:
0:1bc96dc5dc31
game

Who changed what in which revision?

UserRevisionLine numberNew contents of line
psddtgb 0:1bc96dc5dc31 1 #include "mbed.h"
psddtgb 0:1bc96dc5dc31 2 #include "DebounceIn.h"
psddtgb 0:1bc96dc5dc31 3 #include "USBKeyboard.h"
psddtgb 0:1bc96dc5dc31 4 #include "MMA8451Q.h"
psddtgb 0:1bc96dc5dc31 5
psddtgb 0:1bc96dc5dc31 6 PinName const SDA = PTE25;
psddtgb 0:1bc96dc5dc31 7 PinName const SCL = PTE24;
psddtgb 0:1bc96dc5dc31 8 #define MMA8451_I2C_ADDRESS (0X1d<<1)
psddtgb 0:1bc96dc5dc31 9 Serial pc(USBTX, USBRX);
psddtgb 0:1bc96dc5dc31 10
psddtgb 0:1bc96dc5dc31 11 USBKeyboard keyboard;
psddtgb 0:1bc96dc5dc31 12
psddtgb 0:1bc96dc5dc31 13 DigitalOut ledr(LED_RED);
psddtgb 0:1bc96dc5dc31 14 DigitalOut ledg(LED_GREEN);
psddtgb 0:1bc96dc5dc31 15 DigitalOut ledb(LED_BLUE);
psddtgb 0:1bc96dc5dc31 16
psddtgb 0:1bc96dc5dc31 17 DebounceIn pb1(D2);
psddtgb 0:1bc96dc5dc31 18 DebounceIn pb2(D3);
psddtgb 0:1bc96dc5dc31 19 DebounceIn pb3(D4);
psddtgb 0:1bc96dc5dc31 20 DebounceIn pb4(D5);
psddtgb 0:1bc96dc5dc31 21 DebounceIn pb5(D6);
psddtgb 0:1bc96dc5dc31 22 DebounceIn pb6(D7);
psddtgb 0:1bc96dc5dc31 23 DebounceIn pb7(D8);
psddtgb 0:1bc96dc5dc31 24 DebounceIn pbs(D9);
psddtgb 0:1bc96dc5dc31 25 DebounceIn pbm(D10);
psddtgb 0:1bc96dc5dc31 26
psddtgb 0:1bc96dc5dc31 27 int main()
psddtgb 0:1bc96dc5dc31 28 {
psddtgb 0:1bc96dc5dc31 29 int m = 1;
psddtgb 0:1bc96dc5dc31 30 ledr = 1;
psddtgb 0:1bc96dc5dc31 31 ledg = 1;
psddtgb 0:1bc96dc5dc31 32 ledb = 1;
psddtgb 0:1bc96dc5dc31 33 // Use internal pullup for pushbutton
psddtgb 0:1bc96dc5dc31 34 pb1.mode(PullUp);
psddtgb 0:1bc96dc5dc31 35 pb2.mode(PullUp);
psddtgb 0:1bc96dc5dc31 36 pb3.mode(PullUp);
psddtgb 0:1bc96dc5dc31 37 pb4.mode(PullUp);
psddtgb 0:1bc96dc5dc31 38 pb5.mode(PullUp);
psddtgb 0:1bc96dc5dc31 39 pb6.mode(PullUp);
psddtgb 0:1bc96dc5dc31 40 pb7.mode(PullUp);
psddtgb 0:1bc96dc5dc31 41 pbs.mode(PullUp);
psddtgb 0:1bc96dc5dc31 42 pbm.mode(PullUp);
psddtgb 0:1bc96dc5dc31 43
psddtgb 0:1bc96dc5dc31 44 // Delay for initial pullup to take effect
psddtgb 0:1bc96dc5dc31 45 wait(.001);
psddtgb 0:1bc96dc5dc31 46
psddtgb 0:1bc96dc5dc31 47 MMA8451Q acc(SDA, SCL, MMA8451_I2C_ADDRESS);
psddtgb 0:1bc96dc5dc31 48
psddtgb 0:1bc96dc5dc31 49 float x;
psddtgb 0:1bc96dc5dc31 50 float y;
psddtgb 0:1bc96dc5dc31 51 float z;
psddtgb 0:1bc96dc5dc31 52
psddtgb 0:1bc96dc5dc31 53 while(true)
psddtgb 0:1bc96dc5dc31 54 {
psddtgb 0:1bc96dc5dc31 55 x = acc.getAccX();
psddtgb 0:1bc96dc5dc31 56 y = acc.getAccY();
psddtgb 0:1bc96dc5dc31 57 z = acc.getAccZ();
psddtgb 0:1bc96dc5dc31 58 keyboard.printf("X = %1.2f ", x);
psddtgb 0:1bc96dc5dc31 59 keyboard.printf("Y = %1.2f ", y);
psddtgb 0:1bc96dc5dc31 60 keyboard.printf("Z = %1.2f\n", z);
psddtgb 0:1bc96dc5dc31 61 wait(0.05f);
psddtgb 0:1bc96dc5dc31 62 }
psddtgb 0:1bc96dc5dc31 63
psddtgb 0:1bc96dc5dc31 64 }