I'm creating an iOS application that receives an input from a force sensor. The Arduino is connected to a BLE Bluetooth transmitter, that sends a data stream of information to the application.
Below is my code:
-(void) bleDidReceiveData:(unsigned char *)data length:(int)length
{
NSData *d = [NSData dataWithBytes:data length:length];
NSString *s = [[NSString alloc] initWithData:d encoding:NSUTF8StringEncoding];
self.label.text = s;
if (s>150){
[UIImageView beginAnimations:NULL context:nil];
[UIImageView setAnimationDuration:0.01];
[ImageView setAlpha:1];
[UIImageView commitAnimations];
}
else {
//remove red
[UIImageView beginAnimations:NULL context:nil];
[UIImageView setAnimationDuration:1.0];
[ImageView setAlpha:0];
[UIImageView commitAnimations];
}
}
I had two questions:
The Bluetooth subsystem sends a stream of data (d) which is a set of numbers representing force impacts on the force sensor. Is there any way for me to go into each element of d or the converted string,
s
, so that I can use it in my if statement? I need to display the image if any number in the string is above a threshold (theif
statement). Or can I directly use the string in theif
statement? I would imagine this would require a for loop. I am just not sure how to set it up.To get the threshold, I need to calibrate the force sensor. Is there a way that I can get the mode or average of the data stream or string?