test
Dependencies: MMA8451Q RN42 mbed-rtos mbed
main.cpp@0:6152f4e4c841, 2013-12-16 (annotated)
- Committer:
- trisjph
- Date:
- Mon Dec 16 10:26:46 2013 +0000
- Revision:
- 0:6152f4e4c841
inital;
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
trisjph | 0:6152f4e4c841 | 1 | #include "mbed.h" |
trisjph | 0:6152f4e4c841 | 2 | #include "rtos.h" |
trisjph | 0:6152f4e4c841 | 3 | #define MMA8451_I2C_ADDRESS (0x1d<<1) |
trisjph | 0:6152f4e4c841 | 4 | #include "MMA8451Q.h" |
trisjph | 0:6152f4e4c841 | 5 | #include "RN42.h" |
trisjph | 0:6152f4e4c841 | 6 | #define PI 3.14159265 |
trisjph | 0:6152f4e4c841 | 7 | |
trisjph | 0:6152f4e4c841 | 8 | PwmOut led1(LED1); |
trisjph | 0:6152f4e4c841 | 9 | MMA8451Q acc(PTE25, PTE24, MMA8451_I2C_ADDRESS); |
trisjph | 0:6152f4e4c841 | 10 | AnalogIn ain(PTC2); |
trisjph | 0:6152f4e4c841 | 11 | Serial pc(USBTX, USBRX); |
trisjph | 0:6152f4e4c841 | 12 | //USBMouseKeyboard key_mouse; |
trisjph | 0:6152f4e4c841 | 13 | Mutex BT_mutex; |
trisjph | 0:6152f4e4c841 | 14 | //USBHID key_mouse; |
trisjph | 0:6152f4e4c841 | 15 | |
trisjph | 0:6152f4e4c841 | 16 | void click_thread(void const *args) |
trisjph | 0:6152f4e4c841 | 17 | { |
trisjph | 0:6152f4e4c841 | 18 | int press; |
trisjph | 0:6152f4e4c841 | 19 | while(true) { |
trisjph | 0:6152f4e4c841 | 20 | if( (ain.read()>0.3) && (press == 0) ) { |
trisjph | 0:6152f4e4c841 | 21 | press = 1; |
trisjph | 0:6152f4e4c841 | 22 | led1 != led1; |
trisjph | 0:6152f4e4c841 | 23 | pc.printf("%i\n", press); |
trisjph | 0:6152f4e4c841 | 24 | BT_mutex.lock(); |
trisjph | 0:6152f4e4c841 | 25 | //key_mouse.press(MOUSE_LEFT); |
trisjph | 0:6152f4e4c841 | 26 | BT_mutex.unlock(); |
trisjph | 0:6152f4e4c841 | 27 | } else if ( (ain.read()<0.3) && (press == 1) ) { |
trisjph | 0:6152f4e4c841 | 28 | press = 0; |
trisjph | 0:6152f4e4c841 | 29 | pc.printf("%i\n", press); |
trisjph | 0:6152f4e4c841 | 30 | BT_mutex.lock(); |
trisjph | 0:6152f4e4c841 | 31 | // key_mouse.release(MOUSE_LEFT); |
trisjph | 0:6152f4e4c841 | 32 | BT_mutex.unlock(); |
trisjph | 0:6152f4e4c841 | 33 | } |
trisjph | 0:6152f4e4c841 | 34 | Thread::wait(100); |
trisjph | 0:6152f4e4c841 | 35 | } |
trisjph | 0:6152f4e4c841 | 36 | } |
trisjph | 0:6152f4e4c841 | 37 | |
trisjph | 0:6152f4e4c841 | 38 | void mouse_thread(void const *args) |
trisjph | 0:6152f4e4c841 | 39 | { |
trisjph | 0:6152f4e4c841 | 40 | while(true) { |
trisjph | 0:6152f4e4c841 | 41 | |
trisjph | 0:6152f4e4c841 | 42 | BT_mutex.lock(); |
trisjph | 0:6152f4e4c841 | 43 | RN42_mouse(-acc.getAccX()*100, acc.getAccY()*100); |
trisjph | 0:6152f4e4c841 | 44 | BT_mutex.unlock(); |
trisjph | 0:6152f4e4c841 | 45 | Thread::wait(10); |
trisjph | 0:6152f4e4c841 | 46 | } |
trisjph | 0:6152f4e4c841 | 47 | } |
trisjph | 0:6152f4e4c841 | 48 | |
trisjph | 0:6152f4e4c841 | 49 | void heartbeat_thread(void const *args) |
trisjph | 0:6152f4e4c841 | 50 | { |
trisjph | 0:6152f4e4c841 | 51 | int i; |
trisjph | 0:6152f4e4c841 | 52 | led1.period(0.001); |
trisjph | 0:6152f4e4c841 | 53 | while(true) { |
trisjph | 0:6152f4e4c841 | 54 | for(i=0; i<180; i++) { |
trisjph | 0:6152f4e4c841 | 55 | led1 = sin(i*PI/180); |
trisjph | 0:6152f4e4c841 | 56 | Thread::wait(10); |
trisjph | 0:6152f4e4c841 | 57 | } |
trisjph | 0:6152f4e4c841 | 58 | } |
trisjph | 0:6152f4e4c841 | 59 | |
trisjph | 0:6152f4e4c841 | 60 | } |
trisjph | 0:6152f4e4c841 | 61 | |
trisjph | 0:6152f4e4c841 | 62 | int main() |
trisjph | 0:6152f4e4c841 | 63 | { |
trisjph | 0:6152f4e4c841 | 64 | pc.baud(115200); |
trisjph | 0:6152f4e4c841 | 65 | RN42_init(); |
trisjph | 0:6152f4e4c841 | 66 | //RN42_HID(); |
trisjph | 0:6152f4e4c841 | 67 | //RN42_connect(); |
trisjph | 0:6152f4e4c841 | 68 | |
trisjph | 0:6152f4e4c841 | 69 | //Thread click(click_thread); |
trisjph | 0:6152f4e4c841 | 70 | Thread mouse(mouse_thread); |
trisjph | 0:6152f4e4c841 | 71 | Thread heartbeat(heartbeat_thread); |
trisjph | 0:6152f4e4c841 | 72 | |
trisjph | 0:6152f4e4c841 | 73 | led1 = 1.0; |
trisjph | 0:6152f4e4c841 | 74 | |
trisjph | 0:6152f4e4c841 | 75 | while (true) { |
trisjph | 0:6152f4e4c841 | 76 | } |
trisjph | 0:6152f4e4c841 | 77 | } |