Mouse from Joystick on Ice

8) I am making a custom gaming mouse with a Joystick, after a whole day of frade wires and coding, I got it working upto moving the mouse. I have it so when the stick is nuetral/mid/untouched it is suppost to go to center screen and when move the mouse matches the stick corner to corner and back to center lx= x;// Record last X value, ly = y;// Record last Y value; x = map(analogRead(A0), 160, 760, 0, 1280)-640;// turns joystick into screen x width in pixils for coordinates y = map(analogRead(A1), 875, 155, 0, 768)-384;// turns joystick into screen y hight in pixils for coordinates; Mouse.move(x-lx,y-ly);// Moves the mouse by the pixil change That is the code I am using for my Teensy 2.0, I know that Mouse.move() move the mouse and doesnot mean coordinates, which would help me a lot if it did, and that the value of change is limited by -127 to 127; which with this shouldn't be a problem though with a comand to center the mouse each integer of the value seems to move by two pixils but the same doesn't acure with the joystick. :0 THE MAIN PROBLEM IS for some reason this methoid of finding the change it coordinats isn't working, it moves the mouse acoordingly with a bit a shaking from analog reading, BUT =( it causes the problem where the mouse wants to move to the left and inches upwards. Is there a better way/ I've tried to research :astonished: but too tiered, I went to bed :sleeping: and fix it up and tried more research but I came up dry. :disappointed_relieved: Any advice wold be nice but at lest it isn't skating around like an ice skater like it was last night and clicking evergy where till it crashed my computer twice! =( =( =(

Without seeing the whole sketch and know what else is involved (Is the ‘virtual mouse’ connected to a PC? What OS is it running?) it is hard to guess why it isn’t working. However, trying to generate relative moves to get to an absolute position is always going to be problematic.

Assuming you’re trying to drive a mouse in Windows, wouldn’t it be easier to write a Windows app that receives ‘mouse move’ commands in absolute coordinates from the Arduino and calls SetCursorPos() to move the mouse cursor to that position? That ought to work better than generating windows events, which I guess is what you’re doing currently. In fact you could eliminate the Arduino completely and just interface to the joystick directly. Or maybe you’re already doing that - you’ve told us almost nothing about your setup so I can only guess what is going on.

Sorry for the lack of info I was still tiered I am using a Teensy 2.0 hooked up to the thumb pad that is re-wired into a matrix and to the potentiometers directly and i have it all compackted in the origanal body with the minimum amount of modification; I run a windows XP and Ubuntu 11.04 linux, works on both just fine I did this as a way to get acustom to the arduino revolution so this is my first time with Arduino/Teensyduino I will take into mind the idea of a program in the computer, I am uncerten am uncertan how to go about that but i will do my research thanks and here is the code, sorry for the slop :sweat_smile: also i use capasitators to smooth interaction, glowing power indicator lights that flicker from delay in the code and the voltage from the potetiometers, can the upto 5 volt charge on an unpluged teensy cause damage? i know not to but forgot to put a safety diode, but there seems to act just fine from the built in diodes and it eventualy looses their charge completly after 13 seconds, thanks for the help and advise, apreseated, sorry for bad spelling :sleeping:, have a nice day or night where ever you guys or at thx,,,,,,,,,,,,,,,,,,,,,,,, here's my program, uses 23% of the memorie, wait to much so here up to loop void;

/*

created 2012 by Ben Zuniga

*/

// variables for led indicater for power by fading in and out int powerled = 10; // the number of the LED pin that is being used and subports PWM, 9 and 10 // Variables will change: int up = 1; int fade = 0; // ledState used to set the LED long previousMillis = 0; // will store last time LED was updated

// the follow variables is a long because the time, measured in miliseconds, // will quickly become a bigger number than can be stored in an int. constant int rate = 5; long period = 30; // interval at which to blink (milliseconds) best 30 but code before it my go over that causing twiching when darkening // variables to find screen cordinats with the stick int mz = 0; int mx = 0; int my = 0;

int msleft = 0;// tracker int msright = 0; int dleft = 0; int dright = 0; int dup = 0; int ddown = 0; int sc = 0; int scu = 0; int scd = 0; long x = 640; long y = 384;// i have a 1280 by 768 screen so this is mid int lx = 0; int ly = 0; int i = 0; int t = 0; int r = 0; int s = 0;

void setup(){ //++++++++++++++++++++++++++++++++++++ Serial.begin(9600); pinMode(9, OUTPUT); pinMode(4, OUTPUT); pinMode(3, OUTPUT); pinMode(2, INPUT_PULLUP); pinMode(1, INPUT_PULLUP); pinMode(0, INPUT_PULLUP); pinMode(6, INPUT_PULLUP); pinMode(11,OUTPUT); digitalWrite(11, HIGH); }//++++++++++++++++++++++++++++++++++++

here’s the rest
serial for debuging
void loop()
{//++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
// here is where you’d put code that needs to be running all the time.::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::+
if (digitalRead(6) == LOW)
{
if (i ==0){
for(i=0; i<10; i++)
{
Mouse.move(-127, -127);
}
Mouse.move( 127, 127);
Mouse.move( 127, 65);
Mouse.move( 66, 0);
}}
else
{ i = 0;}
digitalWrite(3, HIGH);
digitalWrite(9, LOW);
digitalWrite(4, HIGH);

if (digitalRead(2)== LOW)
{
if (scd == 0)
{
Serial.println(“D;”);
Mouse.scroll(-1);
scd = 1;
};
}
else
{
scd = 0;
};

if (digitalRead(1)== LOW)
{
if (dup == 0)
{
Serial.println(“DU;”);
Keyboard.set_key1(KEY_UP);
dup = 1;
};
}
else
{
Keyboard.set_key1(0);
dup = 0;
};
if (digitalRead(0)== LOW)
{
if (dright == 0)
{
Serial.println(“DR;”);
Keyboard.set_key2(KEY_RIGHT);
dright = 1;
};
}
else
{
Keyboard.set_key2(0);
dright = 0;
};
digitalWrite(9, HIGH);
digitalWrite(4, LOW);
digitalWrite(3, HIGH);

if (digitalRead(2)== LOW)
{
if (sc == 0)
{
Serial.println(“S;”);
sc = 1;
};
}
else
{
sc = 0;
};

if (digitalRead(1)== LOW)
{
if (dleft == 0)
{
Serial.println(“DL;”);
Keyboard.set_key3(KEY_LEFT);
dleft = 1;
};
}
else
{
Keyboard.set_key3(0);
dleft = 0;
};
if (digitalRead(0)== LOW)
{
if (msright == 0)
{
Serial.println(“R;”);
msright = 1;
};
}
else
{
msright = 0;
};
digitalWrite(4, HIGH);
digitalWrite(3, LOW);
digitalWrite(9, HIGH);

if (digitalRead(2)== LOW)
{
if (scu == 0)
{
Serial.println(“UP;”);
Mouse.scroll(1);
scu = 1;
};
}
else
{
scu
= 0;
};

if (digitalRead(1)== LOW)
{
if (ddown == 0)
{
Serial.println(“DD”);
Keyboard.set_key4(KEY_DOWN);
ddown = 1;
};
}
else
{
Keyboard.set_key4(0);
ddown = 0;
};
if (digitalRead(0)== LOW)
{
if (msleft == 0)
{
Serial.println(“T;”);
msleft = 1;
};
}
else
{
msleft = 0;
};
Mouse.set_buttons(msleft,sc,msright);
Keyboard.send_now();

lx= x;
ly = y;
x = map(analogRead(A0), 160, 760, 0, 1280);
y = map(analogRead(A1), 875, 155, 0, 768);
Mouse.move(x-lx,y-ly);

// // converet to usable #'s like mouse cordinats ::+

//end main ::+
//::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::+
unsigned long currentMillis = millis();// +
if (currentMillis - previousMillis > period)// power indicator that fades in and out +
{//----------------------------------------------------------------------------------------------------------------------------------------------------//+
// save the last time you blinked the LED boxes indicate complete ifs //+
previousMillis = currentMillis; //+
//if going up the increase by rate, //+
if (up == 1) //+
{//----------------------------------------------------------------------------------------------------------------------------------------------// |+
fade = fade + rate; // |+
if (fade >= 255) // check to if over or equal to max value of fade of 255 then change to decrease and set fade to max // |+
{//----------------------------------------------------------------------------------------------------------------------------------------// | |+
up = 0; // | |+
fade = 255;
// | |+
}//----------------------------------------------------------------------------------------------------------------------------------------// | |+
analogWrite(powerled,fade); // |+
}//----------------------------------------------------------------------------------------------------------------------------------------------// |+
else//*********************************************************************************************************************************************00//+
{//==============================================================================================================================================\ |+
fade = fade - rate; //and vis-versa for the fading ==== & \ is the if’s else \ |+
if (fade <= 0)// \ |+
{//----------------------------------------------------------------------------------------------------------------------------------------// ) |+
up = 1; // ) |+
fade = 0;
// ) |+
}//----------------------------------------------------------------------------------------------------------------------------------------// ) |+
analogWrite(powerled,fade);// \ |+
}//==============================================================================================================================================\ |+
}//----------------------------------------------------------------------------------------------------------------------------------------------------//+
}//++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++