IR Sensor Not working with adafruit dual stepper

Not quite sure if this is the right forum topic, let me know if I should repost in a different area.

I'm using Arduino UNO with an Adafruit Motor Shield
Adafruit Motor/Stepper/Servo Shield for Arduino v2 Kit - v2.3 - Pimoroni

and IR sensor that looks similar to this one:
3Pcs KY-022 Infrared IR Sensor Receiver Module For Sale - Banggood UK

and two 28BYJ-48 stepper motors

Small Reduction Stepper Motor - 5VDC 32-Step 1/16 Gearing– The Pi Hut

I'm powering my Uno from USB. And shield itself is connected to 6v Power source.
My IR sensor is plugged to pin A0, and is connected to the Shield/ UNO 5v pin. THe shield doesn't use pins 2 or 13 (I believe) but as the shield sits over all the UNO pins, I can't easily connect to those without removing the solder/ pins from the shield. A0-A5

I've tested each component, and all work independently of each other as expected.

I get "strange" results from the IR Sensor when I power both Stepper motors. For example:

If no motors are running, and I press the "1" button on my remote. Arduino receives the signal and correctly decodes as "404736"

If both motors are running, Arduino receives the code, but returns an incorrect code. For other buttons either the incorrect code is returned, or just a "0"

If I rotate motor from M2 on the shield, the IR sensor returns incorrect result
If I rotate motor from M4 on the the IR sensor works as I expect
If I rotate motor both motors using M2 and M4, the IR sensor only only works when M2 stepper is really slow (<0.5 RPH)
Lastly I can power both Motors at the same time (together) as expected at a sensible speed.

What can I try to get the IR sensor working as intended with both the steppers rotating?

Code is here if that is useful, but I think it's a hardware issue rather than a software issue?

Note that it's late here, so I will check back tomorrow evening for responses.

//Solve clock overflow issue ✅
//RA Motor online ✅
//Dec Motor online ✅
//Up/ down/ left/ right functions
//HOME function (RA/ DEC auto speed correction)
//Speed functions
//Max speed limit
//Lunar/ solar default speed
//Change direction functions/ Slack calculator
//Pause/ motor release functions

//======Includes=======================
#include "Arduino.h"
#include <AFMotor.h>
//IR controls
//#include "PinDefinitionsAndMore.h"
#include <IRremote.hpp>

//======Define stuff===================

#define RAMotor 1
#define DECMotor 2
#define FORWARD 1
#define BACKWARD 2
#define IR_RECEIVE_PIN A0

//====================================
//=======Classes======================
//====================================

//=======Create Classes================
class timeControl {
  public:
    unsigned long MPC;
    long countNumber;

    unsigned long currentTime;
    unsigned long storedTime;
    unsigned long TimeToWait;
    double storedNumber;
    //double waitTime;

    timeControl() {
      storedTime = savedTime(micros());
      storedNumber = 6; //
      //TimeToWait = 500000;
      currentTime = 1;
      countNumber = 2;
      _startTime = 1;
      MPC = microsPerCount();
    }

    unsigned long getTime(uint8_t currentTime = 1) { //0 = currentTime = 0, 1 = stored time, 2 = wait time, 3 = count
      if (currentTime == 0) {
        return micros(); //return the time now
      }
      else if (currentTime == 1) {
        storedTime = _storedTime;
        return storedTime; //return the time (for last time activated)
      }
      else if (currentTime == 2) {
        return TimeToWait; //return the time to wait before attempting to activate again
      }
      else if (currentTime == 3) {
        return countNumber; //return the time to wait before attempting to activate again
      }
    }
    unsigned long savedTime(unsigned long whatTime) {
      _storedTime = whatTime;  //2) Store some arbitrary time that I pass to it so I can reference it later. normally used to save the last step time
      unsigned long storedTime = _storedTime;
      return _storedTime;
    }
    double savedNumber(unsigned long whatNumber) {
      _storedNumber = whatNumber;  //2) Store some arbitrary time that I pass to it so I can reference it later. normally used to save the last step time
      unsigned long storedNumber = _storedNumber;
      return _storedNumber;
    }


    void startTimer() {
      _startTime = millis();
    }
    unsigned long get_startTime() {
      return _startTime;
    }


    double Counter (uint8_t controlCounter = 1) { //if countrolCounter = 0, then reset to 0, controlCounter = 1 then increment the counter by 1. If controlCounter = 2 then return current count

      if (controlCounter == 0) {
        _countNumber = 0;
      }
      else if (controlCounter == 1) {
        _countNumber ++;
      }
      else if (controlCounter == 2) {
        countNumber = _countNumber;
        return countNumber;

      }

    }



    unsigned long microsPerCount() {
      _endTime = micros();
      //_startTime = startTime;
      //_counts = counts;
      MPC = (_endTime  - _startTime) / _counts; //3) A function that subtracts one time against another, divides by a counter and returns the answer.
      return MPC;
    }

    unsigned long timeDifference(long startTime, long endTime) {
      _endTime = endTime;
      _startTime = startTime;
      return _endTime  - _startTime; //3) A function that subtracts one time against another and returns the answer.
    }


  private:
    unsigned long _storedTime;
    double _storedNumber;
    long _startTime;
    long _endTime;
    long _counts;
    long _countNumber;


};

//-------------------------------------
class motorControl {



  public:
    //constructor for motorControl class
    //I think this is a constructor and should execute when the object is created AND IT DOES!! YAY!
    motorControl (uint8_t motorType) {
      _type = motorType;
    }

    //No idea if this bit will work:
    //double get_incrementRPH();

    //I think these are member variables.
    int incrementIndex;
    int gap;
    double maxRPM;
    double minRPM;
    double incrementRPM;


    double steps;

    double currentRPH;

    double _motorDirection ;
    unsigned long _startTimeGTD;
    unsigned long _endTimeGTD;
    unsigned long _counterGTD;







    //Set methods so that they are available all the time
    motorControl() {

      //double _steps = get_Steps(1);
      //double this->_currentRPH = 0;
      //double _solarRPM = get_solarRPM();
      //double _lunarRPM = get_lunarRPM();
      //double _stepGap = calculate_stepGapRPM(_currentRPH, _steps);
      //double _increment = get_increment(_incrementSpeed);
      //double _increment = 1;
      //double _motorDirection = get_motorDirection();
      //int _gap = 0;
      unsigned long _startTimeGTD = 0;
      unsigned long _endTimeGTD = 0;
      unsigned long _counterGTD = 0;


    }

    void begin() {

      if (_type == RAMotor) {
        Serial.println("I'm an RA Motor!");
        currentRPH = 00;
        //_motorDirection = FORWARD;
        incrementIndex = 1;
        calc_BaseRPM(currentRPH, incrementIndex);

      }
      else if (_type == DECMotor) {
        Serial.println("I'm a DEC Motor!");
        currentRPH = 600;
        //_motorDirection = FORWARD;
        incrementIndex = 2;
        minRPM = 0;
        maxRPM = 6;
        incrementRPM = 0.01;
      }
      else {
        Serial.println("I'm an unknown Motor!");
        _motorDirection = FORWARD;
      }
      steps = 2048;
      Serial.println("Motor RPM's (current/min/max/incrementRPH/IncrementIndex/Steps");
      //calc_BaseRPM(currentRPH, incrementIndex);

      Serial.println(this->currentRPH);
      Serial.println(this->minRPM);
      Serial.println(this->maxRPM);
      Serial.println(this->incrementRPM);
      Serial.println(this->incrementIndex);
      Serial.println(this->steps);
    }


    //Functions for motorControl class
    //calculate the step gap for a given number of steps and desired output RPM
    unsigned long calc_stepGapTimeDiff(unsigned long startTimeGTD, unsigned long endTimeGTD, unsigned long counterGTD) {
      //startTime is millis (to limit overflow rollover issues - millis repeats every 47 days, micros repeats every 17 minutes)
      double _stepGap;
      unsigned long _startTimeGTD = startTimeGTD;
      unsigned long _endTimeGTD = endTimeGTD;
      unsigned long _counterGTD = counterGTD;

      _stepGap = ((_endTimeGTD - _startTimeGTD) / _counterGTD);
      return _stepGap;

    }

    long calc_stepGapRPM( double output_RPM, double _steps) {
      double _stepGap;

      if (output_RPM == 0) {
        _stepGap = -99;

      } else {

        //Serial.println("I'm in calculate_stepGapRPM");
        _stepGap = (60UL * 60UL * 1000UL * 1000UL ) / (_steps * output_RPM); //(steps * revs per hour (6 revs per hour for RA) / 3.6million MS per hour
        currentRPH = output_RPM;

      }
      return _stepGap;
    }




    void calc_BaseRPM(double baseRPM, int resolutionIndex) {
      double resolution;
      if (resolutionIndex == 1) {
        resolution = 100;
      }
      else if (resolutionIndex == 2) {
        resolution = 50;
      }
      else if (resolutionIndex == 3) {
        resolution = 10;
      }

      double _minRPM = baseRPM *  (0.95);;
      double _maxRPM = baseRPM * (1.05);;
      double _incrementRPM = (_maxRPM - _minRPM) / resolution;

      //      if (requiredStat == 1) {
      //        return _minRPM;
      //      } else if (requiredStat == 2) {
      //        return _maxRPM;
      //      } else if (requiredStat == 3)
      //        return _incrementRPM;
      //    }

      minRPM = _minRPM;
      maxRPM = _maxRPM;
      incrementRPM = _incrementRPM;
    }


  private:


    uint8_t _type;

    //double _currentRPM;


    //int gap;
    uint8_t _incrementSpeed;
    //double _increment;
    //int _incrementIndex;
    unsigned long startTimeGTD;
    unsigned long endTimeGTD;
    unsigned long counterGTD;
    int _increment;
};

//=======Objects=======================
motorControl raMotor(RAMotor) ;
motorControl decMotor(DECMotor) ;
//double whatsthis1;
//double whatsthis2;
//whatsthis1=raMotor._currentRPH;
//whatsthis2=decMotor._currentRPH;

//Serial.println(whatsthis1);
//Serial.println(whatsthis2);

AF_Stepper motor_dec_stepper(1024, 1);
AF_Stepper motor_ra_stepper(1024, 2);

timeControl RATimer;
timeControl DecTimer;
timeControl IRTimer;

//--------------------------------------
//=======Functions=====================
//--------translateIR Function----------

bool counterHasStarted;
void translateIR(unsigned long IRraw) // takes action based on IR code received
// describing Remote IR codes
//unsigned long IRraw = IrReceiver.decodedIRData.decodedRawData;
{
  //Serial.print(IrReceiver.decodedIRData.decodedRawData,HEX);
  switch (IRraw)

  {
    //Elgoo Controller
    //    case 0xFFA25D: Serial.println("POWER");       break;
    //    case 0xFFE21D: Serial.println("FUNC/STOP");   break;
    //    case 0xFF629D: Serial.println("VOL+");        break;
    //    case 0xFF22DD: Serial.println("FAST BACK");   break;
    //    case 0xFF02FD: Serial.println("PAUSE");       break;
    //    case 0xFFC23D: Serial.println("FAST FORWARD"); break;
    //    case 0xFFE01F: Serial.println("DOWN");        break;
    //    case 0xFFA857: Serial.println("VOL-");        break;
    //    case 0xFF906F: Serial.println("UP");          break;
    //    case 0xFF9867: Serial.println("EQ");          break;
    //    case 0xFFB04F: Serial.println("ST/REPT");     break;
    //    case 0xFF6897: Serial.println("0");           break;
    //    case 0xFF30CF: Serial.println("1");     break;
    //    case 0xFF18E7: Serial.println("2");     break;
    //    case 0xFF7A85: Serial.println("3");     break;
    //    case 0xFF10EF: Serial.println("4");     break;
    //    case 0xFF38C7: Serial.println("5");     break;
    //    case 0xFF5AA5: Serial.println("6");     break;
    //    case 0xFF42BD: Serial.println("7");     break;
    //    case 0xFF4AB5: Serial.println("8");     break;
    //    case 0xFF52AD: Serial.println("9");     break;

    //Sony Blu-Ray controller
    case 404758: Serial.println("Eject");        break;
    case 165: Serial.println("Input Select");
      Serial.println("Current RA RPH");
      Serial.println(raMotor.currentRPH);
      Serial.println("Current DEC RPH");
      Serial.println(decMotor.currentRPH);


      break;
    case 149: Serial.println("TV Power");    break;
    case 929045: Serial.println("Main Power");        break;

    case 404736: Serial.println("#1");
      decMotor.incrementIndex = 1;
      raMotor.incrementIndex = 1;
      Serial.println("Getting increment indexfor both motors");
      Serial.println(decMotor.incrementIndex);
      Serial.println(raMotor.incrementIndex);

      break;
    case 404737: Serial.println("#2");
      decMotor.incrementIndex = 2;
      raMotor.incrementIndex = 2;
      Serial.println("Getting increment indexfor both motors");
      Serial.println(decMotor.incrementIndex);
      Serial.println(raMotor.incrementIndex);
      break;
    case 404738: Serial.println("#3");
      decMotor.incrementIndex = 3;
      raMotor.incrementIndex = 3;
      Serial.println("Getting increment indexfor both motors");
      Serial.println(decMotor.incrementIndex);
      Serial.println(raMotor.incrementIndex);
      break;
    case 404739: Serial.println("4");          break;
    case 929028: Serial.println("5");          break;
    case 929029: Serial.println("6");          break;
    case 929030: Serial.println("7");          break;
    case 929031: Serial.println("8");          break;
    case 929032: Serial.println("9");          break;
    case 929033: Serial.println("0");          break;
    case 929127: Serial.println("Red");          break;
    case 929128: Serial.println("Green");          break;
    case 929129: Serial.println("Yellow");         break;
    case 929126: Serial.println("Blue");           break;
    case 929068: Serial.println("Top Menu");       break;
    case 929065: Serial.println("Pop Up/Menu");    break;
    case 929091: Serial.println("Return");         break;
    case 929087: Serial.println("Options");        break;
    case 929090:
      Serial.println("Home");
      Serial.println("RATimer.countNumber");
      Serial.println(RATimer.countNumber);
      if (counterHasStarted == true) { //if the counter has been run before, then
        Serial.println("I'm going to start the RA timer");
        //raMotor.get_stepGap(RATimer.microsPerCount());//calculate the micros Per Count (step gap), and store it
        RATimer.startTimer();//reset the timer
        RATimer.Counter(0); //reset the counter
      } else {
        counterHasStarted = true;
        RATimer.startTimer();
        RATimer.Counter(0);
        //raMotor.get_stepGap(raMotor.calculate_stepGapRPM(raMotor.get_solarRPM(), raMotor.get_Steps(1)) ) ;
      }
      Serial.println("New Step Gap");
      //Serial.println(raMotor.get_stepGap(0));

      Serial.println("");
      break;
    case 929081: Serial.println("Up");
      // get current speed
      Serial.println("DEC RPM before change");
      Serial.println(decMotor.currentRPH);
      decMotor.currentRPH = decMotor.currentRPH + decMotor.incrementRPM;
      Serial.println("Dec RPM after change");
      Serial.println(decMotor.currentRPH);
      DecTimer.TimeToWait = decMotor.calc_stepGapRPM(decMotor.currentRPH , decMotor.steps);
      Serial.println(DecTimer.TimeToWait);
      // get increment

      break;
    case 929082: Serial.println("Down");           break;
    case 929083: Serial.println("Left");           break;
    case 929084: Serial.println("Right");          break;
    case 929085: Serial.println("Select/OK");      break;
    case 929050: Serial.println(">");              break;
    case 929049: Serial.println("\"");             break;
    case 929051: Serial.println("<< ");            break;
    case 929052: Serial.println(">>");             break;
    case 929111: Serial.println("|<< or Pentax Shutter Release");    break;
    case 929110: Serial.println(">>| or Pentax Shutter Release");    break;
    case 929048: Serial.println("Stop");           break;
    case 929123: Serial.println("Subtitles");      break;
    case 929124: Serial.println("Audio");          break;
    case 146: Serial.println("Vol + ");            break;
    case 147: Serial.println("Vol - ");            break;
    case 148: Serial.println("Mute");              break;
    case 929118: Serial.println("Favourite");      break;
    case 929089: Serial.println("Display");        break;
    default: Serial.println(IRraw); break;

  }// End Case

  //Serial.print(step_delay);
} //END translateIR





//=======Global Variables=======================
int doit = 1;
double last_IR_Time;

//=======SET UP=======================
void setup() {
  Serial.begin(9600);
  counterHasStarted = false;
  raMotor.begin();
  decMotor.begin();
  IrReceiver.begin(IR_RECEIVE_PIN, ENABLE_LED_FEEDBACK);




  //waitTime
  Serial.println("Initialise Timers");
  RATimer.savedTime(RATimer.getTime(1));//save the time NOW
  DecTimer.savedTime(DecTimer.getTime(1));
  IRTimer.savedTime(IRTimer.getTime(1));

  RATimer.TimeToWait = raMotor.calc_stepGapRPM(raMotor.currentRPH , raMotor.steps);
  Serial.println("Debugging");
  Serial.println(raMotor.currentRPH);
  Serial.println(raMotor.steps);
  Serial.println(RATimer.TimeToWait);
  Serial.println("Debugging END");
  
  DecTimer.TimeToWait = decMotor.calc_stepGapRPM(decMotor.currentRPH , decMotor.steps);
  IRTimer.TimeToWait = 500;

  Serial.println("Print wait times: RA/DEC/IR");
  Serial.println(RATimer.TimeToWait);
  Serial.println(DecTimer.TimeToWait);
  Serial.println(IRTimer.TimeToWait);
  Serial.println("END Initialise Timers");



}
//=======MAIN LOOP=======================
void loop() {
  // raMotor.steps(2048);

  //serial
  //Wait for IR Time to pass
  //need to initialise these variables then write the code in
  if   (micros() >= IRTimer.getTime(1) + IRTimer.getTime(2)) {
    
    //Serial.println(micros());
    //Serial.println(IRTimer.getTime(1));
    //Serial.println(IRTimer.getTime(2));
    //Serial.println(IRTimer.getTime(1) + IRTimer.getTime(2));
    //Serial.println("NOW, STORED, WAIT, STORED+WAIT");
    //check the wait time here!! is it working?


    if (IrReceiver.decode()) {
      Serial.println("decoding:");
      IrReceiver.printIRResultShort(&Serial);
      //Serial.println(IrReceiver.decodedIRData.command);
      Serial.println(IrReceiver.decodedIRData.decodedRawData);
      translateIR(IrReceiver.decodedIRData.decodedRawData);
      IRTimer.savedTime(micros());
      IrReceiver.resume(); // Enable receiving of the next value
      
    }
  };


  if (micros() >= (RATimer.getTime(1) + RATimer.getTime(2)))
      
  {
    
    //Serial.println("time difference-desired difference");
    //get time now   NOW-SAVEDTIME-WAIT TIME
    //Serial.println("NOW-SAVEDTIME-WAIT TIME");
    //Serial.println(micros());
    //Serial.println(RATimer.getTime(1));
    //Serial.println(RATimer.getTime(2));
    //Serial.println("--------------------");
    //end get time now
//    Serial.println("RA WAIT TIME");
//    Serial.println(RATimer.getTime(2));
//    Serial.println("Dec WAIT TIME");
//    Serial.println(DecTimer.getTime(2));
//    Serial.println("END NOW-SAVEDTIME-WAIT TIME");
    //Serial.println("time difference-actual error gap");
    //Serial.println(RATimer.timeDifference(RATimer.getTime(1), micros())- RATimer.getTime(2));
    //Serial.println("GAP");
    //Serial.println(RATimer.getTime(2));
    motor_ra_stepper.step(1, BACKWARD, DOUBLE); // need to change direction to variable
    RATimer.savedTime(micros());//save the time of the last step
    RATimer.Counter(1);//increment the counter



  }  if (micros() >= (DecTimer.getTime(1) + DecTimer.getTime(2)))
  {
    //    Serial.println("time difference-desired difference");
    //    Serial.println(DecTimer.getTime(2));
    //Serial.println("time difference-actual error gap");
    //Serial.println(DecTimer.timeDifference(DecTimer.getTime(1), micros())- DecTimer.getTime(2));

    motor_dec_stepper.step(1, FORWARD, DOUBLE); // need to change direction to variable
    DecTimer.savedTime(micros());//save the time of the last step
    DecTimer.Counter(1);//increment the counter



  }

};

Please post a wiring diagram. Words just don't cut it for this kind of problem.

Editing this mornings post to correct the wire colours in the diagram, and to give a little more detail in expected/ unexpected results.

For example, button "1" pressed on my remote control:

IR sensor returns 929024 as expected when both motors are set to 0 RPH.
If I rotate DEC motor from M1/ M2 on the shield, the IR sensor/decoder returns unexpected result 404736.
If I rotate RA motor from M3/M4 on the the IR sensor/ decoder returns 929024 as I expect.
If I rotate motor both motors using M1/M2 and M3/M4, the IR sensor/decoder only returns expected result when M1/M2 stepper is really slow (<0.12 RPH).
Lastly I can power both Motors at the same time (together) as expected at a sensible speed - 600 RPH works fine on both.

For the "UP" button (and most other buttons), the expected result is 929081, but the unexpected result is always 0

For the "1" button the expected result is 929024, but the unexpected result is always 404736

I'll be at work so will check back on this thread in a few hours

Any ideas anyone? I've not ideas on what to try.

Hi,
Can you please post some images of your project so we can see your component layout?

Tom... :smiley: :+1: :coffee: :australia:

Thanks for the reply Tom-much appreciated :+1:. Here’s some pics.


I noticed that there are IR libraries that do not require timers - maybe that will help?

See response from Adafruit Support

Debugging your IR problem would be simpler if you worked in HEX instead of decimal.
929024 = E2D00
404736 = 62D00
Looking at it that way, you can clearly see that you are dropping the first bit.

Since the error is consistent, my guess would be that you are seeing some sort of interrupt contention or other timing interference rather than an EMI problem.

...and as my board isn't really an Adafruit, I'm not going to press adafruit support for a reply.

I notice there are IR libraries that do not require timers. I wondered if that was worth a try? I can't seem to get any IR library to work at the moment (cos I'm a noob). If anyone has anything to add about interrupt contention then I'd be very grateful, because I've no clue what that means.

I seem to be playing by myself here! :joy:

OK, so I've updated the stepper code to use onestep() rather than step() as onestep doesn't use a timer apparently. I have also changed pins from A0 to 2, which has had an interesting affect. I now get this message in the serial monitor:

decoding:
Protocol=PULSE_WIDTH Address=0x0 Command=0x0 Raw-Data=0x62D01 19 bits LSB first

Space between two detected transmission is greater than 5000 but smaller than the minimal gap of 20000 known for a protocol.
If you get unexpected results, try to increase the RECORD_GAP_MICROS in IRremote.h.

I'm looking at IRremote.h, and don't see a RECORD_GAP_MICROS, but in the file IRremote.hpp I see this at line 182:

#if !defined(RECORD_GAP_MICROS_WARNING_THRESHOLD)
// To change this value, you simply can add a line #define "RECORD_GAP_MICROS_WARNING_THRESHOLD <My_new_value>" in your ino file before the line "#include <IRremote.hpp>"
#define RECORD_GAP_MICROS_WARNING_THRESHOLD   20000
#endif

So I've changed the gap and tried all kinds of numbers up to 1000000000 and also tried going lower to 6000, but get the same messages. Does this provoke any thoughts? Any other ideas that I might try?

Here's the IRremote.hpp:

/**
 * @file IRremote.hpp
 *
 * @brief Public API to the library.
 *
 * @code
 * !!! All the macro values defined here can be overwritten with values,    !!!
 * !!! the user defines in its source code BEFORE the #include <IRremote.hpp> !!!
 * @endcode
 *
 * This file is part of Arduino-IRremote https://github.com/Arduino-IRremote/Arduino-IRremote.
 *
 ************************************************************************************
 * MIT License
 *
 * Copyright (c) 2015-2022 Ken Shirriff http://www.righto.com, Rafi Khan, Armin Joachimsmeyer
 *
 * Permission is hereby granted, free of charge, to any person obtaining a copy
 * of this software and associated documentation files (the "Software"), to deal
 * in the Software without restriction, including without limitation the rights
 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
 * copies of the Software, and to permit persons to whom the Software is furnished
 * to do so, subject to the following conditions:
 *
 * The above copyright notice and this permission notice shall be included in all
 * copies or substantial portions of the Software.
 *
 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
 * INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A
 * PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
 * HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF
 * CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE
 * OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
 *
 ************************************************************************************
 *
 * For Ken Shiriffs original blog entry, see http://www.righto.com/2009/08/multi-protocol-infrared-remote-library.html
 * Initially influenced by:
 * http://www.arduino.cc/cgi-bin/yabb2/YaBB.pl?num=1210243556
 * and http://zovirl.com/2008/11/12/building-a-universal-remote-with-an-arduino/
 */

/*
 * This library can be configured at compile time by the following options / macros:
 * For more details see: https://github.com/Arduino-IRremote/Arduino-IRremote#compile-options--macros-for-this-library
 *
 * - RAW_BUFFER_LENGTH                  Buffer size of raw input buffer. Must be even! 100 is sufficient for *regular* protocols of up to 48 bits.
 * - IR_SEND_PIN                        If specified (as constant), reduces program size and improves send timing for AVR.
 * - SEND_PWM_BY_TIMER                  Disable carrier PWM generation in software and use (restricted) hardware PWM.
 * - USE_NO_SEND_PWM                    Use no carrier PWM, just simulate an **active low** receiver signal. Overrides SEND_PWM_BY_TIMER definition.
 * - USE_OPEN_DRAIN_OUTPUT_FOR_SEND_PIN Use or simulate open drain output mode at send pin. Attention, active state of open drain is LOW, so connect the send LED between positive supply and send pin!
 * - EXCLUDE_EXOTIC_PROTOCOLS           If activated, BOSEWAVE, WHYNTER and LEGO_PF are excluded in decode() and in sending with IrSender.write().
 * - EXCLUDE_UNIVERSAL_PROTOCOLS        If activated, the universal decoder for pulse width or pulse distance protocols and decodeHash (special decoder for all protocols) are excluded in decode().
 * - DECODE_*                           Selection of individual protocols to be decoded. See below.
 * - MARK_EXCESS_MICROS                 Value is subtracted from all marks and added to all spaces before decoding, to compensate for the signal forming of different IR receiver modules.
 * - RECORD_GAP_MICROS                  Minimum gap between IR transmissions, to detect the end of a protocol.
 * - FEEDBACK_LED_IS_ACTIVE_LOW         Required on some boards (like my BluePill and my ESP8266 board), where the feedback LED is active low.
 * - NO_LED_FEEDBACK_CODE               This completely disables the LED feedback code for send and receive.
 * - IR_INPUT_IS_ACTIVE_HIGH            Enable it if you use a RF receiver, which has an active HIGH output signal.
 * - IR_SEND_DUTY_CYCLE_PERCENT         Duty cycle of IR send signal.
 * - MICROS_PER_TICK                    Resolution of the raw input buffer data. Corresponds to 2 pulses of each 26.3 µs at 38 kHz.
 * - IR_USE_AVR_TIMER*                  Selection of timer to be used for generating IR receiving sample interval.
 */

#ifndef IRremote_hpp
#define IRremote_hpp

#define VERSION_IRREMOTE "3.6.1"
#define VERSION_IRREMOTE_MAJOR 3
#define VERSION_IRREMOTE_MINOR 6

// activate it for all cores that does not use the -flto flag, if you get false error messages regarding begin() during compilation.
//#define SUPPRESS_ERROR_MESSAGE_FOR_BEGIN

/*
 * If activated, BOSEWAVE, MAGIQUEST,WHYNTER and LEGO_PF are excluded in decoding and in sending with IrSender.write
 */
//#define EXCLUDE_EXOTIC_PROTOCOLS
/****************************************************
 *                     PROTOCOLS
 ****************************************************/
/*
 * Supported IR protocols
 * Each protocol you include costs memory and, during decode, costs time
 * Copy the lines with the protocols you need in your program before the  #include <IRremote.hpp> line
 * See also SimpleReceiver example
 */

#if !defined(NO_DECODER) // for sending raw only
#  if (!(defined(DECODE_DENON) || defined(DECODE_JVC) || defined(DECODE_KASEIKYO) \
|| defined(DECODE_PANASONIC) || defined(DECODE_LG) || defined(DECODE_NEC) || defined(DECODE_SAMSUNG) \
|| defined(DECODE_SONY) || defined(DECODE_RC5) || defined(DECODE_RC6) \
|| defined(DECODE_DISTANCE) || defined(DECODE_HASH) || defined(DECODE_BOSEWAVE) \
|| defined(DECODE_LEGO_PF) || defined(DECODE_WHYNTER)))
/*
 * If no protocol is explicitly enabled, we enable all protocols
 */
#define DECODE_DENON        // Includes Sharp
#define DECODE_JVC
#define DECODE_KASEIKYO
#define DECODE_PANASONIC    // the same as DECODE_KASEIKYO
#define DECODE_LG
#define DECODE_NEC          // Includes Apple and Onkyo
#define DECODE_SAMSUNG
#define DECODE_SONY
#define DECODE_RC5
#define DECODE_RC6

#    if !defined(EXCLUDE_EXOTIC_PROTOCOLS) // saves around 2000 bytes program space
#define DECODE_BOSEWAVE
#define DECODE_LEGO_PF
#define DECODE_WHYNTER
#define DECODE_MAGIQUEST // It modifies the RAW_BUFFER_LENGTH from 100 to 112
#    endif

#    if !defined(EXCLUDE_UNIVERSAL_PROTOCOLS)
#define DECODE_DISTANCE     // universal decoder for pulse width or pulse distance protocols - requires up to 750 bytes additional program space
#define DECODE_HASH         // special decoder for all protocols - requires up to 250 bytes additional program space
#    endif
#  endif
#endif // !defined(NO_DECODER)

#if defined(DECODE_NEC) && !(~(~DECODE_NEC + 0) == 0 && ~(~DECODE_NEC + 1) == 1)
#warning "The macros DECODE_XXX no longer require a value. Decoding is now switched by defining / non defining the macro."
#endif

//#define DEBUG // Activate this for lots of lovely debug output from the IRremote core.

/****************************************************
 *                    RECEIVING
 ****************************************************/

/**
 * The length of the buffer where the IR timing data is stored before decoding
 * 100 is sufficient for most standard protocols, but air conditioners often send a longer protocol data stream
 */
#if !defined(RAW_BUFFER_LENGTH)
#  if defined(DECODE_MAGIQUEST)
#define RAW_BUFFER_LENGTH  112  // MagiQuest requires 112 bytes.
#  else
#define RAW_BUFFER_LENGTH  100  ///< Length of raw duration buffer. Must be even. 100 supports up to 48 bit codings inclusive 1 start and 1 stop bit.
//#define RAW_BUFFER_LENGTH  750  // 750 is the value for air condition remotes.
#  endif
#endif
#if RAW_BUFFER_LENGTH % 2 == 1
#error RAW_BUFFER_LENGTH must be even, since the array consists of space / mark pairs.
#endif

/**
 * MARK_EXCESS_MICROS is subtracted from all marks and added to all spaces before decoding,
 * to compensate for the signal forming of different IR receiver modules
 * For Vishay TSOP*, marks tend to be too long and spaces tend to be too short.
 * If you set MARK_EXCESS_MICROS to approx. 50us then the TSOP4838 works best.
 * At 100us it also worked, but not as well.
 * Set MARK_EXCESS to 100us and the VS1838 doesn't work at all.
 *
 * The right value is critical for IR codes using short pulses like Denon / Sharp / Lego
 *
 *  Observed values:
 *  Delta of each signal type is around 50 up to 100 and at low signals up to 200. TSOP is better, especially at low IR signal level.
 *  VS1838      Mark Excess -50 to +50 us
 *  TSOP31238   Mark Excess 0 to +50
 */
#if !defined(MARK_EXCESS_MICROS)
// To change this value, you simply can add a line #define "MARK_EXCESS_MICROS <My_new_value>" in your ino file before the line "#include <IRremote.hpp>"
#define MARK_EXCESS_MICROS    20
#endif

/**
 * Minimum gap between IR transmissions, to detect the end of a protocol.
 * Must be greater than any space of a protocol e.g. the NEC header space of 4500 us.
 * Must be smaller than any gap between a command and a repeat; e.g. the retransmission gap for Sony is around 24 ms.
 * Keep in mind, that this is the delay between the end of the received command and the start of decoding.
 */
#if !defined(RECORD_GAP_MICROS)
// To change this value, you simply can add a line #define "RECORD_GAP_MICROS <My_new_value>" in your ino file before the line "#include <IRremote.hpp>"
#define RECORD_GAP_MICROS   5000 // FREDRICH28AC / LG2 header space is 9700, NEC header space is 4500
#endif
/**
 * Threshold for warnings at printIRResult*() to report about changing the RECORD_GAP_MICROS value to a higher value.
 */
#if !defined(RECORD_GAP_MICROS_WARNING_THRESHOLD)
// To change this value, you simply can add a line #define "RECORD_GAP_MICROS_WARNING_THRESHOLD <My_new_value>" in your ino file before the line "#include <IRremote.hpp>"
#define RECORD_GAP_MICROS_WARNING_THRESHOLD   20000
#endif

/** Minimum gap between IR transmissions, in MICROS_PER_TICK */
#define RECORD_GAP_TICKS    (RECORD_GAP_MICROS / MICROS_PER_TICK) // 221 for 1100

/*
 * Activate this line if your receiver has an external output driver transistor / "inverted" output
 */
//#define IR_INPUT_IS_ACTIVE_HIGH
#ifdef IR_INPUT_IS_ACTIVE_HIGH
// IR detector output is active high
#define INPUT_MARK   1 ///< Sensor output for a mark ("flash")
#else
// IR detector output is active low
#define INPUT_MARK   0 ///< Sensor output for a mark ("flash")
#endif
/****************************************************
 *                     SENDING
 ****************************************************/
/**
 * Define to disable carrier PWM generation in software and use (restricted) hardware PWM.
 */
#if !defined(SEND_PWM_BY_TIMER) && (defined(ESP32) || defined(ARDUINO_ARCH_RP2040) || defined(PARTICLE))
#define SEND_PWM_BY_TIMER       // the best and default method for ESP32
#warning For ESP32, RP2040 and particle boards SEND_PWM_BY_TIMER is enabled by default. If this is not intended, deactivate the line over this error message in file IRremote.hpp.
#else
//#define SEND_PWM_BY_TIMER // restricts send pin on many platforms to fixed pin numbers
#endif

/**
 * Define to use no carrier PWM, just simulate an active low receiver signal.
 */
//#define USE_NO_SEND_PWM
#if defined(SEND_PWM_BY_TIMER) && defined(USE_NO_SEND_PWM)
#warning "SEND_PWM_BY_TIMER and USE_NO_SEND_PWM are both defined -> undefine SEND_PWM_BY_TIMER now!"
#undef SEND_PWM_BY_TIMER // USE_NO_SEND_PWM overrides SEND_PWM_BY_TIMER
#endif

/**
 * Define to use or simulate open drain output mode at send pin.
 * Attention, active state of open drain is LOW, so connect the send LED between positive supply and send pin!
 */
//#define USE_OPEN_DRAIN_OUTPUT_FOR_SEND_PIN
#if defined(USE_OPEN_DRAIN_OUTPUT_FOR_SEND_PIN) && !defined(OUTPUT_OPEN_DRAIN)
#warning Pin mode OUTPUT_OPEN_DRAIN is not supported on this platform -> fall back to mode OUTPUT.
#endif
/**
 * This amount is subtracted from the on-time of the pulses generated for software PWM generation.
 * It should be the time used for digitalWrite(sendPin, LOW) and the call to delayMicros()
 * Measured value for Nano @16MHz is around 3000, for Bluepill @72MHz is around 700, for Zero 3600
 */
#if !defined(PULSE_CORRECTION_NANOS)
#  if defined(F_CPU)
// To change this value, you simply can add a line #define "PULSE_CORRECTION_NANOS <My_new_value>" in your ino file before the line "#include <IRremote.hpp>"
#define PULSE_CORRECTION_NANOS (48000L / (F_CPU/MICROS_IN_ONE_SECOND)) // 3000 @16MHz, 666 @72MHz
#  else
#define PULSE_CORRECTION_NANOS 600
#  endif
#endif

/**
 * Duty cycle in percent for sent signals.
 */
#if ! defined(IR_SEND_DUTY_CYCLE_PERCENT)
#define IR_SEND_DUTY_CYCLE_PERCENT 30 // 30 saves power and is compatible to the old existing code
#endif

/**
 * microseconds per clock interrupt tick
 */
#if ! defined(MICROS_PER_TICK)
#define MICROS_PER_TICK    50
#endif

#define MILLIS_IN_ONE_SECOND 1000L
#define MICROS_IN_ONE_SECOND 1000000L
#define MICROS_IN_ONE_MILLI 1000L

#include "IRremoteInt.h"
#if !defined(USE_IRREMOTE_HPP_AS_PLAIN_INCLUDE)
#include "private/IRTimer.hpp"  // defines IR_SEND_PIN for AVR and SEND_PWM_BY_TIMER
#  if !defined(NO_LED_FEEDBACK_CODE)
#    if !defined(LED_BUILTIN)
/*
 * print a warning
 */
#warning INFO: No definition for LED_BUILTIN found -> default LED feedback is disabled.
#    endif
#include "IRFeedbackLED.hpp"
#  endif
/*
 * Include the sources here to enable compilation with macro values set by user program.
 */
#include "IRReceive.hpp"
#include "IRSend.hpp"

/*
 * Include the sources of all decoders here to enable compilation with macro values set by user program.
 */
#  if defined(DECODE_BOSEWAVE)
#include "ir_BoseWave.hpp"
#  endif
#  if defined(DECODE_DENON )       // Includes Sharp
#include "ir_Denon.hpp"
#  endif
#  if defined(DECODE_DISTANCE)     // universal decoder for pulse width or pulse distance protocols - requires up to 750 bytes additional program space
#include "ir_DistanceProtocol.hpp"
#  endif
#  if defined(DECODE_JVC)
#include "ir_JVC.hpp"
#  endif
#  if defined(DECODE_KASEIKYO) || defined(DECODE_PANASONIC)
#include "ir_Kaseikyo.hpp"
#  endif
#  if defined(DECODE_LEGO_PF)
#include "ir_Lego.hpp"
#  endif
#  if defined(DECODE_LG)
#include "ir_LG.hpp"
#  endif
#  if defined(DECODE_MAGIQUEST)
#include "ir_MagiQuest.hpp"
#  endif
#  if defined(DECODE_NEC)          // Includes Apple and Onkyo
#include "ir_NEC.hpp"
#  endif
#  if defined(DECODE_RC5) || defined(DECODE_RC6)
#include "ir_RC5_RC6.hpp"
#  endif
#  if defined(DECODE_SAMSUNG)
#include "ir_Samsung.hpp"
#  endif
#  if defined(DECODE_SONY)
#include "ir_Sony.hpp"
#  endif
#  if defined(DECODE_WHYNTER)
#include "ir_Whynter.hpp"
#  endif

#include "ir_Pronto.hpp" // pronto is an universal decoder and encoder

#include "ir_Dish.hpp" // contains only sendDISH(unsigned long data, int nbits)
#endif // #if !defined(USE_IRREMOTE_HPP_AS_PLAIN_INCLUDE)

/**
 * Macros for legacy compatibility
 */
#define RAWBUF  101  // Maximum length of raw duration buffer
#define REPEAT 0xFFFFFFFF
#define USECPERTICK MICROS_PER_TICK
#define MARK_EXCESS MARK_EXCESS_MICROS

#endif // IRremote_hpp

#pragma once


Here's my ino file:

//======Includes=======================
#include "Arduino.h"
#include <AFMotor.h>
//IR controls
//#include "PinDefinitionsAndMore.h"

#define RECORD_GAP_MICROS_WARNING_THRESHOLD 20000
#include <IRremote.hpp>

//======Define stuff===================

#define RAMotor 1
#define DECMotor 2
#define FORWARD 1
#define BACKWARD 2
#define IR_RECEIVE_PIN 2
//====================================
//=======Classes======================
//====================================

//=======Create Classes================
class timeControl {
  public:
    unsigned long MPC;
    long countNumber;

    unsigned long currentTime;
    unsigned long storedTime;
    unsigned long TimeToWait;
    double storedNumber;
    //double waitTime;

    timeControl() {
      storedTime = savedTime(millis());
      storedNumber = 6; //
      //TimeToWait = 500000;
      currentTime = 1;
      countNumber = 2;
      _startTime = 1;
      MPC = millisPerCount();
    }

    unsigned long getTime(uint8_t currentTime = 1) { //0 = currentTime = 0, 1 = stored time, 2 = wait time, 3 = count
      if (currentTime == 0) {
        return millis(); //return the time now
      }
      else if (currentTime == 1) {
        storedTime = _storedTime;
        return storedTime; //return the time (for last time activated)
      }
      else if (currentTime == 2) {
        return TimeToWait; //return the time to wait before attempting to activate again
      }
      else if (currentTime == 3) {
        return countNumber; //return the time to wait before attempting to activate again
      }
    }
    unsigned long savedTime(unsigned long whatTime) {
      _storedTime = whatTime;  //2) Store some arbitrary time that I pass to it so I can reference it later. normally used to save the last step time
      unsigned long storedTime = _storedTime;
      return _storedTime;
    }
    double savedNumber(unsigned long whatNumber) {
      _storedNumber = whatNumber;  //2) Store some arbitrary time that I pass to it so I can reference it later. normally used to save the last step time
      unsigned long storedNumber = _storedNumber;
      return _storedNumber;
    }


    void startTimer() {
      _startTime = millis();
    }
    unsigned long get_startTime() {
      return _startTime;
    }


    double Counter (uint8_t controlCounter = 1) { //if countrolCounter = 0, then reset to 0, controlCounter = 1 then increment the counter by 1. If controlCounter = 2 then return current count

      if (controlCounter == 0) {
        _countNumber = 0;
      }
      else if (controlCounter == 1) {
        _countNumber ++;
      }
      else if (controlCounter == 2) {
        countNumber = _countNumber;
        return countNumber;

      }

    }



    unsigned long millisPerCount() {
      _endTime = millis();
      //_startTime = startTime;
      //_counts = counts;
      MPC = (_endTime  - _startTime) / _counts; //3) A function that subtracts one time against another, divides by a counter and returns the answer.
      return MPC;
    }

    unsigned long timeDifference(long startTime, long endTime) {
      _endTime = endTime;
      _startTime = startTime;
      return _endTime  - _startTime; //3) A function that subtracts one time against another and returns the answer.
    }


  private:
    unsigned long _storedTime;
    double _storedNumber;
    long _startTime;
    long _endTime;
    long _counts;
    long _countNumber;


};

//-------------------------------------
class motorControl {



  public:
    //constructor for motorControl class
    //I think this is a constructor and should execute when the object is created AND IT DOES!! YAY!
    motorControl (uint8_t motorType) {
      _type = motorType;
    }

    //No idea if this bit will work:
    //double get_incrementRPH();

    //I think these are member variables.
    int incrementIndex;
    int gap;
    double maxRPM;
    double minRPM;
    double incrementRPM;


    double steps;

    double currentRPH;

    double _motorDirection ;
    unsigned long _startTimeGTD;
    unsigned long _endTimeGTD;
    unsigned long _counterGTD;







    //Set methods so that they are available all the time
    motorControl() {

      //double _steps = get_Steps(1);
      //double this->_currentRPH = 0;
      //double _solarRPM = get_solarRPM();
      //double _lunarRPM = get_lunarRPM();
      //double _stepGap = calculate_stepGapRPM(_currentRPH, _steps);
      //double _increment = get_increment(_incrementSpeed);
      //double _increment = 1;
      //double _motorDirection = get_motorDirection();
      //int _gap = 0;
      unsigned long _startTimeGTD = 0;
      unsigned long _endTimeGTD = 0;
      unsigned long _counterGTD = 0;


    }

    void begin() {

      if (_type == RAMotor) {
        Serial.println("I'm an RA Motor!");
        currentRPH = 60; // set the starting speed of the motor
        //_motorDirection = FORWARD;
        incrementIndex = 1;
        calc_BaseRPM(currentRPH, incrementIndex);

      }
      else if (_type == DECMotor) {
        Serial.println("I'm a DEC Motor!");
        currentRPH = 60;// set the starting speed of the motor
        //_motorDirection = FORWARD;
        incrementIndex = 2;
        minRPM = 0;
        maxRPM = 6;
        incrementRPM = 0.01;
      }
      else {
        Serial.println("I'm an unknown Motor!");
        _motorDirection = FORWARD;
      }
      steps = 2048;
      Serial.println("Motor RPM's (current/min/max/incrementRPH/IncrementIndex/Steps");
      //calc_BaseRPM(currentRPH, incrementIndex);

      Serial.println(this->currentRPH);
      Serial.println(this->minRPM);
      Serial.println(this->maxRPM);
      Serial.println(this->incrementRPM);
      Serial.println(this->incrementIndex);
      Serial.println(this->steps);
    }


    //Functions for motorControl class
    //calculate the step gap for a given number of steps and desired output RPM
    unsigned long calc_stepGapTimeDiff(unsigned long startTimeGTD, unsigned long endTimeGTD, unsigned long counterGTD) {
      //startTime is millis (to limit overflow rollover issues - millis repeats every 47 days, millis repeats every 17 minutes)
      double _stepGap;
      unsigned long _startTimeGTD = startTimeGTD;
      unsigned long _endTimeGTD = endTimeGTD;
      unsigned long _counterGTD = counterGTD;

      _stepGap = ((_endTimeGTD - _startTimeGTD) / _counterGTD);
      return _stepGap;

    }

    long calc_stepGapRPM( double output_RPM, double _steps) {
      double _stepGap;

      if (output_RPM == 0) {
        _stepGap = -99;

      } else {

        //Serial.println("I'm in calculate_stepGapRPM");
        _stepGap = (60UL * 60UL * 1000UL ) / (_steps * output_RPM); //(steps * revs per hour (6 revs per hour for RA) / 3.6million MS per hour
        currentRPH = output_RPM;

      }
      return _stepGap;
    }




    void calc_BaseRPM(double baseRPM, int resolutionIndex) {
      double resolution;
      if (resolutionIndex == 1) {
        resolution = 100;
      }
      else if (resolutionIndex == 2) {
        resolution = 50;
      }
      else if (resolutionIndex == 3) {
        resolution = 10;
      }

      double _minRPM = baseRPM *  (0.95);;
      double _maxRPM = baseRPM * (1.05);;
      double _incrementRPM = (_maxRPM - _minRPM) / resolution;

      //      if (requiredStat == 1) {
      //        return _minRPM;
      //      } else if (requiredStat == 2) {
      //        return _maxRPM;
      //      } else if (requiredStat == 3)
      //        return _incrementRPM;
      //    }

      minRPM = _minRPM;
      maxRPM = _maxRPM;
      incrementRPM = _incrementRPM;
    }


  private:


    uint8_t _type;

    //double _currentRPM;


    //int gap;
    uint8_t _incrementSpeed;
    //double _increment;
    //int _incrementIndex;
    unsigned long startTimeGTD;
    unsigned long endTimeGTD;
    unsigned long counterGTD;
    int _increment;
};

//=======Objects=======================
motorControl raMotor(RAMotor) ;
motorControl decMotor(DECMotor) ;
//double whatsthis1;
//double whatsthis2;
//whatsthis1=raMotor._currentRPH;
//whatsthis2=decMotor._currentRPH;

//Serial.println(whatsthis1);
//Serial.println(whatsthis2);

AF_Stepper motor_dec_stepper(1024, 1);
AF_Stepper motor_ra_stepper(1024, 2);

timeControl RATimer;
timeControl DecTimer;
timeControl IRTimer;

//--------------------------------------
//=======Functions=====================
//--------translateIR Function----------

bool counterHasStarted;
void translateIR(unsigned long IRraw) // takes action based on IR code received
// describing Remote IR codes
//unsigned long IRraw = IrReceiver.decodedIRData.decodedRawData;
{
  //Serial.print("translateIR");
  switch (IRraw)

  {
    //Elgoo Controller
    //    case 0xFFA25D: Serial.println("POWER");       break;
    //    case 0xFFE21D: Serial.println("FUNC/STOP");   break;
    //    case 0xFF629D: Serial.println("VOL+");        break;
    //    case 0xFF22DD: Serial.println("FAST BACK");   break;
    //    case 0xFF02FD: Serial.println("PAUSE");       break;
    //    case 0xFFC23D: Serial.println("FAST FORWARD"); break;
    //    case 0xFFE01F: Serial.println("DOWN");        break;
    //    case 0xFFA857: Serial.println("VOL-");        break;
    //    case 0xFF906F: Serial.println("UP");          break;
    //    case 0xFF9867: Serial.println("EQ");          break;
    //    case 0xFFB04F: Serial.println("ST/REPT");     break;
    //    case 0xFF6897: Serial.println("0");           break;
    //    case 0xFF30CF: Serial.println("1");     break;
    //    case 0xFF18E7: Serial.println("2");     break;
    //    case 0xFF7A85: Serial.println("3");     break;
    //    case 0xFF10EF: Serial.println("4");     break;
    //    case 0xFF38C7: Serial.println("5");     break;
    //    case 0xFF5AA5: Serial.println("6");     break;
    //    case 0xFF42BD: Serial.println("7");     break;
    //    case 0xFF4AB5: Serial.println("8");     break;
    //    case 0xFF52AD: Serial.println("9");     break;

    //Sony Blu-Ray controller
    case 929046: Serial.println("Eject");        break;
    case 165: Serial.println("Input Select");    break;
    case 149: Serial.println("TV Power");    break;
    case 929045: Serial.println("Main Power");        break;
    case 929024: Serial.println("1");          break;
    case 929025: Serial.println("2");          break;
    case 929026: Serial.println("3");          break;
    case 929027: Serial.println("4");          break;
    case 929028: Serial.println("5");          break;
    case 929029: Serial.println("6");          break;
    case 929030: Serial.println("7");          break;
    case 929031: Serial.println("8");          break;
    case 929032: Serial.println("9");          break;
    case 929033: Serial.println("0");          break;
    case 929127: Serial.println("Red");          break;
    case 929128: Serial.println("Green");          break;
    case 929129: Serial.println("Yellow");         break;
    case 929126: Serial.println("Blue");           break;
    case 929068: Serial.println("Top Menu");       break;
    case 929065: Serial.println("Pop Up/Menu");    break;
    case 929091: Serial.println("Return");         break;
    case 929087: Serial.println("Options");        break;
    case 929090:
      Serial.println("Home");
      Serial.println("RATimer.countNumber");
      Serial.println(RATimer.countNumber);
      if (counterHasStarted==true) {  //if the counter has been run before, then
        Serial.println("I'm going to start the RA timer");  
        //raMotor.get_stepGap(RATimer.millisPerCount());//calculate the millis Per Count (step gap), and store it
        RATimer.startTimer();//reset the timer
        RATimer.Counter(0); //reset the counter
      } else {
        counterHasStarted=true;
        RATimer.startTimer();
        RATimer.Counter(0);
        //raMotor.get_stepGap(raMotor.calculate_stepGap(raMotor.get_solarRPM(), raMotor.get_Steps(1)) ) ;
      }
      Serial.println("New Step Gap");
      //Serial.println(raMotor.get_stepGap(0));

      Serial.println("");
      break;
    case 929081: Serial.println("Up");            break;
    case 929082: Serial.println("Down");           break;
    case 929083: Serial.println("Left");           break;
    case 929084: Serial.println("Right");          break;
    case 929085: Serial.println("Select/OK");          break;
    case 929050: Serial.println(">");           break;
    case 929049: Serial.println("\"");          break;
    case 929051: Serial.println("<< ");            break;
    case 929052: Serial.println(">>");            break;
    case 929111: Serial.println("|<< or Pentax Shutter Release");    break;
    case 929110: Serial.println(">>| or Pentax Shutter Release");    break;
    case 929048: Serial.println("Stop");           break;
    case 929123: Serial.println("Subtitles");      break;
    case 929124: Serial.println("Audio");    break;
    case 146: Serial.println("Vol + ");            break;
    case 147: Serial.println("Vol - ");            break;
    case 148: Serial.println("Mute");             break;
    case 929118: Serial.println("Favourite");             break;
    case 929089: Serial.println("Display");             break;

    default: Serial.println(IRraw,HEX); break;

  }// End Case

  //Serial.print(step_delay);
} //END translateIR





//=======Global Variables=======================
int doit = 1;
double last_IR_Time;

//=======SET UP=======================
void setup() {
  Serial.begin(9600);
  counterHasStarted = false;
  raMotor.begin();
  decMotor.begin();
  IrReceiver.begin(IR_RECEIVE_PIN, ENABLE_LED_FEEDBACK);




  //waitTime
  Serial.println("Initialise Timers");
  RATimer.savedTime(RATimer.getTime(1));//save the time NOW
  DecTimer.savedTime(DecTimer.getTime(1));
  IRTimer.savedTime(IRTimer.getTime(1));

  RATimer.TimeToWait = raMotor.calc_stepGapRPM(raMotor.currentRPH , raMotor.steps);
  Serial.println("Debugging");
  Serial.println(raMotor.currentRPH);
  Serial.println(raMotor.steps);
  Serial.println(RATimer.TimeToWait);
  Serial.println("Debugging END");
  
  DecTimer.TimeToWait = decMotor.calc_stepGapRPM(decMotor.currentRPH , decMotor.steps);
  IRTimer.TimeToWait = 500;

  Serial.println("Print wait times: RA/DEC/IR");
  Serial.println(RATimer.TimeToWait);
  Serial.println(DecTimer.TimeToWait);
  Serial.println(IRTimer.TimeToWait);
  Serial.println("END Initialise Timers");



}
//=======MAIN LOOP=======================
void loop() {
  // raMotor.steps(2048);

  //serial
  //Wait for IR Time to pass
  //need to initialise these variables then write the code in
  if   (millis() >= IRTimer.getTime(1) + IRTimer.getTime(2)) {
    
    //Serial.println(millis());
    //Serial.println(IRTimer.getTime(1));
    //Serial.println(IRTimer.getTime(2));
    //Serial.println(IRTimer.getTime(1) + IRTimer.getTime(2));
    //Serial.println("NOW, STORED, WAIT, STORED+WAIT");
    //check the wait time here!! is it working?


    if (IrReceiver.decode()) {
      Serial.println("decoding:");
      IrReceiver.printIRResultShort(&Serial);
      translateIR(IrReceiver.decodedIRData.decodedRawData);
      IRTimer.savedTime(millis());
      IrReceiver.resume(); // Enable receiving of the next value
      
    }
  };


  if (millis() >= (RATimer.getTime(1) + RATimer.getTime(2)))
      
  {

    motor_ra_stepper.onestep(FORWARD, DOUBLE); // need to change direction to variable
    RATimer.savedTime(millis());//save the time of the last step
    RATimer.Counter(1);//increment the counter



  }  if (millis() >= (DecTimer.getTime(1) + DecTimer.getTime(2)))
  {
    //    Serial.println("time difference-desired difference");
    //    Serial.println(DecTimer.getTime(2));
    //Serial.println("time difference-actual error gap");
    //Serial.println(DecTimer.timeDifference(DecTimer.getTime(1), millis())- DecTimer.getTime(2));

    motor_dec_stepper.onestep(FORWARD, DOUBLE); // need to change direction to variable
    DecTimer.savedTime(millis());//save the time of the last step
    DecTimer.Counter(1);//increment the counter



  }

};

Here's my new wiring diagram- note that the adafruit board is V1

Leaving this here in case it's helpful to anyone in the future. I solved by using an IR library that doesn't use timers.

This one worked with my Sony remote:
LuisMiCa / IRsmallDecoder

#include <IRsmallDecoder.h>

Giving myself a pat on the back. Thanks to all who looked :blush:- appreciate that this was probably a weird one.