I am working on a device that will be able to measure the speed of a rotating object (in this case a bicycle wheel) and control the pitch of an audio file (in ableton) I have go the optical tachometer working accuratly enough (although the incrementations by which it goes up and down need a bit of tweaking), I have managed to also get it to control the brightness of an LED according to the RPM. The next hurdle is to get the arduino to output the RPM as a midi cc message. I have wired into the arduino a MIDI out port and have attempted to hack together some code I had from previous projects but so far with so success. The arduino is outputting midi values but its jibbirish. I just want the RPM to be a cc value so that when it is at its fastest speed it is reading the highest midi value of 127 and when it is still it reads a midi value of 0. below is the code I have so far - does anyone have any suggestions how to improve it?

/* * Optical Tachometer * * Uses an IR LED and IR phototransistor to implement an optical tachometer. * The IR LED is connected to pin 13 and ran continually. A status LED is connected * to pin 12. Pin 2 (interrupt 0) is connected across the IR detector. * * */

void setup() { Serial.begin(baud_rate); //Interrupt 0 is digital pin 2, so that is where the IR detector is connected //Triggers on FALLING (change from HIGH to LOW) attachInterrupt(0, rpm_fun, FALLING);

void loop() { //Update RPM every second delay(500); //Don't process interrupts during calculations detachInterrupt(0); //Note that this would be 60*1000/(millis() - timeold)*rpmcount if the interrupt //happened once per revolution instead of twice. Other multiples could be used //for multi-bladed propellers or fans rpm = 3*1000/(millis() - timeold)*rpmcount; timeold = millis(); rpmcount = 0;

you might benefit (and, I should say, your code would also) from a peek at the map() function.

map(inLow,inHigh,outLow,outHigh);

[this is from memory, so no slings and arrows, please!!]

for instance: map(0,4095,1,127) will map input values of 0-4095 into output values of 1-127

also, you probably don't want to swamp the MIDI bus with THOUSANDS of CC messages per second, so you'll want to determine a way to scale that back a bit (perhaps only output an averaged value every so often, for example

thanks for your reply - the map function is next on my list. For now, I have managed to get the MIDI working pretty well - just need to tidy up the maths regarding the rpm readout as it jumps around a bit. here is the code I have used:

/* * Optical Tachometer * * Uses an IR LED and IR phototransistor to implement an optical tachometer. * The IR LED is connected to pin 13 and ran continually. A status LED is connected * to pin 12. Pin 2 (interrupt 0) is connected across the IR detector. * * *///#define DEBUG

void setup() { Serial.begin(SERIAL_PORT_RATE); //Interrupt 0 is digital pin 2, so that is where the IR detector is connected //Triggers on FALLING (change from HIGH to LOW) attachInterrupt(0, rpm_fun, FALLING);

//Turn on IR LED pinMode(ledPin, OUTPUT); digitalWrite(ledPin, HIGH);

//Use statusPin to flash along with interrupts pinMode(statusPin, OUTPUT);