#include <MsTimer2.h>

#define PWM 2
#define DIR 3
#define MODE 4

#define duty 5

unsigned int cnt = 0;

void TimerISR()
{
  if (cnt < duty)
  {
    digitalWrite(PWM, HIGH);
    cnt++;
  }
  else if (cnt < 10)
  {
    digitalWrite(PWM, LOW);
    cnt++;
  }
  if (cnt == 10)
  {
    cnt = 0;
  }
}


void setup() {
  // put your setup code here, to run once:
  pinMode(PWM, OUTPUT);
  pinMode(DIR, OUTPUT);
  pinMode(MODE, OUTPUT);

  digitalWrite(DIR, HIGH);
  digitalWrite(MODE, HIGH);
  
  MsTimer2::set(1, TimerISR);
  MsTimer2::start();
}

void loop() {
  // put your main code here, to run repeatedly:
  digitalWrite(DIR, HIGH);
  delay(500);
  digitalWrite(DIR, LOW);
  delay(500);
}
