Just learning to make my very first library. This far it has one function that I found out I need pretty often.
This has also been asked on a forum how to do this comparison, so I may publish this some day.
But like I said, I'm still learning, and this works ok, but I want one boolean to be optional (default = true)
Here is also a mystery for me, why optional is accepted in .cpp but in the .h as you can see below?
How do I do this right?
Also, english is not my mother language, so that makes a bit hard for me to figure out right words to find a solution from the net. Thanks.
//CPP
#include "is_between.h"
boolean isBetween(int givenValue, int Start, int Stop, boolean vEqual = true)
{
boolean vAliv = false;
if (Start < Stop)
{
if (vEqual && givenValue >= Start && givenValue <= Stop) // jos on rajoissa, oletuksena huomidaan annetut rajat
{
vAliv = true; // kaikki natsaa, voidaan palauttaa true
}
else // ei ole rajoissa, testataan onko equal FALSE
{
if (!vEqual && givenValue > Start && givenValue < Stop) //jos ei tartte olla just rajoissa, niin sitten ok, muuten false
{
vAliv = true; // on rajoiss, equal = FALSE
}
else // ei mene rajoihin
{
vAliv = false; // tämä testivaihe??
}
}
}
return(vAliv);
}
// .h
#ifndef IS_BETWEEN_H
#define IS_BETWEEN_H
#include <Arduino.h>
boolean isBetween(int givenValue, int Start, int Stop, boolean vEqual);
// IF I CHANGE THIS TO; boolean isBetween(int givenValue, int Start, int Stop, boolean vEqual = true);
//IDE DOES NOT COMPILE
#endif
//Test main code which works, but I must give boolean argument
#include <is_between.h>
void setup() {
// put your setup code here, to run once:
Serial.begin(115200);
}
void loop() {
// put your main code here, to run repeatedly:
Serial.println(isBetween(4,2,6, true));
}