i want to make a accelerometer controlled mouse. i want the pointer to move with the same acceleration as my accelerometer and in the same direction as that. i have an arduino UNO to get accel-meter readings (X,Y,Z) . i wrote a C++ code for serial communication with the arduino. which is working fine. i even calibrated my the accelerometer to get correct reading for 1g. but the problem is i cant match the real life acceleration with the mouse acceleration.
the c++ code for mouse movement is --
#define _WIN32_WINNT 0x0500
#include <windows.h>
#include <stdio.h>
#include <iostream>
#include <conio.h>
#include <stdlib.h>
#include "tserial.h"
#include "bot_control.h"
#include <math.h>
using std::cout;
serial comm;
POINT p; //pointer for position (global)
void show()
{
HWND hwnd = GetConsoleWindow();
SetWindowPos(
hwnd,
HWND_TOPMOST,
25,
25,
110,
200,
0
);
}
void checkpos()
{
GetCursorPos(&p); //get current mouse position
}
int map(int x, int in_min, int in_max, int out_min, int out_max)
{
return (x - in_min) * (out_max - out_min) / (in_max - in_min) + out_min;
}
int constrain(int a, int lb,int ub)
{ if((a>=lb)&&(a<=ub))
return a;
else if(a>ub)
return ub;
else if(a<lb)
return lb;
}
int main(){
int x,y,z;
//show();
printf("MOUSE");
comm.startDevice("COM3", 9600);
while(1)
/* “COM2” refers to the com port in which the USB to SERIAL port is attached. It is shown by right clicking on my computer, then going to properties and then device manager. 9600 is the baud-rate */
{ float a=0,b=0;
int c=0,d=0;
x=comm.get_char();
y=comm.get_char();
z=comm.get_char();
// if(z<1)
//z=z-37;
// if(y<1)
// y=y-87;
//z=map(z,-102,102,172,501);
// y=map(y,-125,125,172,501);
printf("X= %d Y= %d Z= %d \n",x,y,z);
checkpos();
a=(y*5*980*0.01)/(1024*2.45);
c=p.x+a;
b=(z*5*980*0.01)/(1024*2.45);
d=p.y+b;
SetCursorPos(c,d);
cout<<" "<<a<<" "<<b<<'\n';
cout<<" "<<c<<" "<<d<<'\n';
}
//comm.send_data(data); //The data is sent through the port
comm.stopDevice(); //The device is closed down
}
where tserial.h and bot_control.h is from the link below:- http://ift.tt/1fVuT4Q
pls help meee I am stuck
Aucun commentaire:
Enregistrer un commentaire