// Test project to show how picky the servo motor is.
// Before 30 November 2021, 544 ... 2400 µs was accepted and nothing outside that.
// After  30 November 2021, extra 88 µs on both sides is accepted and clipped.
//
// The original sketch was provided by Arduino user Blackfin:
//   https://forum.arduino.cc/t/50hz-pwm-on-both-pin-9-and-10/930720/5


const uint8_t pinRC1 = 9;   //OC1A output
const uint8_t pinRC2 = 10;  //OC1B output

void setup() 
{
  Serial.begin(115200);

  TCCR1A = _BV(COM1A1) | _BV(COM1B1) | _BV(WGM11);    //COM1x clear on match, set on bottom
  TCCR1B = _BV(WGM13) | _BV(WGM12)| _BV(CS11);        //WGM=14, /8 prescaler
  ICR1 = 39999;   //20mS period for timer 1
  OCR1A = 3000;   //1.5mS pulse on pin  9 for centre position
  OCR1B = 3000;   //1.5mS pulse on pin 10 for centre position

  pinMode( pinRC1, OUTPUT );
  pinMode( pinRC2, OUTPUT );

  Serial.println( "medium pulse");

  delay( 2000);
}//setup

void loop() 
{
  // Default servo signal:
  //   minimal 544 microseconds   OCR1 compare value = 1088
  //   maximum 2400 microseconds  OCR1 compare value = 4800

  Serial.println( "short pulse");
  OCR1A = 912;        // still accepted, 456 µs
  OCR1B = 1088;       // normal, 544.0 µs

  delay( 2000);

  Serial.println( "long pulse");
  OCR1A = 4976;       // still accepted, 2488 µs
  OCR1B = 4800;       // normal, 2400.0 µs

  delay( 2000);
}//loop