   noInterrupts();
   ProcessFallOfINT(RC_RVS);
   RC_Done[RC_RVS] = 1;
-  attachInterrupt(IRPT_RVS, ISR_RVS_rise, RISING);
+  attachInterrupt(digitalPinToInterrupt(IRPT_RVS), ISR_RVS_rise, RISING);
   interrupts();
 }
 

    Serial.print("Throttle\t");
    Serial.print("Brake\t");
    Serial.print("Steer\t");
    Serial.println("(m) Distance");
}

/*---------------------------------------------------------------------------------------*/
//circleRoutine 
void circleRoutine(unsigned long seconds){
  steer(LEFT_TURN_OUT);
  delay(1000);
  seconds = seconds * 1000;
  unsigned long loopTime = millis();
  while(millis() < (loopTime + seconds)){
    moveVehicle(128);
  } 
}
/*---------------------------------------------------------------------------------------*/
void startCapturingRCState()
{
  for (int i = 1; i < 7; i++) {
    RC_Done[i] = 0;
  }
}

/*---------------------------------------------------------------------------------------*/
//done in setup, calibrate RC values for MIDDLE, MIN_RC, and MAX_RC at startup
void calibrateRC(unsigned long mic){

    Serial.print(mic);
    Serial.println("Calibration Started");
    //Step 1: Wait for controller to turn on, and leave joysticks in neutral
//    while (micros() < TEN_SECONDS_IN_MICROS ||
//    ~((RC_Done[RC_ESTP]) && (RC_Done[RC_GO]) && (RC_Done[RC_TURN]) ))
//    digitalWrite(LED_PIN_OUT, HIGH); //wait for 10 seconds to receive radio signal to Calibrate Neutral Positions on RC controller, otherwise proceed

    //Step 2: Calibrate MIDDLE
    Serial.println(RC_elapsed[RC_GO]);
    mid = RC_elapsed[RC_GO];
    Serial.print("MIDDLE \t");
    Serial.println(mid);
    mic = micros();
    
    //Step 3: Turn on LED and wait for Right joystick DOWN
    //digitalWrite(LED_PIN_OUT, HIGH);
    while(micros() < (mic + (TEN_SECONDS_IN_MICROS/4)))
    //digitalWrite(LED_PIN_OUT, HIGH);//wait
    //if
    //digitalWrite(LED_PIN_OUT, LOW);
    //Set MIN_RC
    min_rc = RC_elapsed[RC_GO];
    Serial.print("MIN_RC \t");
    Serial.println(min_rc);
    mic = micros();

    //Step 4:Turn on LED again and wait for Right joystick UP
    //digitalWrite(LED_PIN_OUT, HIGH);
    while(micros() < (mic + (TEN_SECONDS_IN_MICROS/4)))
    //digitalWrite(LED_PIN_OUT, HIGH);//wait

    max_rc = RC_elapsed[RC_GO];
    Serial.print("MAX_RC \t");
    Serial.println(max_rc);
    //digitalWrite(LED_PIN_OUT, LOW);
}

/*---------------------------------------------------------------------------------------*/
byte processRC (unsigned long *results)
{   
    // 1st pulse is aileron (position 5 on receiver; controlled by Right left/right joystick on transmitter)
    //     used for Steering
    int aileron = results[RC_TURN];
//    Serial.print("\tTurn input "); Serial.print(aileron);
    results[RC_TURN] = convertTurn(aileron);
//    Serial.print("\tTurn Cmd "); Serial.println(results[RC_TURN]);   
    /* 2nd pulse is aux (position 1 on receiver; controlled by flap/gyro toggle on transmitter) 
       will be used for selecting remote control or autonomous control. */
//    Serial.print("In processRC, received results[RC_AUTO] = "); Serial.println(results[RC_AUTO]);
    if (NUMBER_CHANNELS > 5) 
        results[RC_AUTO] = (results[RC_AUTO] > MIDDLE? HIGH: LOW);
//    Serial.print("processed results[RC_AUTO] = "); Serial.println(results[RC_AUTO]);

    /* 4th pulse is gear (position 2 on receiver; controlled by gear/mode toggle on transmitter) 
    will be used for emergency stop. D38 */
    results[RC_ESTP] = (results[RC_ESTP] > MIDDLE? HIGH: LOW);
    
    if (results[RC_ESTP] == HIGH)
    {
        E_Stop();  // already done at interrupt level
        if ((results[RC_AUTO] == LOW)  && (NUMBER_CHANNELS > 5)) // under RC control
            ;//steer(results[RC_TURN]);
        //Serial.println("Exiting processRC due to E-stop.");
        return 0x00;
    }
    
    
    if ((results[RC_AUTO] == HIGH)  && (NUMBER_CHANNELS > 5))
    {
//        Serial.println("Calling processHighLevel.");
        return 0x01;  // not under RC control
    } else {
//        Serial.println("Continuing processRC as under RC control.");
    }
    /*  6th pulse is marked throttle (position 6 on receiver; controlled by Left up/down joystick on transmitter). 
    It will be used for shifting from Drive to Reverse . D40
    */
    //results[RC_RVS] = (results[RC_RVS] > MIDDLE? HIGH: LOW);
        
// TO DO: Select Forward / reverse based on results[RC_RVS]
       
    /*   3rd pulse is elevator (position 4 on receiver; controlled by Right up/down.  
       will be used for throttle/brake: RC_Throttle
    */
    // Braking or Throttle
    if (liveBrake(results[RC_GO]))
         convertBrake (&(results[RC_GO]));

    //Accelerating
    if(liveThrottle(results[RC_RDR]))
    {
        int going = convertThrottle(results[RC_RDR]);
        moveVehicle(going);
    }
    else
    {
        moveVehicle(MIN_ACC_OUT);
    }

    steer(results[RC_TURN]); 

    /* 5th pulse is rudder (position 3 on receiver; controlled by Left left/right joystick on transmitter) 
    Not used */
//    results[RC_RDR] = (results[RC_RDR] > MIDDLE? HIGH: LOW);  // could be analog
//    Serial.println(results[RC_RDR]);
//    if (results[RC_RDR] >= HubAtZero)
//        HubSpeed_kmPh = 0;
//    else
//        HubSpeed_kmPh = HubSpeed2kmPh / results[RC_RDR];
    
//  Serial.println("");  // New line
    return 0x00;
}
/*---------------------------------------------------------------------------------------*/
void processHighLevel()
{
    SerialData Results;
    readSerial(&Serial3, &Results);
    //Throttle

    //End Throttle
    //Brake

    //End Brake
    //Steer
    int turn_signal = convertDeg(Results.angle_deg);
    steer(turn_signal);
    //End Steer
    writeSerial(&Serial3, &Results);
}
/*---------------------------------------------------------------------------------------*/
//Converts RC values to corresponding values for the PWM output
int convertTurn(int input)
{
     long int steerRange, rcRange;
     long output;
     int trueOut;
//     Serial.print("\tconvertTurn: input = \t"); Serial.print(input);
     //  Check if Input is in steer dead zone
     if ((input <= MIDDLE + DEAD_ZONE) && (input >= MIDDLE - DEAD_ZONE))
       return STRAIGHT_TURN_OUT;
       // On SPEKTRUM, MIN_RC = 1 msec = stick right; MAX_RC = 2 msec = stick left
       // On HI_TEC, MIN_RC = 1 msec = stick left; MAX_RC = 2 msec = stick right
      // LEFT_TURN_OUT > RIGHT_TURN_OUT
      else
          return input;
      
// @ToDo: Fix this so it is correct in any case.
// If a controller requires some value to be reversed, then specify that
// requirement in Settings.h, and use the setting here.
#ifdef RC_HITEC
  input = MAX_RC - (input - MIN_RC);
#endif
      
//      if (input > MIDDLE + DEAD_ZONE)
//      {  // left turn
//         steerRange = LEFT_TURN_OUT - STRAIGHT_TURN_OUT;
//         rcRange = MAX_RC - (MIDDLE + DEAD_ZONE);
//        input = input - MIDDLE - DEAD_ZONE; // originally input = middle + dead_zone
//        output = STRAIGHT_TURN_OUT + input * steerRange / rcRange;
//        //set max and min values if out of range
//        trueOut = (int)output;
//        if(trueOut > LEFT_TURN_OUT)
//            trueOut = LEFT_TURN_OUT;
//        if(trueOut < STRAIGHT_TURN_OUT)
//            trueOut = STRAIGHT_TURN_OUT;
//        return trueOut;
//    }
//      if (input < MIDDLE - DEAD_ZONE)
//      {  // right turn
//         steerRange = STRAIGHT_TURN_OUT - RIGHT_TURN_OUT;
//         rcRange = MIDDLE - DEAD_ZONE - MIN_RC;
//        input = input - DEAD_ZONE - MIDDLE;  // input is negative
//        output = STRAIGHT_TURN_OUT + input * steerRange / rcRange;
//        //set max and min values if out of range
//        trueOut = (int)output;
//        if(trueOut < RIGHT_TURN_OUT)
//            trueOut = RIGHT_TURN_OUT;
//        if(trueOut > STRAIGHT_TURN_OUT)
//            trueOut = STRAIGHT_TURN_OUT;
//        return trueOut;
//    }
}
/*---------------------------------------------------------------------------------------*/
int convertDeg(int deg)
{
    int result = STRAIGHT_TURN_OUT;
    result += (deg * 2.25);
    return result; 
}
/*---------------------------------------------------------------------------------------*/
int convertThrottle(int input)
{
    //full throttle = 227, min = 40
    const int dacRange = MAX_ACC_OUT - MIN_ACC_OUT;
    const int rcRange = MAX_RC - (MIDDLE + DEAD_ZONE);
    input -= (MIDDLE + DEAD_ZONE);
    double output = (double)input /(double)rcRange;
    output *= dacRange;
    output += MIN_ACC_OUT;
    //set max values if out of range
    int trueOut = (int)output;
    if(trueOut > MAX_ACC_OUT)
        trueOut = MAX_ACC_OUT;
    return trueOut;
}
/*---------------------------------------------------------------------------------------*/
//Tests for inputs
// Input not in throttle dead zone
boolean liveThrottle(int acc)
{
      return (acc > MIDDLE + DEAD_ZONE);
}
/*---------------------------------------------------------------------------------------*/
// Input is not in brake dead zone
boolean liveBrake(int brake)
{
      return (brake < MIDDLE - DEAD_ZONE);
}
/*---------------------------------------------------------------------------------------*/
// Emergency stop
void E_Stop()
{
    brake(MAX_BRAKE_OUT);
    moveVehicle(MIN_ACC_OUT);
    delay (2000);   // inhibit output
    // TO DO: disable 36V power
}
/*---------------------------------------------------------------------------------------*/
//Send values to output pin
void steer(int pos)
{
      STEER_SERVO.writeMicroseconds(pos);
//      Serial.print("\tSteering to: \t"); Serial.print(pos);
     steer_control = pos;
}
/*---------------------------------------------------------------------------------------*/
void convertBrake(long unsigned *amount)
{
      if (*amount < (MIDDLE + MIN_RC)/2)
          *amount = MAX_BRAKE_OUT;
      else
           *amount = MIN_BRAKE_OUT; 
      brake (*amount);     
}
/*---------------------------------------------------------------------------------------*/
void brake (int amount)
{
      analogWrite(BRAKE_OUT_PIN, amount);
 //     Serial.print("\tBraking to: \t"); Serial.print(*amount);
      brake_control = amount;
}
/*---------------------------------------------------------------------------------------*/
/* DAC_Write applies value to address, producing an analog voltage.
// address: 0 for chan A; 1 for chan B; 2 for chan C; 3 for chan D
// value: digital value converted to analog voltage
// Output goes to mcp 4802 Digital-Analog Converter Chip via SPI
// There is no input back from the chip.
*/
void DAC_Write(int address, int value)
/*
REGISTER 5-3: WRITE COMMAND REGISTER FOR MCP4802 (8-BIT DAC)
A/B — GA SHDN D7 D6 D5 D4 D3 D2 D1 D0 x x x x
bit 15 bit 0
bit 15 A/B: DACA or DACB Selection bit
1 = Write to DACB
0 = Write to DACA
bit 14 — Don’t Care
bit 13 GA: Output Gain Selection bit
1 = 1x (VOUT = VREF * D/4096)
0 = 2x (VOUT = 2 * VREF * D/4096), where internal VREF = 2.048V.
bit 12 SHDN: Output Shutdown Control bit
1 = Active mode operation. VOUT is available.
0 = Shutdown the selected DAC channel. Analog output is not available at the channel that was shut down.
VOUT pin is connected to 500 k (typical)
bit 11-0 D11:D0: DAC Input Data bits. Bit x is ignored.
With 4.95 V on Vcc, observed output for 255 is 4.08V.
This is as documented; with gain of 2, maximum output is 2 * Vref
*/
{
      int byte1 = ((value & 0xF0)>>4) | 0x10; // acitve mode, bits D7-D4
      int byte2 = (value & 0x0F)<<4; // D3-D0
      if (address < 2)
      {
          // take the SS pin low to select the chip:
          digitalWrite(SelectAB,LOW);
          if (address >= 0)
          {
              if (address == 1)
                  byte1 |= 0x80; // second channnel
              SPI.transfer(byte1);
              SPI.transfer(byte2);
          }
          // take the SS pin high to de-select the chip:
          digitalWrite(SelectAB,HIGH);
      }
      else
      {
          // take the SS pin low to select the chip:
          digitalWrite(SelectCD,LOW);
          if (address <= 3)
          {
              if (address == 3)
                  byte1 |= 0x80; // second channnel
              SPI.transfer(byte1);
              SPI.transfer(byte2);
          }
          // take the SS pin high to de-select the chip:
          digitalWrite(SelectCD,HIGH);
      }
}
/*---------------------------------------------------------------------------------------*/
void moveVehicle(int acc)
{
      /* Observed behavior on ElCano #1 E-bike no load (May 10, 2013, TCF)
      0.831 V at rest 52 counts
      1.20 V: nothing 75
      1.27 V: just starting 79
      1.40 V: slow, steady 87
      1.50 V: brisker 94
      3.63 V: max 227 counts
      255 counts = 4.08 V
      */
      DAC_Write(DAC_CHANNEL, acc);
      throttle_control = acc;    // post most recent throttle.
}

/*========================================================================/
 *============================WheelRev4 code==============================/
 *=======================================================================*/
 
/* Wheel Revolution Interrupt routine
   Ben Spencer 10/21/13
   Modified by Tyler Folsom 3/16/14; 3/3/16
   
   A cyclometer gives a click once per revolution. 
   This routine computes the speed.
*/



  // Clear the display, and then turn on all segments and decimals
  clearDisplay();  // Clears display, resets cursor
  //  setBrightness(127);  // Medium brightness
  setBrightness(255);  // High brightness
}
/*---------------------------------------------------------------------------------------*/
