The code below should generate a PWM signal on digital pin 3. But know I want to see if it is even working. I was thinking about a Event triggering method like ISR. But somehow it does not work. I guess a ISR needs to a Input Pin, e.g. it would work, when I would've a PWM signal coming from somewhere.
Is it even possible to generate a PWM signal and read it to see some results on the serial monitor?
edited code:
byte const PWM_PIN = 3;
volatile unsigned long pwm_value = 0;
volatile unsigned long prev_time = 0;
void setup() {
pinMode(PWM_PIN, OUTPUT);
Serial.begin(9600);
attachInterrupt(digitalPinToInterrupt(PWM_PIN), rising, RISING);
}
void loop() {
digitalWrite(PWM_PIN, HIGH);
delay(400);
digitalWrite(PWM_PIN, LOW);
delay(1600);
}
void rising() {
attachInterrupt(digitalPinToInterrupt(PWM_PIN), falling, FALLING);
prev_time = millis();
}
void falling() {
attachInterrupt(digitalPinToInterrupt(PWM_PIN), rising, RISING);
pwm_value = millis()-prev_time;
Serial.println(pwm_value);
}