Read duty cycle of a pwm pin on Arduino Mega... ?!

delphino-999:

I don't get why saving a variable is such a big deal.

Oh, come on, don't take it so seriously, i don't think saving variables is such a big deal :slight_smile:
I just generally try to make my programms as efficient as possible (i think i'm not very good at that though :)) and i thought if there would be something like digitalRead() except for reading the pwm duty cycle, i could have used that instead of having to save all the values in variables (although, i was already woundering, if assuming that would be possible, it wouldn't take alot more time to read the duty cycles instead of reading them from the variables).

The value was in a variable when you did the analogWrite, so why not use that again?
The problem is, the variables that are used for the analogWrite, are the parameters passed to the function, and they get overwritten each time the function is called... But never mind, i'll just save them to variables, i just wanted to ask, i mean it could have been as easy as digitalRead, who knows...

Thanks for all the replys...

Delphiño

That makes no sense. The contents of the variable you pass to the analogWrite function do not change due to the fact that you called that function. The function uses the value but does not change it. The contents of the variable remain the same until you yourself change them else where in your sketch. Hence your sketch already knows the current duty cycle being outputted, it was and is the contents of the variable you used in the last call to the analogWrite function. I think you are trying to see a problem that does not exist. Your sketch knows where you last left your car keys, even if you yourself can't recall.
Lefty