int motor1 = 10;
int motor2 = 13;
int button1 = 8; 
int button2 = 11; 
int pot = A0; 
int value, state=false, dir=false;

void setup() {
  pinMode(motor1, OUTPUT);  
  pinMode(motor2, OUTPUT); 
  // prescaler = 1
  TCCR1B = TCCR1B & B11111000 | B00000001;   
  // prescaler = 8
  //TCCR1B = TCCR1B & B11111000 | B00000010;    
  // prescaler = 64
  // TCCR1B = TCCR1B & B11111000 | B00000011;    
  // prescaler = 256
  //TCCR1B = TCCR1B & B11111000 | B00000100;    
  // prescaler = 1024
  //TCCR1B = TCCR1B & B11111000 | B00000101;    
}

void loop(){
  // get direction
  if (digitalRead(button1) == HIGH) { 
    dir=!dir;
    while (digitalRead(button1) == HIGH) {
      delay(20);  
    }
  }
  
  // get speed and correct for direction
  value = map(analogRead(pot), 0, 1023, 0, 255);
  if (dir==false) value=255-value;
  
  // start/stop
  if (digitalRead(button2) == HIGH) { 
    state=!state;
    while (digitalRead(button2) == HIGH) {
      delay(20);  
    }
  } 
  
  // execute settings
  if (state==true){
    // run with PWM
    analogWrite(motor1,value);
    digitalWrite(motor2, dir); 
  }
  else
  {
    // stop
    analogWrite(motor1,0);
    digitalWrite(motor2,LOW);
  }
}
