Last active
March 24, 2024 06:48
-
-
Save mrcodetastic/3669355c3c7f29e6d306d821f4d22d66 to your computer and use it in GitHub Desktop.
USB Mouse Jiggler (Work From Home (WFH) emulator)
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
/* | |
* Compile and flash this firmware onto a ESP32-S2 and then use a seperate micro USB connector | |
* to connect the S2's Pin 19 to USB D- and Pin 20 to USB D+ (and of course +5V to +5V and GND to GND) | |
* | |
* It will appear as a 'USB Mouse' in Windows/Linux/Mac, and move the mouse every 30 seconds or so | |
* that you are always online/green. The ESP's LED will flash briefly when this occurs. | |
* | |
* Even better, buy and ESP32-S2 Mini with USB-C and put it into DFU mode: https://www.youtube.com/watch?v=YPX2nlr-ySU | |
* | |
* If writing firmware to an ESP32-S2 Mini using Arduino IDE. Make sure you have 'USB CDC On Boot' set to 'False' | |
* otherwise the 'USB Device Name' that shows up on Windows will not be correct as per the code below. | |
* | |
* Update: Now stops jiggling after 'jiggle_hours'. Avoids accidental jiggling all night long! Boss might get suspicious! | |
*/ | |
#include <Arduino.h> | |
#include "USB.h" | |
#include "USBHIDMouse.h" | |
USBHIDMouse Mouse; | |
ESPUSB usbdev; | |
// the number of the LED pin | |
const int ledPin = 15; // 16 corresponds to GPIO15 | |
// setting PWM properties | |
const int freq = 5000; | |
const int ledChannel = 0; | |
const int resolution = 8; | |
const int jiggle_hours = 8; // Number of hours to jiggle for after each reset. | |
unsigned long start_ms = 0; | |
//unsigned long last_jiggle_ms = 0; | |
void setup() | |
{ | |
usbdev.productName("Dell Laser Mouse MS3220"); | |
usbdev.manufacturerName("Dell"); | |
usbdev.begin(); | |
Mouse.begin(); | |
delay(1000); | |
// configure LED PWM functionalitites | |
ledcSetup(ledChannel, freq, resolution); | |
// attach the channel to the GPIO to be controlled | |
ledcAttachPin(ledPin, ledChannel); | |
delay(200); | |
start_ms = millis(); | |
} | |
void loop() { | |
//digitalWrite(LED_PIN, HIGH); | |
if ( (millis() - start_ms) > (jiggle_hours*60*60*1000) ) | |
{ | |
// Keep LED lit when jiggling is over. | |
ledcWrite(ledChannel, 255); | |
delay(5000); | |
return; | |
} | |
// increase the LED brightness | |
for(int dutyCycle = 0; dutyCycle <= 255; dutyCycle++) | |
{ | |
// changing the LED brightness with PWM | |
ledcWrite(ledChannel, dutyCycle); | |
delay(5); | |
} | |
int random_x = random(1,4); | |
int random_y = random(1,4); | |
Mouse.move(random_x,random_y,0,0); | |
// decrease the LED brightness | |
for(int dutyCycle = 255; dutyCycle >= 0; dutyCycle--){ | |
// changing the LED brightness with PWM | |
ledcWrite(ledChannel, dutyCycle); | |
delay(5); | |
} | |
delay(20000); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment