hi
i am trying to use this sensor (PulseSensor :
http://pulsesensor.myshopify.com/pages/pulse-sensor-amped-arduino-v1dot1")
with ioio-otg
I adjusted the arduino code to work with ioio but the reading keep in the
range of 166 to 230 i want to know if this code is right
----------------------------------------------------------------------------------------------------
package com.tryr.ioiotest3;
import ioio.lib.api.AnalogInput;
import ioio.lib.api.exception.ConnectionLostException;
import ioio.lib.util.BaseIOIOLooper;
import ioio.lib.util.IOIOLooper;
import ioio.lib.util.android.IOIOActivity;
import android.os.Bundle;
import android.view.Menu;
import android.widget.TextView;
public class MainActivity extends IOIOActivity {
TextView textview ;
volatile float BPM;
volatile float Signal;
volatile float IBI = 600;
volatile boolean Pulse = false;
volatile boolean QS = false;
volatile float rate[]=new float[10];
volatile long sampleCounter = 0;
volatile long lastBeatTime = 0;
volatile float P =1.5;
volatile float T = 1.5;
volatile float thresh = 1.5;
volatile float amp = 100;
volatile boolean firstBeat = true;
volatile boolean secondBeat = false;
long runningTotal;
float N;
private AnalogInput pin;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
textview=(TextView)findViewById(R.id.textView);
enableUi(false);
}
class Looper extends BaseIOIOLooper {
@Override
protected void setup() throws ConnectionLostException {
pin=ioio_.openAnalogInput(40);
enableUi(true);
}
public void loop() throws ConnectionLostException,
InterruptedException {
pin.setBuffer(256);
Signal = pin.getVoltageBuffered();
sampleCounter += 1;
N =(sampleCounter - lastBeatTime);
if(Signal < thresh && N > (IBI/5)*3){
if (Signal < T){
T = Signal;
}
}
if(Signal > thresh && Signal > P){
P = Signal;
}
if (N > 250){
if ( (Signal > thresh) && (Pulse == false) && (N >
((IBI/5)*3) )) {
Pulse = true;
IBI = (sampleCounter - lastBeatTime);
lastBeatTime = sampleCounter;
}
}
if(secondBeat){
secondBeat = false;
for(int i=0; i<=9; i++){
rate[i] = IBI;
}
}
if(firstBeat){
firstBeat = false;
secondBeat = true;
return;
}
runningTotal = 0;
for(int i=0; i<=8; i++){
rate[i] = rate[i+1];
runningTotal += rate[i];
}
rate[9] = IBI;
runningTotal += rate[9];
runningTotal /= 10;
BPM = (60000/runningTotal);
QS = true;
if (Signal < thresh && Pulse ==
true){
Pulse = false;
amp = P - T;
thresh = amp/2 + T;
P = thresh;
T = thresh;
}
if (N > 2500){
thresh = 1.5;
P = 1.5;
T = 1.5;
firstBeat = true;
secondBeat = false;
lastBeatTime = sampleCounter;
}
setText(Float.toString(BPM));
}
@Override
public void disconnected() {
enableUi(false);
}
}
private void enableUi(final boolean enable) {
runOnUiThread(new Runnable() {
@Override
public void run() {
}
});
}
@Override
protected IOIOLooper createIOIOLooper() {
return new Looper();
}
private void setText(final String str) {
runOnUiThread(new Runnable() {
@Override
public void run() {
textview.setText(str);
}
});
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is
present.
getMenuInflater().inflate(R.menu.main, menu);
return true;
}
}
--
You received this message because you are subscribed to the Google Groups
"ioio-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To post to this group, send email to [email protected].
Visit this group at http://groups.google.com/group/ioio-users.
For more options, visit https://groups.google.com/groups/opt_out.