Hi, I am having some trouble with my code and wondered if anyone has an idea on how I can improve it..
The reading I am getting is somewhat not satisfying.
I am using 'max' and 'min' and 'switch case' to sort them in order then display to an LCD...
The problem I am getting is to do with the ranking refresh (it's gonna be tricky for me to explain):
Basically, the position1 or P1 etc, is not automatically updating to P2 as soon as another variable becomes greater than his.... Make sense? it takes a few numbers above to actually make the transition and it seem that greater the variable, the more gap you need between the variables to make a transition...
Long story short: this is part of the code that I am not happy with:
int maximum = max(max(intOne, intTwo), max(intThree, intFour));
int minimum = min(min(intOne, intTwo), min(intThree, intFour));
int red = map(intOne, maximum, minimum, 0, 3);
switch (red){
case 0:
redPos = 1;
break;
case 1:
redPos = 2;
break;
case 2:
redPos = 3;
break;
case 3:
redPos = 4;
break;
}
int green = map(intTwo, maximum, minimum, 0, 3);
switch (green){
case 0:
greenPos = 1;
break;
case 1:
greenPos = 2;
break;
case 2:
greenPos = 3;
break;
case 3:
greenPos = 4;
break;
}
int yellow = map(intThree, maximum, minimum, 0, 3);
switch (yellow){
case 0:
yellowPos = 1;
break;
case 1:
yellowPos = 2;
break;
case 2:
yellowPos = 3;
break;
case 3:
yellowPos = 4;
break;
}
int blue = map(intFour, maximum, minimum, 0, 3);
switch (blue){
case 0:
bluePos = 1;
break;
case 1:
bluePos = 2;
break;
case 2:
bluePos = 3;
break;
case 3:
bluePos = 4;
break;
}
lcd.setCursor(0,0);
lcd.print("P");
lcd.setCursor(1,0);
lcd.print(intOne);
lcd.setCursor(0,1);
lcd.print("P");
lcd.setCursor(1,1);
lcd.print(intTwo);
lcd.setCursor(0,2);
lcd.print("P");
lcd.setCursor(1,2);
lcd.print(intThree);
lcd.setCursor(0,3);
lcd.print("P");
lcd.setCursor(1,3);
lcd.print(intFour);
Thanks in advance for any help..