Mouse.scroll() a variable less than 1? Or how to get more resoloution..

Status
Not open for further replies.
I'm working on a mouse scroll wheel that I made with an encoder. It works, but I'm trying to get the scrolling to slow down a bit. Mouse.scroll(0.5) won't work. I tried to use a float variable, that also doesn't work for anything less than 1.

My goal here is a smooth scrolling wheel, just like what you'd find in a typical mouse. It's going to be used with a teleprompting software to scroll text on a screen, so smooth and slow is the way to go.

Here's my code, which started from the basic encoder example sketch. I'm using a teensy 2.0 and a 20ppr encoder.

Code:
#include <Encoder.h>

float ScPos = 1.5;
float ScNeg = -1.5;

Encoder myEnc(5, 6);
//   avoid using pins with LEDs attached

void setup() {
  Serial.begin(9600);
  Serial.println("Basic Encoder Test:");
}

long oldPosition  = -999;

void loop() {
  long newPosition = myEnc.read();
  if (newPosition > oldPosition) {
    oldPosition = newPosition;
    Mouse.scroll(ScPos);
    delay(10);
  }
  if (newPosition < oldPosition) {
    oldPosition = newPosition;
    Mouse.scroll(ScNeg);
    delay(10);
  }
}
 
Last edited:
You can't send less than 1. The HID protocol uses integers, so 1 is the smallest possible change.

If you need things smoother, you'll need to adjust settings on the host side, so that 1 causes less scrolling.
 
Status
Not open for further replies.
Back
Top