Take the 2-minute tour ×
Electrical Engineering Stack Exchange is a question and answer site for electronics and electrical engineering professionals, students, and enthusiasts. It's 100% free, no registration required.

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;
}
share|improve this question
add comment

1 Answer 1

up vote 4 down vote accepted

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.

share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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