Created
January 24, 2024 01:53
-
-
Save erikson1970/bd15afe61ab59ff47d0e1ec20e65ea94 to your computer and use it in GitHub Desktop.
Mouse Jiggler for Arduino Micro
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
* NAME: Arduino Mouse Jiggler | |
* DATE: 2020-09-17 | |
* DESC: Arduino based mouse emulator | |
* VERSION: 1.0 | |
*/ | |
#include <Mouse.h> | |
//#define debug true | |
int nextTime(int rateParameter, int minVal, int maxVal) | |
// creates a poisson distributed random integer | |
{ | |
float poiss =-log(1.0f - random(RAND_MAX) / ((float)RAND_MAX + 1)) * (float) rateParameter; | |
return minVal + min(maxVal-minVal, int(poiss)); | |
} | |
int move_interval = 3; | |
float posX = 0; | |
float posY = 0; | |
#ifdef debug | |
int loop_interval = 4; | |
int min_loop_interval = 1; | |
#else | |
int loop_interval = 360; | |
int min_loop_interval = 240; | |
#endif | |
int RXLED = 17; // The RX LED has a defined Arduino pin | |
void setup() | |
{ | |
#ifdef debug | |
Serial.begin(19200); | |
//delay(1000); | |
Serial.println("Sending Debug info to Console"); | |
//while(!Serial); | |
//delay(1000); | |
#endif | |
randomSeed(analogRead(0)); | |
Mouse.begin(); | |
pinMode(RXLED, OUTPUT); // Set RX LED as an output | |
} | |
void loop() | |
{ | |
int distance = nextTime(50,30,400); | |
int x = random(7) - 3 + int(-posX * abs(posX) / 30000. + 0.5); | |
int y = random(7) - 3 + int(-posY * abs(posX) / 30000. + 0.5); | |
int SECs = nextTime(loop_interval-min_loop_interval,min_loop_interval,loop_interval*2); | |
#ifdef debug | |
Serial.print(distance); | |
Serial.print("\t"); | |
Serial.print(x); | |
Serial.print("\t"); | |
Serial.print(y); | |
Serial.print("\t"); | |
Serial.print(SECs); | |
Serial.print("\n"); | |
#endif | |
for (int i = 0; i < distance; i++) { | |
int movX = random(5) - 2 + x; | |
int movY = random(5) - 2 + y; | |
posX += movX; | |
posY += movY; | |
Mouse.move(movX,movY, 0); | |
if (((i >> 3) % 2) == 1) { | |
digitalWrite(RXLED, LOW); // set the RX LED ON | |
} else { | |
digitalWrite(RXLED, HIGH); // set the RX LED ON | |
} | |
if (random(1000)<3) { | |
//occasionally change direction in the middle of a slide | |
x = random(7) - 3 + int(-posX * abs(posX) / 30000. + 0.5); | |
y = random(7) - 3 + int(-posY * abs(posX) / 30000. + 0.5); | |
} | |
delay(move_interval + random(3) - 1); | |
} | |
for (int ii = 0; ii < SECs;ii++) { | |
delay(1000); | |
} | |
delay(random(1000)); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment