Hola , no se si alguien me puede ayudar.
Tengo un código arduino UNO que ya tiene varios años. Sin embargo , quiero usarlo pero usando el arduino MEGA 2560 (presenta un i2c lcd) y no se si es que el código que tengo vaya a verse afectado al hacer el cambio de arduino o por el contrario , si es que esté de plano no funcione , ya que se trata de un medidor de pulsos cardíacos.
A continuación el código (usa dos):
#include <LiquidCrystal_I2C.h>
LiquidCrystal_I2C lcd(0x27,16,2);
int pulsePin = 0;
volatile int BPM;
volatile int Signal;
volatile int IBI = 600;
volatile boolean Pulse = false;
volatile boolean QS = false;
void setup(){
pinMode(13, OUTPUT);
lcd.init();
lcd.backlight();
lcd.clear();
Serial.begin(9600);
interruptSetup();
}
void loop(){
int pulso = analogRead(A0);
if (pulso >= 530) {
digitalWrite(13, HIGH);
}
else{
digitalWrite(13, LOW);
}
lcd.setCursor(1,0);
lcd.print("BPM= ");
lcd.print(BPM);
lcd.print(" ");
Serial.println(pulso);
if (QS == true){
QS = false;
}
}
=============================================================================
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;
// find the peak and trough of the pulse wave
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 *= IBI; *
- }*
- }*
- if(firstBeat){ *
- firstBeat = false; *
- secondBeat = true; *
- sei(); *
- return; *
- } *
- // keep a running total of the last 10 IBI values*
- word runningTotal = 0; *
- for(int i=0; i<=8; i++){ *
_ rate = rate[i+1]; _
_ runningTotal += rate;
}
* 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 = 512;
P = 512;
T = 512;
lastBeatTime = sampleCounter;
firstBeat = true;
secondBeat = false;
}
sei();
}*
Gracias y espero me puedan ayudar._