RGB Halo Project Issues

Hi,
I have created some code that will sort the inputted numbers into a min mid and max variable. However, the problem is whenever the inputted values are the same. The program does not recognize this.

int red;
int green;
int blue;

int mMin;
int mMid;
int mMax;

void minMidMax()
{
  mMax = green;
  if(red > mMax)
  {
    mMax = red;
  }
  if(blue>mMax)
  {
    mMax = blue;
  }

  mMin = green;
  if(red<mMin)
  {
    mMin = red;
  }
  if(blue<mMin)
  {
    mMin = blue;
  }

  if(green>mMin&&green<mMax)
  {
    mMid = green;
  }
  if(red>mMin&&red<mMax)
  {
    mMid = red;
  }
  if(blue>mMin&&blue<mMax)
  {
    mMid = blue;
  }
}
void setup() 
{
  Serial.begin(9600);
}
void loop()
{
  Serial.print("Red: ");
  while(Serial.available()==0)
  {
    
  }
  red = Serial.parseInt();
  Serial.println(red);

  Serial.print("Green: ");
  while(Serial.available()==0)
  {
    
  }
  green = Serial.parseInt();
  Serial.println(green);

  Serial.print("Blue: ");
  while(Serial.available()==0)
  {
    
  }
  blue = Serial.parseInt();
  Serial.println(blue);
  minMidMax();
  

  Serial.println(mMin);
  Serial.println(mMid);
  Serial.println(mMax);
}

Before determining mMid, you must also set mMid = green - as with min and max.

Is this a well camouflaged duplicate of
Finding the minimum, middle and maximum values?

This topic was automatically closed 120 days after the last reply. New replies are no longer allowed.