•	Title: Air Mouse with sensitivity. 

•	Group Members: Sridhar Stalin Kumar 

Rutuj Tanksale

•	Assignment Description: 

•	Case1:Depending upon the three characters (H,L,M) sent from terminal window the sensitivity and the speed of cursor must be controlled by changing the scaling factor for each case . 

•	Case2:The scaling factor or sensitivity is directly given from the terminal window by which sensitivity and speed of cursor is controlled. 

•	API Used: 

•	object.readable():It checks whether the character sent from PC is received. 

•	object.getc():It reads the character that is received. 

•	Object(led)=:It is used for writing the digital values in the Led’s. 

•	Object.getaccY():It gives the accelerometer y-axis value. 

•	Object.getaccX():It gives the accelerometer x-axis value. 

•	Object.readpercentage():It reads the values of slider in the range of 0-100% or 0-1. 

•	Object.press(MOUSE_LEFT): This function allow to do right click in the monitor. 

•	Object.release(MOUSE_RIGHT): This function allow to release after the right click in the monitor. 

•	Object.release(MOUSE_LEFT): This function allow to release after the left click in the monitor. 

•	Object.move(x,y):This function allows to move the cursor depending on the direction the board is moved. 

•	Object.scanf():It checks whether any number is received or present on the serial terminal of the board. 

•	Errors Solved : 

•	Giving accelerometer y axis value to the x-axis of the x variable of object.move(x,y) and x axis value to the y variable of object.move(x,y) . 

•	Outputs Observed: 

•	Whenever ‘h’ is sent from PC then the sensitivity of the cursor was high. 

•	Whenever ‘m’ is sent from PC then the sensitivity of the cursor was medium . 

•	Whenever ‘l’ is sent from PC then the sensitivity of the cursor was low. 

•	Depending upon the value of sensitivity sent from terminal window the sensitivity of cursor was observed. 

•	`Learning Outcomes: 

•	To change the sensitivity of the cursor in the monitor using Terminal window. 

•	To use switch case statements. 

•	To send the number from terminal window and reading it in the board. 

•	To use the slider. 

· Intended code with comments:

a)Sensitivity control with Switch case. #include "mbed.h"

#include "USBMouse.h" #include "MMA8451Q.h" #include "TSISensor.h"

#define MMA8451_I2C_ADDRESS (0x1d<<1) define address of the

accelerometer

Serial pc(USBTX,USBRX);  class and object for serial communication .

BusOut led(PTB18,PTB19,PTD1);   class and object for LEDS.

MMA8451Q acc (PTE25,PTE24,MMA8451_I2C_ADDRESS);   class and

Object for

accelerometer

USBMouse mouse; class and object for mouse

TSISensor tsi;  class and object for TSISensor or slider

int main()

{

float click=0,x=0,y=0;	defining float variables

int s=1;	defining integer variables

char in;   defining integer variables

while(1)

{

if(pc.readable())	if character is received

{

in=pc.getc();	store the read character in variable in

pc.printf("%c\r\n",in); print the read character in the  terminal

window

}

switch(in)

{

case 'h':s=100; if received character is h turn green led on and make s=100

led=0x5;

break;

case 'm':s=50; if received character is m turn blue led on and make s=50

led=0x3;

break;

case 'l':s=10; ; if received character is l turn red led on and make s=10

led=0x6;

break;

default:s=10; if received character is anything other then s=10 break;

}

x=-s*acc.getAccY(); negate and multiply accelerometer y axis with s

y=s*acc.getAccX(); multiply accelerometer x axis with s

mouse.move(x,y); move the cursor as per value of x and y click=tsi.readPercentage(); read the percentage value of sensor if(click>0&&click<=0.4) if click is less than 0.4 then perform

{

mouse.press(MOUSE_RIGHT); right click

wait(0.001);

}

if(click==0)

{

mouse.release(MOUSE_RIGHT); if click is zero then release right

wait(0.001);	and left click.	
mouse.release(MOUSE_LEFT);	
wait(0.001);			
}			
if(click>=0.6)	)	if click is greater then 0.6	

{

mouse.press(MOUSE_LEFT); then perform left click wait(0.001);

}

}

}

b)Sensitivity control with scanf.

#include "mbed.h" #include "USBMouse.h" #include "MMA8451Q.h" #include "TSISensor.h"

#define MMA8451_I2C_ADDRESS (0x1d<<1) Serial pc(USBTX,USBRX);

BusOut led(PTB18,PTB19,PTD1);

MMA8451Q acc (PTE25,PTE24,MMA8451_I2C_ADDRESS); USBMouse mouse;

TSISensor tsi;

int main()

{

float click=0; float x=0; float y=0;

int s=10;

while(1)

{

if(pc.readable())

{

pc.scanf("%d",&s); store the scanned number  in  
			            variable s.
pc.getc();   along with the number the terminal sends 
                              
   the /r or /n,this will store that character.

}

x=-s*acc.getAccY(); y=s*acc.getAccX(); mouse.move(x,y); click=tsi.readPercentage(); if(click>0&&click<=0.4)

{

mouse.press(MOUSE_RIGHT);

wait(0.001);

}

if(click==0)

{

mouse.release(MOUSE_RIGHT); wait(0.001); mouse.release(MOUSE_LEFT); wait(0.001);

}

if(click>=0.6)

{

mouse.press(MOUSE_LEFT); wait(0.01);

}

}

}