Hi Everyone,
I have a touch screen radio in my truck that has no physical knob to adjust the volume, one of these days I swear I will die trying to adjust it using the touch screen.
The radio runs android, so I figured I could use a rotary encoder to send volume up and down keys through the arduino as an HID, this worked however not exactly how I thought it would.
Turns out, my android radio has 2 separate volumes. When I rotate the rotary encoder, similar to a phone, a volume control pops up, however this does not change the volume level on the bottom fixed bar which stays at a certain volume, turns out it is sending this data directly to the car i.e. no keystroke.
I figured I could rethink my plan and change what would be a keyboard to a mouse, however I am struggling to accurately position the mouse where I need the keypress to happen. I understand absolute positioning goes against the entire concept that a mouse was made for, but the concept of relative positioning is hard to grasp for my use.
I found an example sketch from someone on this forum that would locate the mouse to the bottom left, move up slightly to the right at a diagonal, do a circle with the mouse then return to the same location. No matter if you moved the mouse during that operation, it would always return to the same spot. I would very much like to not have someone just give me the answer, but rather point me in the direction of how I could better understand the code that is written in this example. I really just need to understand how the positioning it always repeating back to a 0 location, my positioning is 720 pixels from the left and my understanding is that I can only travel 127 (not even sure the unit, I dont think pixels).
If anyone could point me in the right direction I would be greatly appreciated!
The code I would like to better understand is below, not so much the circle, but the exact positioning.
/*
Demo of moving the mouse in a smooth circle without delay
or blocking of the loop
*/
#include <Mouse.h>
void setup() {
delay(1000);
}
void loop() {
static float angle = 100;
static int x, y;
static unsigned long counter6;
static unsigned long counter7;
if (millis() > 10000 && counter6 < millis() - 10000) {
counter6 = millis();
angle = 0.0;
}
if (millis() > 20 && counter7 < millis() - 20 && angle < 100) {
counter7 = millis();
if (angle < 0.1 ) {
Mouse.begin();
// move to the corner of the screen
for (int counter5 = 0; counter5 <= 100; counter5++) {
Mouse.move(-127, 127, 0);
}
// move to a specific point on the screen
Mouse.move(20,-30,0);
}
// move around a couple of times in a circle
x = 9 * cos (angle);
y = 9 * sin (angle);
angle += .2; // increment the angle
Mouse.move(x, y, 0);
if (angle >= 4 * PI) {
angle = 100;
Mouse.end();
}
}
}