Hi,
I'm getting a bit mad with the issue I have at the moment : on the code below the minVal doesn't want to be anything except 0 !
I have introduced a test at the beginning of the loop to check the first run fo the loop and here is the result :
15:36:43.946 -> 24 24 24 24 24 24 24 24
15:36:43.979 -> Min value : 24
15:36:48.952 -> Min value : 0
So something is happening between the end of the setup and the very beginning of the loop.
Looking for more than an hour now and no clue what is it ![]()
Can you have a fresh look and let me know what I have done wrong ?
#include <Adafruit_BME280.h>
#define adresseI2CduBME280 0x76
Adafruit_BME280 bme;
unsigned long action2 = 0;
unsigned long t = 0;
int myArray[8] = {};
int maxVal ;
int minVal ;
int index = 0 ;
/*------------------------------------ Setup ------------------------------------*/
void setup()
{
Serial.begin(9600);
bme.begin(adresseI2CduBME280);
int maxVal = bme.readTemperature(); // Set up values for the start
int minVal = bme.readTemperature();
for (int i = 0; i < 8; i++)
{
myArray[i] = bme.readTemperature(); // Set all values of the array for the start
}
for (int i = 0; i < 8; i++)
{
Serial.print(myArray[i]);Serial.print(" "); // Check all is well in the array
}
Serial.println();
Serial.print("Min value : "); Serial.println(minVal); // Check if the value is indeed the current temperature
delay(5000);
}
/*------------------------------------ Loop ------------------------------------*/
void loop()
{
Serial.print("Min value : "); Serial.println(minVal); // Check if there is a difference between loop and setup
delay(2000);
t = millis();
for (int i = 0; i < 8 ; i++) // Test and attribute min & max
{
if (myArray[i] > maxVal)
{
maxVal = myArray[i];
Serial.println("salut");
}
if (myArray[i] < minVal)
{
minVal = myArray[i];
Serial.println("coucou");
}
}
if ( ( t - action2 ) > 2000 ) // Update value of array every 2 secondes
{
action2 = t;
index = index+1 ;
if (index > 8) {index=1;}
myArray[index] = bme.readTemperature();
Serial.print("Max value is : "); Serial.println(maxVal);
Serial.print("Min value is : "); Serial.println(minVal);
Serial.println(index);
}
}