Fixing the Symptom, Not the Cause – The Smallest Trinket Project


My (not so) fancy-like PC has recently developed this issue where it, regardless what the power settings are set to, will always go to sleep within one or two minutes of inactivity. I found this to be an incredibly large nuisance when it came to watching videos, 3D printing something over USB , or just brainstorming in front of the keyboard basking in the warm glow of the monitor; the PC will never fail to go to sleep after a mere matter of seconds.
After much wasted time in the many Power Options windows, and after hunting through old, seemingly irrelevant forums, I have decided to bring yet another Adafruit Trinket to the rescue.

In less than a dozen lines of code, I got the Trinket to “poke” the mouse once every 59 seconds. The net movement is 0 pixels over time, and the “poke” occurs in a matter of a few clock cycles.
Check out the code below:

 * Adafruit Trinket Mouse-Poke Sketch
 * Causes the Trinket to act like a USB mouse and 
 * "poke" the cursor once every 59 seconds to prevent 
 * any computer from declaring itself idle.

#include <TrinketMouse.h>

void setup()
  //Start the library:

void loop()
  //Call "TrinketMouse" once every 10ms for 59 seconds:
  //This prevents the USB device from becoming unrecognized!
  for (int i=0; i <= 5900; i++){ 

  //Move cursor right 1px, then left 1px immediately after. 

  //You didn't see anything.

Give it a shot yourself if you happen to have the same issue… and a Trinket. Also check out the Trinket Auto Greeter for another Trinket HID project idea.

Edit: After about a day or two of use, it turns out I just had to run some software/driver updates… Never mind, the problem has returned. How odd.

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.