Thank you for the help! It works now. Reading the signal on Pin 10 works. Now I have connected Pin 9 and Pin 6 by a cable. My current code looks like this:
#include "TimerOne.h"
unsigned long pwm_high = 0;
unsigned long current_t = 0;
volatile byte flag = LOW;
void setup()
{
Serial.begin(9600);
pinMode(10, OUTPUT);
pinMode(9, OUTPUT);
pinMode(6, INPUT);
Timer1.initialize(50000); // initialize timer1, and set a 1/2 second period
Timer1.pwm(9, 128); // setup pwm on pin 9, 50% duty cycle
Timer1.attachInterrupt(callback);
sei();
}
void loop()
{
Serial.print(digitalRead(6));
/*if(flag == HIGH)
{
Serial.print(millis());
Serial.print(F(": "));
Serial.println(digitalRead(10));
flag = LOW;
}*/
}
void callback()
{
digitalWrite(10, !digitalRead(10));
flag = HIGH;
Serial.print("X");
}
And the output on my Serial Monitor like: 00011X11100000000000000000000000000000000000000000011X1110000
The goal was to actual see the PWM with duty cycle ~25%. But I am not sure how this works. When my timer1 overflows after 50ms so is the period of time for my pwm equal to 50ms right? And 25% of these 50ms should be on HIGH, but it turned out as wrong.