ARDUINO-BASED EXERCISE BIKE INTERFACE//////////////////////////

I programmed an ATMega chip with Arduino and attached a reed switch to a bike pedal connected to a MAX/MSP patch that controlled the playback and speed of a live database of audio files generated by participants uploading via the BIKE BOX locative media project.

By the way, this worked remarkably well using this simple Arduino source code and just one reed switch! The Arduino connects to MAX/MSP via MAXUINO.

I posted the Arduino code below.

//////////////////////////////////////////////

ARDUINO CODE

/*
* Bicycle Reed Switch Interface
*
* Setup:
* LED on digital pin 11 (for debugging)
* Reed switch on digital pin 2 (interrupt 0)
*/

int ledPin = 11;
int counter = 0;
long nextSwitchTime = 0;
int resolution = 330; // ms between sending readings via serial
int incomingByte = 0;
long nextCountTime = 0;
int countResolution = 5;
long nextStopCountTime = 0;
int stopCountResolution = 2;

volatile int state = LOW;

void setup() {
pinMode(ledPin, OUTPUT);
attachInterrupt(0, blink, RISING);
nextSwitchTime = millis() + resolution;
nextCountTime = millis() + resolution;
Serial.begin(9600);
Serial.println("ready");
}

void loop () {
digitalWrite(ledPin, state);
if (nextSwitchTime < millis()) {
// Rotation count
nextSwitchTime = millis() + resolution;
Serial.println(counter);
Serial.println(counter, BYTE);
counter = 0;
}
}

void blink() {
if(nextCountTime < millis()) {
nextCountTime = millis() + countResolution;
counter++;
state = !state;
}
}

void lift() {
if(nextStopCountTime < millis()) {
nextStopCountTime = millis() + stopCountResolution;

}
}

void drop() {
if(nextStopCountTime < millis()) {
nextStopCountTime = millis() + stopCountResolution;

}
}