I have a sensor reading values periodically, and I want to store these values in an array so that I can perform logic on the list before I do anything with it.
For example:
My code is reading the sensor value in a while loop, but I only want to record values higher than 50, and only print all the values recorded if at least one of them was higher than 150.
This would be straightforward in python, but I can't seem to figure out the array syntax in arduino.
Is there a way to do this in arduino?
Would be something like:
int sensorPin = A0;
int sensorVal = 0;
int trigger = 0;
int var = 0;
declare array of unknown length
void setup() {
Serial.begin(9600);
}
void loop() {
while (var < 200) {
val = analogRead(sensorPin);
if (val > 150)
{
trigger = 1;
}
if (val >50)
{
append val to array**
}
var++;
}
if (trigger == 1)
{
Serial.println(array);
}
}