fgjfjfdjdjdjd
Dependencies: mbed
Fork of EDP2_display by
Diff: main.cpp
- Revision:
- 3:5f89484f8c84
- Parent:
- 2:281d8c268a8e
- Child:
- 4:82c807b7685e
--- a/main.cpp Wed Feb 14 23:27:29 2018 +0000 +++ b/main.cpp Tue Feb 27 13:58:05 2018 +0000 @@ -24,30 +24,25 @@ AnalogIn pulse_in(PTB0); AnalogOut o(PTE30); DigitalOut led(PTD5); -float xi,ypast,y,sum;//absolute max -float alpha=0.8; -int no; +float xi,ypast,y,alpha=0.5;//absolute max +float v[80]; int q=0; bool first=true; + void get_pulse() { - xi=(float)pulse_in; + if(q==80) q=0; + xi=(float)pulse_in; //noise reduction algorithm if(!first)//noise filtering procedure { - y=alpha*xi+ (1-alpha)*ypast; + y= (alpha*xi)+ ((1-alpha)*ypast); + ypast=y; } else first=false; - if(y>0.6)//make the led blink to the heartbeat when signal reaches a certain high region, it will stay lit till the signal decreases below that value - { - led=1; - } - else - { - led=0; - } - //pc.printf("%.3f, %.3f\n",xi,y); - ypast=y;sum+=y;no++; + v[q]=xi; + o=v[q]; + q++; } @@ -114,6 +109,20 @@ //END OF DISPLAY FUNCTIONS +void detect_pulse() +{ + if(slope(5,25,v[5],v[25])>SOMETHING NEED TESTING and slope(40,50,v[40],v[50])<SOMETHING NEEDS TESTING) + //then the pulse is where it is supposed to be + //so out put it with regard to 0 + +} + +inline float slope(float a1, float a2, float b1, float b2) +{ + return (float)((b2-b1)/(a2-a1)); +} + + void splash_screen() { setup_dot_matrix (); /* setup matric */ @@ -137,12 +146,14 @@ clear(); } + + int main() { pulse.attach(&get_pulse,0.0125);//attach the interrupt thing so it starts the ISR every 0.0125 s splash_screen();//wait for the pulse to be stable by showing stuff on the display so the user is happy knowing he is gay while(1) { - o=(sum*100)/no-1;//attempt at doing the running average which at the moment does not work + } }