Sunday, February 5, 2017

Arduino project: Scroll footswitch

I have been super busy with mentoring an FRC team for the last 4 weeks, and I'm doing FRC stuff today, but I figured I could bash out a quick project while I'm doing other things.

I modified my generic box library to be able to make slant front boxes, made a small foot switch (just barely big enough to hold the two components I need) printed it out and tossed in a Digispark and a push switch.



I think this is absolutely as simple as it gets, folks.

Along with a tiny bit of Arduino code, this sends down arrow keys to a USB port at a speed of 10 per second when the button is pressed.  Allows for internet page reading while you're doing other things. Got the idea from an online suggestion.

I had thought about using scroll wheel, but it only works on the frame that the mouse cursor is over.  Down arrow works on any window that has focus. It's still not perfect. If this isn't satisfactory I may put a selector switch on it to choose different methods.

The code:
// Really simple program to send 10 "down arrow" keys a second if a button is pressed
// for Digispark
// John Ridley Feb 5 2017
// Public Domain Dedication PD0

#include "DigiKeyboard.h"

// down arrow
#define KEY_DOWN 81

void setup() {
  // don't need to set anything up to use DigiKeyboard
  pinMode(0,INPUT_PULLUP);
}

void loop() {
  DigiKeyboard.delay(10); // keep usb alive and other functions
  if (!digitalRead(0)) // if the button is pressed
  {
    // this is generally not necessary but with some older systems it seems to
    // prevent missing the first character after a delay:
    DigiKeyboard.sendKeyStroke(0);
    DigiKeyboard.sendKeyStroke(KEY_DOWN);
    DigiKeyboard.delay(100);
  }
}