sanastasiazxn 2017-10-26 16:13 采纳率: 0%
浏览 1348

萌新提问关于心率传感器数据显示到三位数码管

直接使用pulse sensor传感器的程序和上位机小软件显示心率图和心率的,目前想把心率数据导出显示到三位共阴的小数码管上,但是快崩溃了,数码管只有一位四位的教程,这并不重要,重要的是怎么把心率数据弄到数码管上,好像没有这样的教程啊。。。着能操作吗?哭唧唧的开源课作业。
这是传感器的程序
int pulsePin = 0;

int blinkPin = 13;

int fadePin = 5;

int fadeRate = 0;

volatile int BPM;

volatile int Signal;

volatile int IBI = 600;

volatile boolean Pulse = false;

volatile boolean QS = false;

void setup(){
pinMode(blinkPin,OUTPUT);

pinMode(fadePin,OUTPUT);

Serial.begin(115200);

interruptSetup();

}

void loop(){
sendDataToProcessing('S', Signal);

if (QS == true){

fadeRate = 255;

sendDataToProcessing('B',BPM);

sendDataToProcessing('Q',IBI);

QS = false;

}

ledFadeToBeat();

delay(20);

}

void ledFadeToBeat(){
fadeRate -= 15;

fadeRate = constrain(fadeRate,0,255);

analogWrite(fadePin,fadeRate);

}

void sendDataToProcessing(char symbol, int data ){
Serial.print(symbol);

Serial.println(data);

}

volatile int rate[10];

volatile unsigned long sampleCounter = 0;

volatile unsigned long lastBeatTime = 0;

volatile int P =512;

volatile int T = 512;

volatile int thresh = 512;

volatile int amp = 100;

volatile boolean firstBeat = true;

volatile boolean secondBeat = false;

void interruptSetup(){

TCCR2A = 0x02;

TCCR2B = 0x06;

OCR2A = 0X7C;

TIMSK2 = 0x02;

sei();

}

ISR(TIMER2_COMPA_vect){

cli();

Signal = analogRead(pulsePin);

sampleCounter += 2;

int 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;

digitalWrite(blinkPin,HIGH);

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;                  
    sei();                               
    return;                              
  }   



  word 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){

digitalWrite(blinkPin,LOW);

Pulse = false;

amp = P - T;

thresh = amp/2 + T;

P = thresh;

T = thresh;
}

if (N > 2500){

thresh = 512;

P = 512;

T = 512;

lastBeatTime = sampleCounter;

firstBeat = true;

secondBeat = false;

}

sei();

}

  • 写回答

2条回答 默认 最新

  • devmiao 2017-10-27 01:34
    关注
    评论

报告相同问题?

悬赏问题

  • ¥50 有数据,怎么建立模型求影响全要素生产率的因素
  • ¥50 有数据,怎么用matlab求全要素生产率
  • ¥15 TI的insta-spin例程
  • ¥15 完成下列问题完成下列问题
  • ¥15 C#算法问题, 不知道怎么处理这个数据的转换
  • ¥15 YoloV5 第三方库的版本对照问题
  • ¥15 请完成下列相关问题!
  • ¥15 drone 推送镜像时候 purge: true 推送完毕后没有删除对应的镜像,手动拷贝到服务器执行结果正确在样才能让指令自动执行成功删除对应镜像,如何解决?
  • ¥15 求daily translation(DT)偏差订正方法的代码
  • ¥15 js调用html页面需要隐藏某个按钮