Go Down

Topic: which less power consumption? (Read 439 times) previous topic - next topic


Is second code less power consumption than first code?

first code:
Code: [Select]
void loop() {
int x = analogRead(A0);

second code:
Code: [Select]
void loop() {
int x = analogRead(A0);


Code does not affect the power consumption of this processor at all.


Well, not in this case anyway.  You could possibly affect power consumption by changing the duty cycle of the PWM output.

But the analogWrite() function simply changes the duty cycle by updating the appropriate OCR value for the timer in use.  if x == p, that value is already the same value and it won't change anything.

Well, if analogWrite() is given a value of 0 or 255, it uses digitalWrite() HIGH or LOW, but then if x == p it will just write that value again and that won't change anything, either.

So no, you're not going to use any more power if you call analogWrite() with the same parameters as the previous time. You might waste some processor time, but that's it.

Go Up

Please enter a valid email to subscribe

Confirm your email address

We need to confirm your email address.
To complete the subscription, please click the link in the email we just sent you.

Thank you for subscribing!

via Egeo 16
Torino, 10131