user52175: How to get a pwm pin value that is in pinMode OUTPUT?
How to get a digital OUTPUT PIN value:
#define pin 3

void setup()
{
  pinMode(pin, OUTPUT);
  Serial.begin(9600);
}

void loop()
{
    delay(1000);
    digitalWrite(pin, HIGH);
    Serial.println(bitRead(PORTD,pin));
    delay(1000);
    digitalWrite(pin, LOW);
    Serial.println(bitRead(PORTD,pin));
}


For testing reasons, I want to get PWM output pin value.
Incorrect sketch:
#define pin 3

void setup()
{
  pinMode(pin, OUTPUT);
  Serial.begin(9600);
}

void loop()
{
    delay(1000);
    analogWrite(pin, 100);
    Serial.println(pulseIn(pin, HIGH)); // value of the PWM output pin
}

This sketch was created for example only.
I don't know PWM value because PWM value will be generating dynamically.
Could you explain how to get a PWM output pin value, please?

user52137: According to the source code implementation of analogWrite function
(Arduino analogWrite source code explanation).
You can use OCRnx register for reading PWM value.

52175: <p>How to get a pwm pin value that is in pinMode OUTPUT?</p>

<p><a href="https://stackoverflow.com/a/6171551">How to get a digital OUTPUT PIN value:</a></p>

<pre><code>#define pin 3

void setup()
{
  pinMode(pin, OUTPUT);
  Serial.begin(9600);
}

void loop()
{
    delay(1000);
    digitalWrite(pin, HIGH);
    Serial.println(bitRead(PORTD,pin));
    delay(1000);
    digitalWrite(pin, LOW);
    Serial.println(bitRead(PORTD,pin));
}
</code></pre>

<p><a href="https://i.stack.imgur.com/W9Ril.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/W9Ril.png" alt="enter image description here"></a></p>

<p>For testing reasons, I want to get PWM output pin value.</p>

<p><strong>Incorrect sketch:</strong></p>

<pre><code>#define pin 3

void setup()
{
  pinMode(pin, OUTPUT);
  Serial.begin(9600);
}

void loop()
{
    delay(1000);
    analogWrite(pin, 100);
    Serial.println(pulseIn(pin, HIGH)); // value of the PWM output pin
}
</code></pre>

<p>This sketch was created for example only.
I don't know PWM value because PWM value will be generating dynamically.
Could you explain how to get a PWM output pin value, please?</p>
 52137: <p>According to the source code implementation of <code>analogWrite</code> function
(<a href="https://arduino.stackexchange.com/questions/45309/arduino-analogwrite-source-code-explanation">Arduino analogWrite source code explanation</a>).</p>

<p>You can use <code>OCRnx</code> register for reading PWM value.</p>
