Controlling Whammy IV via Midi

I’m attempting to use the Arduino as a Midi Controller in order to Cycle the Whammy Pedal through each of the presets by Clicking a momentary switch. (rather than turning the knob on the unit).

I’m fairly new to this, so I ripped off another Sketch that I found online. The trouble I’m having is that, when I click the switch, the preset changes to the Whammy Pedal are pretty erratic. Sometimes the switch does nothing, sometimes it bounces back and forth between two presets, and sometimes it turns the unit on/off.

I’m wondering if someone could give me some guidance on this Sketch, or suggest a way to wire the switch (which has worked in other Sketches to do simple tasks like turn an LED on/off).

The sketch is listed below:

#include <MIDI.h>

#define KEY 8 // The switch is connected to PIN 8.

int keyispressed = 0; // Variable. Is the key currently pressed?
int currentprogram = 0;

void setup()
pinMode(KEY, INPUT);
MIDI.begin(); // Initialise midi library
void loop() //the main loop
keyispressed = digitalRead(KEY); // Read pin 8

if (keyispressed == LOW){
delay (175); // When footswitch is pressed, the preset will change and then wait the amount specified before moving on to the next preset.
if(currentprogram > 16) currentprogram = 0; // The Whammy has 16 presets, 0 - 16 are all active.


void setProgram(uint8_t p) {

I forgot to post the Whammy Manual:

Pages 12/13 get into the channels for each preset.