I want to make my code more elegant to get ekstra points from my teacher. So my plan is to use a seperet file for all my functions that I will need to use throughout the program. We are making an arduino which can calculate your BPM of your heart. So I have so far made one function and it's job is to get average of a list. here is my code!:
Now that is so far my main code. This function is made in notepad++ and I want to use it as a library for my code:
Now will this work or do I need to make the library inside the arduino IDE?
Do I need to make classes for a library to work or is this fine?
Note: I'm just a beginner at coding and please tell me if there is anything wrong with the code.
Code
#include "Helper.cs"
int measurment[10];
int measur = 0;
int reading = 0;
int counter = 0;
void setup() {
Serial.begin(9600);
}
void loop() {
while(counter < 10) { // we will get readings from the analogreader and we want to do that 10 times and then start calulating.
reading = analogRead(0);
measurment[counter] = reading;
counter++;
}
getAverage(measurment[10]); // using average to get to know if this will work or not!
}Now that is so far my main code. This function is made in notepad++ and I want to use it as a library for my code:
Code
#ifndef Helper.cs
#define Helper.cs
#include "Arduino.h"
public int getAverage(int list) {
int counter = 0;
int sum = 0;
for(int counter;counter < 10;counter++){
sum += list[counter];
}
return sum;
}
#endifNow will this work or do I need to make the library inside the arduino IDE?
Do I need to make classes for a library to work or is this fine?
Note: I'm just a beginner at coding and please tell me if there is anything wrong with the code.



