Alternatives to keep your computer awake
The most obvious alternative for keeping your computer awake is turning down your power settings. Another option is apps like Don’t Sleep for Windows and Taurine for macOS which can simulate activity to keep the OS awake.
Why a hardware solution to keep your computer awake?
Other than “because it’s there,” plugging in and removing a hardware device can be easier than remembering to turn on and off a setting or app. Just remember that this will also prevent your computer from locking itself, so don’t use in any scenario where that would be a problem.
- I’m using a DFROBOT Beetle as my Arduino, but any 32u4 or SAMD micro based board will support the Mouse functions.
- A cable to connect your computer’s USB port (USB-A or USB-C) to the Arduino (micro USB for all of my 32u4-compatible boards)
What’s this blinking stuff?
blinkIfYoureRebooted function is there in case there needs to be a reset of the device, I can get a signal with the five consecutively longer blinks that I successfully reset, since with the Beetle, I bridge a connection to reset instead of pressing a button.
Reset is sometimes necessary if you’ve been switching out dev computers and devices:
Couldn't find a Board on the selected port. Check that you have the correct port selected. If it is correct, try pressing the board's reset button after initiating the upload.
The random bits
if(random(0,10090)==0) code was just an arbitrarily large chance at moving the mouse, and then
Mouse.move(random(0,5)-2, random(0,5)-2, 0) just moves [-2,+2] pixels in the X and Y direction so that it moves “enough” to register as input, but not enough or frequently enough to prevent normal computer usage.