1

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);
}
}
asked Nov 12, 2015 at 13:51

1 Answer 1

0

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

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.