Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Dependencies: MMA8451Q USBDevice mbed
main.cpp
00001 #include "mbed.h" 00002 #include "USBMouse.h" 00003 #include "MMA8451Q.h" 00004 00005 #define LED_ON 0 //outON, pwmON 00006 #define LED_OFF 1 //outOFF,pwmOFF 00007 #define PRESS_ON 0 00008 #define PRESS_OFF 1 00009 00010 #define LED_PERIOD 150 //[ms] 00011 00012 #define MMA8451_I2C_ADDRESS (0x1d<<1) 00013 00014 00015 struct KL46_SENSOR_DATA { 00016 int sw1state; 00017 int sw2state; 00018 float accValX; 00019 float accValY; 00020 float accValZ; 00021 } sensorData; 00022 00023 00024 00025 int main(void) 00026 { 00027 USBMouse mouse; 00028 MMA8451Q acc(PTE25, PTE24, MMA8451_I2C_ADDRESS); 00029 DigitalOut gLED(LED_GREEN); //PTD5 00030 PwmOut rLED(LED_RED); //PTE29 00031 DigitalIn sw1(PTC3); //if(sw1) Release else Press 00032 DigitalIn sw2(PTC12); //while(sw3); wait for Press 00033 00034 sw1.mode(PullUp); 00035 sw2.mode(PullUp); 00036 00037 gLED = LED_ON; 00038 rLED = LED_OFF; 00039 rLED.period(LED_PERIOD); 00040 00041 while (1) { 00042 sensorData.accValX = acc.getAccX(); 00043 sensorData.accValY = acc.getAccY(); 00044 sensorData.accValZ = acc.getAccZ(); 00045 sensorData.sw1state = sw1; 00046 sensorData.sw2state = sw2; 00047 00048 00049 rLED = abs(sensorData.accValZ); 00050 mouse.move(sensorData.accValX*16.0, sensorData.accValY*16.0); 00051 00052 if(sensorData.sw1state == PRESS_ON) mouse.press(MOUSE_LEFT); 00053 else mouse.release(MOUSE_LEFT); 00054 00055 if(sensorData.sw2state == PRESS_ON) mouse.press(MOUSE_RIGHT); 00056 else mouse.release(MOUSE_RIGHT); 00057 00058 wait(0.05); 00059 } 00060 }
Generated on Wed Jul 20 2022 10:35:27 by
1.7.2