 #include <Adafruit_MCP23017.h>
+
+// NOTE: dacb has edited the Adafruit library to include a call to 
+// Wire.setClock after Wire.begin to increase the i2c clock to 1.7M
+// which is an allowed rate in the MCP23017 datasheet
 
 #undef DEBUG
 #define DEBUG

	gpioAB[1] = mcp1.readGPIOAB();

	// process the encoders
	for (i == 0; i < ENCODERS; ++i) {
		if (encoders[i].mcpX == &mcp0) {
			A = bitRead(gpioAB[0], encoders[i].pinA);
			B = bitRead(gpioAB[0], encoders[i].pinB);

		// like report the state change over midi
		if (sw != buttons[i].sw) {
			buttons[i].sw = sw;
#ifdef DEBUG
			Serial1.print("button ");
			Serial1.print(i, DEC);
			Serial1.print("state change: ");
			Serial1.println(sw, DEC);
#endif
		}
	}

	// this needs to do something with the new value	
	for (i = 0; i < STRINGS; ++i) {
		event_magnitude = 0;
		value = analogRead(strings[i].pin);
		// if we have deviated more than STRING_LEVEL_EVENT_PERCENT_CHANGE% of baseline
		// report a change
		if (strings[i].state == IDLE && value < strings[i].baseline_value - (strings[i].baseline_value / STRING_LEVEL_EVENT_PERCENT_CHANGE)) {
			strings[i].state = EVENT;
			strings[i].value = value;
#ifdef DEBUG
			Serial1.print("string ");
			Serial1.print(i, DEC);
			Serial1.print("event begins");
#endif
		} else if (strings[i].state == EVENT) {
			// if value begins to recover, put us in recover state
			if (value > strings[i].value) {
				int event_magnitude = strings[i].baseline_value - strings[i].value;
				strings[i].state = RECOVER;
#ifdef DEBUG
				Serial1.print("string ");
				Serial1.print(i, DEC);
				Serial1.print("event with magnitude: ");
				Serial1.println(event_magnitude, DEC);
#endif
			}
		// if we are in recovery state and the analog voltage has reached baseline again IDLE the event
		} else if (strings[i].state == RECOVER && value >  strings[i].baseline_value - (strings[i].baseline_value / STRING_LEVEL_EVENT_PERCENT_CHANGE)) {
			strings[i].state = IDLE;
#ifdef DEBUG
			Serial1.print("string ");
			Serial1.print(i, DEC);
			Serial1.println("is idle again");
#endif
		}
	}
}
