Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Using the code given (for an arduino mega), how do you find heart beat per minut

ID: 3815165 • Letter: U

Question

Using the code given (for an arduino mega), how do you find heart beat per minute and have it display in the serial port?

#include // Math Library

// variables for the pushbutton
const int buttonPin=2; // Push Button
volatile int pushValue; // value of button

// constants for the Buzzer
const int speakerPin=8;

// constants for RGB LED
const int GreenledPin = 5; // Green LED
const int RedledPin = 3; // Red LED
const int BlueledPin = 6; // Blue LED


// variables for Analog Signals
const int Analog2Pin=3; // Thermistor input
const int PulsePin=1; // Pulse sensor Input
const int PotPin=0; // Potentiometer pin
int Vth; // thermistor value

int waittime=1000;


// The setup() method runs once, when the sketch starts
void setup() {
// initialize the digital pin as an output:
pinMode(GreenledPin, OUTPUT);
pinMode(RedledPin, OUTPUT);   
pinMode(BlueledPin, OUTPUT);
// tun off RGB LEDs
digitalWrite(GreenledPin, HIGH);
digitalWrite(RedledPin, HIGH);   
digitalWrite(BlueledPin, HIGH);
//
pinMode(buttonPin,INPUT);
pinMode(speakerPin,OUTPUT);   
// Serial Comm
Serial.begin(115200);
}

// the loop() method runs over and over again,
// as long as the Arduino has power
int pot_reading; // potentiometer's value in ADC units (0:1023)
float pot_reading_volts; // potentiometer's value in Volts (0:5)
int pulse_value;
int state=0;
int Threshold=520; // for pulse
long int T0=0;
long int dT;
float HR;
void loop()
{
pulse_value = analogRead(PulsePin);
Serial.println(pulse_value);
switch (state) {
case 0:
if (pulse_value>Threshold) {
dT=millis()-T0;
T0=T0+dT;

tone(speakerPin,1000,200);
digitalWrite(GreenledPin,LOW);
digitalWrite(RedledPin,HIGH);
state=1;
}
break;
case 1:
if (pulse_value<=Threshold) {
digitalWrite(GreenledPin,HIGH);
digitalWrite(RedledPin,LOW);
state=0;
}
}
delay(1);
}

Explanation / Answer

Ans:

program: heart beat per minute

// def buffer-size four

#define ADC_BUFFER_SIZE 4

// adc buffer-static

static uint8_t seq_buffer[ADC_BUFFER_SIZE];

//usess the buffer of 4 uint8_t bytes to store analog-signal

uint32_t signal = (uint32_t) seq_buffer[0]

| (uint32_t) seq_buffer[1] << 8

| (uint32_t) seq_buffer[2] << 16

| (uint32_t) seq_buffer[3] << 24;

// heart rate measure

value = measure_heartrate(signal);

displayng heart_beat::

// static , fade effect

static void show_heartbeat_using_fade_effect(int index)

{

// red green blue

uint8_t red, green, blue;

// fade_rate & index less then 0, index greater than 3

if (!glcd || fadeRate < 0 || index < 0 || index > 3) {

// return

return;

}

// for red 0xff

red = (color[index][0] * fadeRate / 245) & 0xff;

// for green 0xff

green = (color[index][1] * fadeRate / 245) & 0xff;

// for blue 0xff

blue = (color[index][2] * fadeRate / 245) & 0xff;

// color set

glcd_color_set(glcd, red, green, blue);

// rate

fadeRate -= 16;

}

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote