Reputation: 9
I have a list of randomly generated 50 numbers. If i want to check the list to see if there are any numbers above 15 in it, how it should be done on Arduino IDE?
This is how i am doing it, but not working:
for (int x = 0 ; x < 50 ; x++)
{
if(list[x]>=15)
digitalWrite(ledPin, HIGH); //turn LED on
if(list[x]<15)
digitalWrite(ledPin, LOW); //turn LED off
}
Please help!
Upvotes: 0
Views: 44
Reputation: 61
If I am getting you right, you want the led to be turned on if there is at least one element higher than 15.
In this case I would do something like this:
digitalWrite(ledPin, LOW); //turn LED off
for (int x = 0 ; x < 50 ; x++)
{
if(list[x]>=15)
{
digitalWrite(ledPin, HIGH); //turn LED on
break;
}
}
Upvotes: 1