Things to do with a chipKIT™ Lenny and a QuickIO. No. 1: Autoclicker

This is the first part of a new series entitled "Things to do with a chipKIT™ Lenny and a QuickIO". In it, I'm going to be exploring some of the cool things you could do in just a matter of seconds using the two boards combined.

This first one is an Autoclicker.

In my spare time (of which I have plenty, obviously...) I find myself playing a number of web-based "clicker" games. Things like Cookie Clicker, etc. And after a while, I find I need to replace the microswitch in my mouse, or my finger decides to fall off and roll under the desk, which is a real pain.

So why not make something that will do the clicking for me? And do it a darn sight faster than my slow index finger can...?

By grabbing a Lenny and slapping a QuickIO on it you have all the controls you could need for configurable clicking. Add to that the new USB stack in chipKIT-core 2.x.x and in just a few lines of code, you will be clicking faster than anyone else.

To this end we will use the Mouse object to emulate a USB mouse. And we will simply ask it to click. It's as simple as that.  One command is all it takes:

Mouse.click();

All the rest of the code is for turning it on and off and for setting the speed of clicking. I may as well make use of the LEDs on the QuickIO for some simple visual feedback as well, so I can see how fast it's clicking.

So here's what I came up with:

/*
 * Simple Auto-Clicker for QuickIO
 *
 * Button A0 controls the clicking. Press it and clicking
 * starts. Release it and clicking stops.
 *
 * Potentiometer A4 controls the delay between clicks in
 * the range 0 to 255 milliseconds.
 *
 * The 8 LEDs count up one per click looping after 8 clicks
 * to provide visual feedback.
 */

#include <Mouse.h>

void setup() {
    pinMode(A0, INPUT_PULLUP);

    for (uint8_t i = 2; i < 10; i++) {
        pinMode(i, OUTPUT);
    }

    Mouse.begin();
}

void loop() {
    static uint8_t clicks = 0;

    if (digitalRead(A0) == LOW) {
        Mouse.click();
        clicks++;

        if (clicks == 8) { clicks = 0; }

        for (uint8_t i = 0; i < 8; i++) {
            digitalWrite(2 + i, i <= clicks ? HIGH : LOW);
        }
        delay(analogRead(A4) >> 2);
    }
}

That's pretty simple stuff, really. Start out by configuring one button as an input, and the LEDs as outputs. Then, if the button is pressed, click the mouse and delay for a while depending on the position of one of the potentiometers. Count the clicks and display them on the LEDs, looping after you get all the LEDs on.


Things to do with a chipKIT™ Lenny and a QuickIO. No. 2: Virtual Mouse