I'm having trouble with the syntax of code. I want to have the motor turn when the next average the program measures is 100 or more greater than the previous average it measured. I don't know how to write the if statement:
if(average == (average>=100)) {
for(pos = 0; pos <= 120; pos += 1) {
sServo.write(pos);
delay(50);
}
for(pos = 120; pos >= 0; pos -= 1) {
sServo.write(pos);
delay(50);
}
}
1 Answer 1
The motor should
turn when the next average the program measures is 100 or more greater than the previous average it measured
So simply write it:
// Old average is called "average"
// Compute the new average and put it in next_average
if ((next_average - average) >= 100)
{
// Turn the motor
}
average = next_average;
answered Nov 12, 2015 at 14:50
default