 
   }
 
-  if (y < 65) {
+  if (y < 150) {
     if (x < 300) {
       return GEAR_6;
     }  

//#define DEBUG

#define PIN_X 1
#define PIN_Y 2
#define PIN_Z 0

#define GEAR_1 1
#define GEAR_2 2

    
    Joystick.button(gear, 0);
    Joystick.send_now();

    while (get_current_gear() != 0) {
      delay(5);
    }
  }
}

void poll_handbrake() {
  int minBrakeValue = 60; // I got these values printing idle and max brake values
  int maxBrakeValue = 160;
  int rawBrake = analogRead(PIN_HANDBRAKE);
  
  if (rawBrake > maxBrakeValue) {
    rawBrake = maxBrakeValue;
  } else if (rawBrake < minBrakeValue) {
    rawBrake = minBrakeValue;
  }
  
  int normalizedBrake = (rawBrake - minBrakeValue) * (1024 / (maxBrakeValue-minBrakeValue));
  
  Joystick.X(normalizedBrake);
  Joystick.send_now();  
}

void loop() {
  #ifdef DEBUG
  debug();
  #endif

  pollShifter();
  pollHandbrake();

  delay(5);
}

