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-rtos mbed
Fork of Super_Hans_USB by
main.cpp
- Committer:
- anuragdhutti
- Date:
- 2013-12-27
- Revision:
- 1:e1a1bf8c36d9
- Parent:
- 0:d270a9981e69
File content as of revision 1:e1a1bf8c36d9:
#include "mbed.h"
#include "rtos.h"
#define MMA8451_I2C_ADDRESS (0x1d<<1)
#include "MMA8451Q.h"
#include "USBMouseKeyboard.h"
#define PI 3.14159265
PwmOut led1(LED2);
MMA8451Q acc(PTE25, PTE24, MMA8451_I2C_ADDRESS);
AnalogIn ain(PTC2);
Serial pc(USBTX, USBRX);
USBMouseKeyboard key_mouse;
Mutex USB_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);
USB_mutex.lock();
key_mouse.press(MOUSE_LEFT);
USB_mutex.unlock();
} else if ( (ain.read()<0.3) && (press == 1) ) {
press = 0;
pc.printf("%i\n", press);
USB_mutex.lock();
key_mouse.release(MOUSE_LEFT);
USB_mutex.unlock();
}
Thread::wait(100);
}
}
void mouse_thread(void const *args)
{
while(true) {
USB_mutex.lock();
pc.printf("%f, %f, %f\n", acc.getAccX(), acc.getAccY(), acc.getAccZ() );
if (acc.getAccZ()
key_mouse.move(-acc.getAccZ()*10, 0);
key_mouse.move(0, acc.getAccX()*10);
USB_mutex.unlock();
Thread::wait(1);
}
}
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()
{
//Thread click(click_thread);
Thread mouse(mouse_thread);
Thread heartbeat(heartbeat_thread);
led1 = 1.0;
while (true) {
}
}
