Go Down

Topic: Mouse cursor control using push button. (Read 811 times) previous topic - next topic

Hard01

Hey Forum,
             I was wondering if any talent out there could help me with some improvisation on Joystick as  mouse control project with push button emulation. I need some brain to think on:

              I have two push button, one joystick and Leonardo circuit board. I want joystick to operate the same way as it functions but when i press one of the two push button my mouse cursor should run to the right top corner of the screen and when i press another push button it should run to the bottom right side of the screen. If any one of you could help me with suggestions. Program without push button integration is as follows:

#include <Mouse.h>
int horizPin = A0;
int vertPin = A1;
int selPin = 9;

int vertZero, horizZero;
int vertValue, horizValue;
const int sensitivity = 200;
 int mouseClickFlag = 0;

void setup() {                           // put your setup code here, to run once:
// Serial.begin (9600);
 pinMode (horizPin, INPUT);
 pinMode (vertPin, INPUT); 
pinMode (selPin, INPUT); 
digitalWrite (selPin, HIGH);  delay (1000); 
vertZero = analogRead (vertPin); 
horizZero = analogRead (horizPin); 
 }

void loop() {                             // put your main code here, to run repeatedly: 
vertValue = analogRead (vertPin) - vertZero;
 horizValue = analogRead (horizPin) - horizZero;
 
if (vertValue != 0)     
 Mouse.move (0, (vertValue/ sensitivity)*-1, 0);
 if (horizValue != 0)     
Mouse.move ((horizValue/ sensitivity)*-1, 0, 0);
 
((digitalRead(selPin)==0) && (!mouseClickFlag))  { 
  mouseClickFlag = 1;
Mouse.press (MOUSE_LEFT);   
  }
  else if ((digitalRead (selPin)) && (mouseClickFlag))  {
mouseClickFlag = 0;
Mouse.release (MOUSE_LEFT);  }
 }
Thank You !!!

Go Up