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);
}
}
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;
|improve this answer|||||

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.