The USB-HID Library is built into Arduino, there is no external installation required. Verify that you have a Metro Express, then copy and paste the code below into the Arduino Editor. Then, compile and upload.

/*
 * USB Blog Buddy
 * a USB-HID Scroll Wheel for Metro Express
 * 
 * by Brent Rubell for Adafruit Industries.   Support Open Source, buy Adafruit!
 */
 
// include the mouse library 
#include <Mouse.h>

// trimpot pin
const int trimPin = A0;

// button pin
const int buttonPin = 2;

// reduces scrolling speed (ms)
const int scrollDelay = 100;

// trimpot value
int trimValue = 0; 

// button state
int buttonState = 0;

void setup() {
  // start serial monitor at 9600 baud
  Serial.begin(9600);
  // start the mouse 
  Mouse.begin();
}

void loop() {
  // read the button state 
  buttonState = digitalRead(buttonPin);
    
  if (buttonState == HIGH) {
    // stop the mouse if button not pressed
    Mouse.end();
  }
  else {
    // start the mouse (if stopped)
    Mouse.begin();
    // read the trimpot value
    trimValue = analogRead(trimPin);
    // map the trimValues to scroll wheel down (-neg values) and up (+pos values)
    trimValue = map(trimValue, 0, 1023, -5, 5);
    // move the mouse wheel (dont change cursor position) 
    Mouse.move(0, 0, trimValue);
    // reduce the scrolling speed
    delay(scrollDelay); 
  }
}

Using USB Blog Buddy

When you press the push button, the Metro Express will take control of your mouse and start scrolling the mouse wheel. 

Scroll Page Up: Move the potentiometer such that the arrow on it faces towards the top of the breadboard

Scroll Page Down: Move the potentiometer such that the arrow on it faces towards the bottom of the breadboard

Not Working?

I don't see anything moving on my screen

Check your wiring, the library for USB interfacing is built into Arduino and should automatically start when you upload this code. 

This guide was first published on Aug 18, 2017. It was last updated on Jun 12, 2017.

This page (Code) was last updated on Jul 18, 2017.

Text editor powered by tinymce.