2
\$\begingroup\$

I'm working with energia for the launchpad 430 and have a rather specific question to make: is example A the equivalent in power consumption has example B, or is it that B drains more power? Thank you.

EXAMPLE A:

void setup() {
  boolean flag = false;
}
void loop() {
  flag = true;
}

EXAMPLE B:

void setup() {
  boolean flag = false;
}
void loop() {
  flag = !flag;
}
\$\endgroup\$
5
\$\begingroup\$

Assuming its not optimized, Example A loops flag = 1. Example B on the other hand, toggles every time. Flag = 0, Then Flag = 1, repeat. Based on that, Example B will have more instructions, as it takes the value of flag, inverts it and updates flag. More instructions, more processing time, more power. But since your entire code is a loop without any low-power mode, they will take the same amount of power. Example B just takes a little bit longer, but we are talking fractions of a second.

| improve this answer | |
\$\endgroup\$

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.