Measure 2 hall-effect sensors simultaneously

As you may soon discover, this is my first programming project. I am trying to modify an existing sketch which reads fidget spinner rpms and read 2 fidget spinners at once.
Here is a link to the sketch I started from:
https://create.arduino.cc/projecthub/andriy-baranov/fidget-spinner-rpm-counter-253ac0?ref=userrespected&ref_id=401439&offset=0

I have managed to get the display to show both lines but both show the rpm from pin 2 and not pin 4. I am wondering if I need to identify the rpm input from pin 4 differently than pin 2.

Any other critique/suggestions of my sketch would be welcomed.

#include <LiquidCrystal.h>
LiquidCrystal lcd(13,12,11,10,9,8);
const int hallSensorPin1 = 2;                      // connect the hall effect sensor on pin 2
const int hallSensorPin2 = 4;
const unsigned long sampleTime = 1000;
const int maxRPM = 960;                  // maximum RPM for LCD Bar
int rpmMaximum = 0;

void setup() 
{
  pinMode(hallSensorPin1,INPUT);
  pinMode(hallSensorPin2,INPUT);
  Serial.begin(9600);
  lcd.begin(16, 2);
  lcd.print("startup");
  delay(2000);
  lcd.clear();
}

void loop() 
{
  delay(100);
  int rpm = getRPM();
  if (rpm > rpmMaximum) rpmMaximum = rpm;
  lcd.clear();
  displayRPM(rpm);
  //displayBar(rpm);
  
}
 

int getRPM()
{
  int count = 0;
  boolean countFlag = LOW;
  unsigned long currentTime = 0;
  unsigned long startTime = millis();
 while (currentTime <= sampleTime)
  {
    if (digitalRead(hallSensorPin1) == HIGH)
    {
      countFlag = HIGH;
    }
  
    if (digitalRead(hallSensorPin1) == LOW && countFlag == HIGH)
    {
      count++;
      countFlag=LOW;
    }
   
    currentTime = millis() - startTime;
  }
//  int countRpm = int(60000/float(sampleTime))*count;
//  return countRpm;
//   int count = 0;
//  boolean countFlag = LOW;
//  unsigned long currentTime = 0;
//  unsigned long startTime = millis();
  while (currentTime <= sampleTime)
  {
    if (digitalRead(hallSensorPin2) == HIGH)
    {
      countFlag = HIGH;
    }
  
    if (digitalRead(hallSensorPin2) == LOW && countFlag == HIGH)
    {
      count++;
      countFlag=LOW;
    }
   
    currentTime = millis() - startTime;
  }
  int countRpm = int(60000/float(sampleTime))*count;
  return countRpm;
}
    
void displayRPM(int rpm) 
{
  lcd.clear();
  lcd.setCursor(0,0);
  lcd.print(rpm,DEC);
  lcd.setCursor(0,1); 
  lcd.print(rpm,DEC);
  lcd.setCursor(9,0);
  lcd.print(rpmMaximum, DEC);
  lcd.setCursor(9,1);
  lcd.print(rpmMaximum, DEC);
  lcd.setCursor(13,0);
  lcd.print("MAX");
  lcd.setCursor(13,1);
  lcd.print("MAX");
  Serial.print("RPM = ");
  Serial.print(rpm);
  Serial.print("  MAX RPM = ");
  Serial.println(rpmMaximum);
}

Your code appears to take one second counting pulses from hallSensorPin1 and then it takes a further second adding the pulses from hallSensorPin2. Then it divides by 1 second, even though it counted for 2 seconds. So if one is doing 100rpm and two is doing 500rpm then your code will show 600rpm.

This can't be what you want?

There's a couple of ways to improve the code you have. I would start by returning to the single-sensor version of the getRPM() function. But I would make it take a pin number as an argument, so that it counts for one second whatever pin you gave it. Then you can call it with the different pin numbers and display the two RPM values in different places on the LCD.

The next improvement might be to count both at the same time. Use two different counters but count both of them in the same sample time.

For measuring RPM the best way is to use the interrupt hardware built into the Arduino chip. Look for examples using attachInterrupt(). The UNO has two special interrupt pins (2 and 3) which you can use to easily count pulses from these kinds of sensors. That interrupt will work independently of your main sketch. Think of it like a helper that's always counting even when you are asleep. Then you can use the values it counted at any time, even when you just woke up and haven't had time to count for a whole second yet.

In order to return the value of both sensors, you must return two values. I would suggest you declare two global variables for the values like so:

int rpm1, rpm2;

int getRPMForPin(int pin) {
  int count = 0;
  boolean countFlag = LOW;
  unsigned long startTime = millis();
  while (millis() - startTime <= sampleTime)
  {
    if (digitalRead(pin) == HIGH) countFlag = HIGH;
    else if (countFlag == HIGH)
    {
      count++;
      countFlag=LOW;
    }
  }
  return int(60000/float(sampleTime))*count;
}

void detectRPM()
{
  rpm1 = getRPMForPin(hallSensorPin1);
  rpm2 = getRPMForPin(hallSensorPin2);
}

Two immediate problems. First, inside getRPM(), by the time the first while is complete, currentTime is already > sampleTime (hence the exit from the loop) so the second while loop never gets entered. The result returned is always the rpm calculated in the first loop.

Secondly, the variables is each loop are the same so the second instance of count simply adds to the first.

Third, (I did say three, didn't I?), you can only return one value from a function call. You need to pass the values by reference (at least the second one) or use a struct.

Lastly (who's counting) you only pass one value to the displayRPM() function and then print it twice so of course it will be the same.