 
 // The one shot pulses are output on Digial pin 3
 
+/***************************/
+/* PIN CONNECTIONS & NAMES */
+/***************************/
+#define SERVO_PIN 9
+
+/*************/
+/* CONSTANTS */
+/*************/
+#define MIN 740
+#define MAX 2430
+#define BUFLEN 100
+#define MAXF 5
+#define MAXA 45
+#define OFFSET -40
 
 
 #define OSP_SET_WIDTH(cycles) (OCR2B = 0xff-(cycles-1))
+
+int pos;
+int maxt = MAX + OFFSET;
+int mint = MIN + OFFSET;
+int mid = round((float)(maxt+mint)/2.0);
 
 // Setup the one-shot pulse generator and initialize with a pulse width that is (cycles) clock counts long
 

{
  // Step though 0-19 cycle long pulses for demo purposes 

  for (uint8_t o = 0; o < 20; o++) {

    OSP_SET_AND_FIRE(o*F_CPU / 1000000);

    while (OSP_INPROGRESS());         // This just shows how you would wait if nessisary - not nessisary in this application. 

    _delay_ms(1000);      // Wait a sec to let the audience clap

  }


}

              // This keeps anyhting from happeneing while we get set up

  TCNT2 = 0x00;     // Start counting at bottom. 
  OCR2A = 0;      // Set TOP to 0. This effectively keeps us from counting because the counter just keeps reseting back to 0.
          // We break out of this by manually setting the TCNT higher than 0, in which case it will count all the way up to MAX and then overflow back to 0 and get locked up again.
  OSP_SET_WIDTH(cycles);    // This also makes new OCR values get loaded frm the buffer on every clock cycle. 

  TCCR2A = _BV(COM2B0) | _BV(COM2B1) | _BV(WGM20) | _BV(WGM21); // OC2B=Set on Match, clear on BOTTOM. Mode 7 Fast PWM.
  TCCR2B = _BV(WGM22)| _BV(CS20);         // Start counting now. WGM22=1 to select Fast PWM mode 7

  DDRD |= _BV(SERVO_PIN);     // Set pin to output (Note that OC2B = GPIO port PD3 = Arduino Digital Pin 3)
}

// Setup the one-shot pulse generator
