New to arduino

Hello,

I am extremely new to coding however I am coding a heart rate monitor for an assignment. Most of this is working but I am really stuck on how to count only the first reading over the calculated threshold. I have tried a few things with bools and count++ but i can not figure it out. I also don't understand how you then put this value into the LCD code as that needs to initialise before void loop. Any help will be greatly appreciated as I am a bit lost and overwhelmed

/*
*/
#include <SPI.h>
#include <Wire.h>
#include <Adafruit_GFX.h>
#include <Adafruit_SSD1306.h>

#define OLED_RESET 4
Adafruit_SSD1306 display(OLED_RESET);

#define NUMFLAKES 10
#define XPOS 0
#define YPOS 1
#define DELTAY 2

#define LOGO16_GLCD_HEIGHT 16
#define LOGO16_GLCD_WIDTH 16
static const unsigned char PROGMEM logo16_glcd_bmp[] =
{ B00000000, B11000000,
B00000001, B11000000,
B00000001, B11000000,
B00000011, B11100000,
B11110011, B11100000,
B11111110, B11111000,
B01111110, B11111111,
B00110011, B10011111,
B00011111, B11111100,
B00001101, B01110000,
B00011011, B10100000,
B00111111, B11100000,
B00111111, B11110000,
B01111100, B11110000,
B01110000, B01110000,
B00000000, B00110000 };

int Heartoutput=(A0);
int Warning=(4);
int X1=0;
int X2=0;
int X3=0;
int X4=0;
int X5=0;
float average=0;
float highest=0;
int counted=0;
int count=0;

void setup(){
// pinMode(Warning,OUTPUT);
pinMode(Heartoutput,INPUT);
// pinMode(LED,OUTPUT);
Serial.begin(115200);
}
void loop() {

Serial.begin(9600);
display.begin(SSD1306_SWITCHCAPVCC, 0x3C)

display.clearDisplay();

// text display tests
display.setTextSize(1);
display.setTextColor(WHITE);
display.setCursor(0,0);
display.println("BPM");
display.setTextColor(BLACK, WHITE); // 'inverted' text
display.display();

X5=X4;
X4=X3;
X3=X2;
X2=X1;
X1=analogRead(A0); //not a pin, not assigning value, centre value = analogue read, store the read into a value
int AVG = (X1+X2+X3+X4+X5) /5;
delay(10);

int heartreading1={analogRead(A0)};
delay (1);
int heartreading2={analogRead(A0)};
delay (1);
int heartreading3={analogRead(A0)};
delay (1);
int heartreading4={analogRead(A0)};
delay (1);
int heartreading5={analogRead(A0)};
delay (1);
int heartreading6={analogRead(A0)};
delay (1);
int heartreading7={analogRead(A0)};
delay (1);
int heartreading8={analogRead(A0)};

if (heartreading1>heartreading2)highest=heartreading1;
if (heartreading1<heartreading2)highest=heartreading2;
if (highest<heartreading3)highest=heartreading3;
if (highest<heartreading4)highest=heartreading4;
if (highest<heartreading5)highest=heartreading5;
if (highest<heartreading6)highest=heartreading6;
if (highest<heartreading7)highest=heartreading7;
if (highest<heartreading8)highest=heartreading8;

int Threshold=highest-100;

if (AVG>Threshold &)count++;

int BPM=count;
Serial.println (BPM);

//if(heartrate > Threshold) {
//digitalWrite(Indicator, HIGH);
//} else {
//digitalWrite(Indicator, LOW);
}
//delay(10)}
//if(bpm>Threshold+150)
//digitalWrite(Alarmlight, HIGH);
//digitalWrite(Alarmsound, HIGH);
//if BPM=>Threshhold(LED,HIGH);
//if BPM=<Threshhold(LED,LOW);

What made you think that your question has anything to do with the working of this Website and Forum? I have suggested to the Moderator to move it to the Programming section.

This sort of carelessness makes unnecessary work for the Moderators.

...R

Your code as posted does not compile, a few minor errors but it would be nice if they were fixed.

Take a look at how to use arrays, it will make your life easier than having variables like heartreading5 and heartreading6.

This is unusual:

  int heartreading1 = {analogRead(A0)};

Braces are not required there. Does it actually work?

int heartreading1={analogRead(A0)};
delay (1);
int heartreading2={analogRead(A0)};
delay (1);
int heartreading3={analogRead(A0)};
delay (1);
int heartreading4={analogRead(A0)};
delay (1);
int heartreading5={analogRead(A0)};
delay (1);
int heartreading6={analogRead(A0)};
delay (1);
int heartreading7={analogRead(A0)};
delay (1);
int heartreading8={analogRead(A0)};

Please read up on arrays and do it soon