03-08-2018 01:27 PM
Good, I summarize my problem: I have a series of conditions and each time one of them is fulfilled I would like a led to light up and an accountant to increase, that is, having 4 conditions, there would have to be 4 counters. I show it in an image what I have done together with the code in java so they can understand me.
Java code:
for (i = 0; i <10; i ++)
if (x <0.25) {
Turn on a led1;
r1 = r1 + 1;
} else if (x> = 0.25 & <= 0.5) {
Turn on a led2;
r2 = r2 + 1;
} else if (x> 0.5 & x <= 0.75) {
I turn on a led3;
r3 = r3 + 1;
} else {
I turn on a led4;
r4 = r4 + 1;
}
}
I have made the conditions and the for loop, but I do not know how to pass a counter to each condition so that each time one of the ifs is fulfilled, the respective led lights up and the counter accumulates.
I hope you can help me !!
Solved! Go to Solution.
03-08-2018 02:03 PM - edited 03-08-2018 02:05 PM
The is an In Range and Coerce for comparing to an upper and lower limit. But you can convert the boolean result of a comparison to a 0 or 1 and add it to a shift register initialized to 0. Do this for each of the ranges. Here are the first two cases.
What do you want to do with the LED? Once they are lit up, what happens to them on the next iteration?