I am developing and app and I would like to measure the turns of a wheel. I bought a cheap bicycle odometer that counts the turns of the bike wheel using a magnet switch that closes the circuit once per turn, when the magnet is close enough to the sensor. I had the idea of adding this magnet switch to the mic circuit of an iphone headset and then use the audio frameworks to manage the connection of the mic, making a switch that can be identify when the mic is or not connected and then make a counter with it. The way I could make the switch was using the AVFoundation framework with [AVCaptureDevice] class, as I found out be the only way to differentiate external and internal mic following [this-post] answered question.
I paste an excerpt from my code to test the switch. The code in in the loop of a timer.
NSString *name;
static int micSwitch=0;
NSArray *devices = [AVCaptureDevice devicesWithMediaType:AVMediaTypeAudio];
for (AVCaptureDevice *device in devices) {
name = [ device localizedName];
}
if ([name isEqual:@"iPhone Microphone"]) {
micSwitch=0;
}
else{
micSwitch=1;
}
However, this switch updates slower than I need. According to my estimation, the switch will need to be updated in less than 1.5ms . Somebody has a better idea how can I do that using the audio jack input ?