4. Software

4.5. interrupts header


#ifndef INTERRUPT_FUNCTIONS
#define INTERRUPT_FUNCTIONS

#include "declarations.h"

/*## Interrupt service routines used for switching between servos  ##*/

void next_servo() {
  static unsigned long last_interrupt_time_1 = 0;
  unsigned long interrupt_time = millis();
  if (interrupt_time - last_interrupt_time_1 > 200) {		// This part is for debouncing the buttonpress. Debouncing is necessary
    if (curr_servo_index < last_servo) curr_servo_index++;	// to prevent multiple calls to this ISR (interrupt service routine)
    last_interrupt_time_1 = interrupt_time;			// with one buttonpress.
    ledchange = true;						//
  }
}

void previous_servo() {
  static unsigned long last_interrupt_time_2 = 0;
  unsigned long interrupt_time = millis();
  if (interrupt_time - last_interrupt_time_2 > 200) {
    if (curr_servo_index > first_servo) curr_servo_index--;
    last_interrupt_time_2 = interrupt_time;
    ledchange = true;
  }
}

/*## Interrupt service routine (pin change) ##*/

ISR (PCINT2_vect) {		// This ISR is used by the optical switches when performing a speed test
  timer = micros();
  counter++;
}

#endif