let me preface this post with saying that I have no programming skills at all. Nada.
I have bought a Teensy 3 and a rotary encoder. What I would like to build is a little box sitting next to my keyboard, with a single rotary encoder. Turning the encoder left acts as a mouse click & hold, and moves the mouse pointer down until I stop turning it. Turning it right is the same except it moves the mouse pointer up. I would use this to quickly adjust faders/knobs, in a Digital audio workstation, simply by mousing over the parameters with my trackpad then turn the encoder.
How feasible would something like this be without any programming skills?
The way to handle this would be to use a processor like the one used in the Leonardo, which has USB built in. These devices can easily emulate a keyboard and mouse, when plugged into the computer. There are libraries, so it's relatively easy to code. I don't know whether the processor used in the Teensy has this capability, though. And I suspect that, without the in-built USB, you are looking at an uphill battle.
If the Teensy turns out not to have that functionality, I would suggest looking at the Arduino Micro from Adafruit, which should have it.
i will check out the links you provided. I do believe the Teensy has built in USB, and is also able to emulate mouse & keyboard. (At least from what I can understand after reading through their webpages).
smllechtim:
i will check out the links you provided. I do believe the Teensy has built in USB, and is also able to emulate mouse & keyboard. (At least from what I can understand after reading through their webpages).
The next thing I would do, then, would be to test whether the linked library works for you, such as by writing a small script that reads a button press and outputs a short text string like ABCDEFG or something when the button is detected. There is actually an example script that does just this: http://arduino.cc/en/Tutorial/KeyboardMessage
BTW, the coding examples on Arduino.cc are sometimes not perfect. For example, IMO it is bad practice to use pinMode(INPUT) without activating the internal pullup resistor of the Arduino. The simplest way to do this is to use pinMode(INPUT_PULLUP) instead. Then you must remember that the line goes LOW when the button is pressed and is HIGH when the button is not pressed. This is counter-intuitive to most people, but once you learn it, it's no problem. When using INPUT_PULLUP, you also wire the button differently:
INPUT: 5v -> button -> input pin (with 10k resistor in there somewhere)
INPUT_PULLUP: input pin -> button -> GND (with a 10k resistor in there somewhere)
I'm actually not sure whether a current-limiting resistor is needed on an input pin. I have never used them, and haven't destroyed an Arduino yet, but maybe I've just been lucky.
EDIT: This post ( http://forums.adafruit.com/viewtopic.php?f=25&t=14018 ) seems to indicate that current-limiting resistors are not needed on input pins. Maybe another way that the Arduino.cc example is a little flawed. But let's not be too harsh, after all. They do so much for us!
EDIT 2: The current-limiting resistor seems to be a hedge against accidentally setting the input pin to be an output. In that case, you could short your 5v rail to your ground rail and damage your Arduino. If you're reasonably confident you won't make this mistake, the resistor can probably be omitted.
smllechtim:
How feasible would something like this be without any programming skills?
It's definitely feasible, but the 'without programming skills' might be an issue. It's not a trivial project by any means, and to implement it you'd need to acquire those programming skills. So it comes down to how willing and able you are to do that.
If you just want somebody to give you the working product and aren't interested in making it yourself there is a Gigs and Collaborations section of the forum where you can ask people to implement projects for/with you. Note that most people would expect to be paid for working for you. This would still leave to sort out the hardware side - not difficult, but it would need doing.
#include <Encoder.h>
// Change these pin numbers to the pins connected to your encoder.
// Best Performance: both pins have interrupt capability
// Good Performance: only the first pin has interrupt capability
// Low Performance: neither pin has interrupt capability
Encoder knob(5, 6);
// avoid using pins with LEDs attached
long currentPosition;
const byte mouseMoveAmount = 10; // no idea what the units are for this, so tweak as needed
unsigned long lastMoveMillis;
int mouseReleaseTimer = 500; // time of no encoder move until mouse is released
void setup() {
Mouse.begin();
currentPosition = 0;
knob.write(0);
}
void loop() {
long newPosition = knob.read();
if (newPosition != currentPosition) // has encoder position changed?
{
lastMoveMillis = millis(); // mark time of this move
if (!Mouse.isPressed())
Mouse.press(); // mouse left-button down
Mouse.move(0, newPosition * mouseMoveAmount, 0); // move mouse up or down depending on direction of turn
}
if (millis() - lastMoveMillis > mouseReleaseTimer) // release the mouse and reset knob state to zero if sufficient time has elapsed.
{
Mouse.release();
knob.write(0);
newPosition = 0;
}
currentPosition = newPosition;
}
For what it's worth, one problem you will run into is that the actual mouse cursor is moving up or down, which means that if you move a fader, and during that move, your mouse moves off of the fader, then you stop moving the knob, then you start moving the knob again to keep moving the same fader, the mouse will no longer be on the fader when the Arduino presses the left mouse button. A better approach would be to use either the mouse wheel (assuming your software allows you to move faders with the mouse wheel) or to use a keystroke shortcut. Like, for example, if the software lets you click a fader to give it focus, then press up and down arrow, have the Arduino send up or down arrow keystrokes instead of having it move the mouse. That way the focus doesn't change when you move the knob. I'll leave figuring out how to do that as an exercise for you.
One more thing: that library assumes your rotary encoder is quadrature-encoded. I don't know if that's very common, or if there are other encoding types used, as I don't use rotary encoders myself very much.
joshuabardwell:
One more thing: that library assumes your rotary encoder is quadrature-encoded. I don't know if that's very common, or if there are other encoding types used, as I don't use rotary encoders myself very much.
I don't think that is a problem - there are not really any other ways to construct such an encoder.
Joshua Bardwell, the code you posted above pretty much does exactly what I want! Thanks! The only problem I haven´t figured out yet is how to slow down the mouse pointer. When setting "const byte mouseMoveAmount = 10" to 1, it´s still way to fast.