Rotary encoders to control the mouse cursor.

can you tel me please how did you solved the problem with "drag and drop"? (mouse press an move).

thanks...

Hello Fredemo, Are you Ok?

Can you send me all code, please?

and pictures of the project.

Thank you.

Hi, i am trying to make too rotary encoders to emulate the mouse movement, but its not easy! So i find this topic here. Can i got the code and the shcematics from you, and try to build this project. Will be very nice!!! thanks! if anyone have it, just send it on the my e-mail, or post it here.

If anyone is intrested or visit this thread, sorry i totaly forgot about it. I got everything to work the way i wanted it.

It was a while ago and since then I've learned how to properly back up things. The final code have sadly been lost due to failed hardware but I found one of my prototypes that i think might work. Another thing i have learnt is to propperly comment my code... Have fun with this mess.

// Prototype 4
#include <Mouse.h>

// Encoder

  int val; 
 int encoder0PinA = 3;
 int encoder0PinB = 4;
 int encoder0Pos = 0;
 int encoder0PinALast = LOW;
 int n = LOW;


void setup(){


pinMode(5, INPUT);                                          // x1 x10 mouse cursour movement
pinMode(6, INPUT);                                          // x
pinMode(7, INPUT);                                          // y

 // Encoder setup
 
pinMode (encoder0PinA,INPUT);
pinMode (encoder0PinB,INPUT);
Serial.begin (9600);

 
 }

void loop(){

// x/y, lmb and mouse.begin

if(digitalRead(6) == HIGH && digitalRead(7) == LOW)
{       
  // x axis, mouse.begin, mouse.press
  Mouse.begin();
  Mouse.press(MOUSE_LEFT);
}

if(digitalRead(6) == LOW && digitalRead(7) == HIGH)
{       
  // y axis, mouse.begin, mouse.press
  Mouse.begin();
  Mouse.press(MOUSE_LEFT);
}

if(digitalRead(6) == LOW && digitalRead(7) == LOW)
{        
  //  off
  Mouse.release(MOUSE_LEFT);
  Mouse.end();
}


// Encoder

 n = digitalRead(encoder0PinA);
   if ((encoder0PinALast == LOW) && (n == HIGH)) 
   {
     if (digitalRead(encoder0PinB) == LOW) 
     {
       encoder0Pos--;
     } 
     else 
     {
       encoder0Pos++;
     }
    
   } 
   encoder0PinALast = n;

// Cursour movment


if (digitalRead(5) == HIGH) 
{                                
  // x1 cursour movement
  if (digitalRead(6) == HIGH)
  {                                     
    // x+
   if (encoder0Pos++) 
   {
     Mouse.move(+1,0,0);
   }
  
   if (encoder0Pos--) 
   {                                              
    // x-
     Mouse.move(-1, 0,0);
   }
  }

  if (digitalRead(7) == HIGH)
  {                                   
   // y+
   if (encoder0Pos++) 
   {
     Mouse.move(0,+1,0);
    }
  
   if (encoder0Pos--) 
  {                                            
    // y-
     Mouse.move(0, -1,0);
   }
  }
}
 
if (digitalRead(5) == LOW) 
{                                 
  // x10 cursour movment
  if (digitalRead(6) == HIGH)
  {                                    
   // x+
   if (encoder0Pos++) 
   {
     Mouse.move(+10,0,0);
    }
  
    if (encoder0Pos--) 
    {                                             
     // x-
     Mouse.move(-10, 0,0);
    }
   }

  if (digitalRead(7) == HIGH)
  {                                   
   // y+
   if (encoder0Pos++) 
   {
     Mouse.move(0,+10,0);
    }
  
   if (encoder0Pos--) 
   {                                             
   // y-
   Mouse.move(0, -10,0);  
    }           
  }
}
     
}

I also found this, prototype 3.

/*  

on off on switch for x and y  axis, it also toggle the mouse.begin/lmb on and off.


*/


#include <Mouse.h>

// Encoder

  int val; 
 int encoder0PinA = 3;
 int encoder0PinB = 4;
 int encoder0Pos = 0;
 int encoder0PinALast = LOW;
 int n = LOW;


void setup(){

pinMode(1, INPUT);                                          // x
pinMode(2, INPUT);                                          // y
pinMode(5, INPUT);                                          // x1 x10 mouse cursour movement
 
 // Encoder setup
 
pinMode (encoder0PinA,INPUT);
pinMode (encoder0PinB,INPUT);
Serial.begin (9600);




 
 }

void loop(){

// x/y, lmb and mouse.begin

if(digitalRead(1) == HIGH && digitalRead(2) == LOW){       // x axis, mouse.begin, mouse.press
  Mouse.begin();
  Mouse.press(MOUSE_LEFT);
    }

if(digitalRead(1) == LOW && digitalRead(2) == HIGH){       // y axis, mouse.begin, mouse.press
  Mouse.begin();
  Mouse.press(MOUSE_LEFT);
    }

if(digitalRead(1) == LOW && digitalRead(2) == LOW){        //  off
  Mouse.release(MOUSE_LEFT);
  Mouse.end();
    }


// Encoder

 n = digitalRead(encoder0PinA);
   if ((encoder0PinALast == LOW) && (n == HIGH)) {
     if (digitalRead(encoder0PinB) == LOW) {
       encoder0Pos--;
     } else {
       encoder0Pos++;
     }
    
   } 
   encoder0PinALast = n;

// Cursour movment


if (digitalRead(5) == HIGH) {                                // x1 cursour movement
  if (digitalRead(1) == HIGH){                                     // x+
   if (encoder0Pos++) {
     Mouse.move(+1,0,0);
    }
  
   if (encoder0Pos--) {                                              // x-
     Mouse.move(-1, 0,0);
    }
      }

  if (digitalRead(2) == HIGH){                                   // y+
   if (encoder0Pos++) {
     Mouse.move(0,+1,0);
    }
  
  if (encoder0Pos--) {                                            // y-
     Mouse.move(0, -1,0);
    }
      }
    }
 
if (digitalRead(5) == LOW) {                                 // x10 cursour movment
  if (digitalRead(1) == HIGH){                                    // x+
   if (encoder0Pos++) {
     Mouse.move(+10,0,0);
    }
  
    if (encoder0Pos--) {                                             // x-
     Mouse.move(-10, 0,0);
    }
      }

  if (digitalRead(2) == HIGH){                                   // y+
   if (encoder0Pos++) {
     Mouse.move(0,+10,0);
    }
  
   if (encoder0Pos--) {                                             // y-
   Mouse.move(0, -10,0);  
    }
      }
    }
     
}

I got my rotary encoder to act like a mouse with the purpus to control plugins i audio software and give me a "analog feel" while working. I've also stoped using it due to the fact that it takes more time to switch between it and a mouse and time is not a luxury you got in the audio post production industry.