How to make LCD display the colors on the LCD and count upwards when each color

#include <AccelStepper.h>
#include <MultiStepper.h>

/* Arduino Project - Color Sorting Machine
*

  • by Ali

*/
#include <Wire.h>
#include <LiquidCrystal_I2C.h>
LiquidCrystal_I2C lcd(0x27, 2, 1, 0, 4, 5, 6, 7, 3, POSITIVE);
#include <Servo.h>

#define S0 2
#define S1 3
#define S2 5
#define S3 4
#define sensorOut 6
Servo topServo;
Servo bottomServo;
int frequency = 0;
int color=0;

const int s0 = 6;
const int s1 = 5;
const int s2 = 4;
const int s3 = 3;
const int out = 2;

int red = 0;
int green = 0;
int blue = 0;

void setup() {///////////////////////////setup

Serial.begin(9600);

digitalWrite(s0, HIGH);
digitalWrite(s1, HIGH);

lcd.begin(16,2);
lcd.clear();
lcd.print(“Color Sorter”);
lcd.setCursor(0, 1);
lcd.print(“By: Ali Atif”);

lcd.clear();
delay(5000);
lcd.print(“Welcome to my”);
delay(1000);
lcd.setCursor(0,1);
lcd.print(“Candy Sorter!”);
delay(4000);
lcd.clear();

lcd.print(“By: Ali Atif”);
lcd.setCursor(0,1);
delay(1000);
lcd.print(“Mr. Cho /TDJ4M1”);
delay(4000);
lcd.clear();

lcd.print(“Load Candy and”);
delay(1000);
lcd.setCursor(0,1);
lcd.print(“Press Start to…”);
delay(2000);
lcd.clear();
lcd.setCursor(0,1);
lcd.print(“BEGIN!Have Fun!”);
delay(5000);
lcd.clear();

pinMode(S0, OUTPUT);
pinMode(S1, OUTPUT);
pinMode(S2, OUTPUT);
pinMode(S3, OUTPUT);
pinMode(sensorOut, INPUT);
// Setting frequency-scaling to 20%
digitalWrite(S0, HIGH);
digitalWrite(S1, LOW);
topServo.attach(7);
bottomServo.attach(8);

}
void loop() {/////////////////////////////loop

//lcd.print("R: G: B: ");
//lcd.setCursor(0,1);
//delay(1000);
// lcd.print("B: O: Y: ");

topServo.write(100);
delay(500);

for(int i = 115; i > 65; i–) {
topServo.write(i);
delay(2);
}
delay(500);

color = readColor();
delay(10);
switch (color) {
case 1:
bottomServo.write(50);
break;
case 2:
bottomServo.write(75);
break;
case 3:
bottomServo.write(100);
break;
case 4:
bottomServo.write(125);
break;
case 5:
bottomServo.write(150);
break;
case 6:
bottomServo.write(175);
break;

case 0:
break;
}
delay(300);

for(int i = 65; i > 29; i–) {
topServo.write(i);
delay(2);
}
delay(200);

for(int i = 29; i < 115; i++) {
topServo.write(i);
delay(2);
}
color=0;
}
// Custom Function - readColor()
int readColor() {
// Setting red filtered photodiodes to be read
digitalWrite(S2, LOW);
digitalWrite(S3, LOW);
// Reading the output frequency
frequency = pulseIn(sensorOut, LOW);
int R = frequency;
// Printing the value on the serial monitor
Serial.print("R= “);//printing name
Serial.print(frequency);//printing RED color frequency
Serial.print(” ");
delay(50);

// Setting Green filtered photodiodes to be read
digitalWrite(S2, HIGH);
digitalWrite(S3, HIGH);
// Reading the output frequency
frequency = pulseIn(sensorOut, LOW);
int G = frequency;
// Printing the value on the serial monitor
Serial.print("G= “);//printing name
Serial.print(frequency);//printing RED color frequency
Serial.print(” ");
delay(50);

// Setting Blue filtered photodiodes to be read
digitalWrite(S2, LOW);
digitalWrite(S3, HIGH);
// Reading the output frequency
frequency = pulseIn(sensorOut, LOW);
int B = frequency;
// Printing the value on the serial monitor
Serial.print("B= “);//printing name
Serial.print(frequency);//printing RED color frequency
Serial.println(” ");
delay(50);
if(R<45 & R>32 & G<65 & G>55){
color = 1; // Red
lcd.print(“R”);
}
if(G<55 & G>43 & B<47 &B>35){
color = 2; // Orange
}
if(R<53 & R>40 & G<53 & G>40){
color = 3; // Green
}
if(R<38 & R>24 & G<44 & G>30){
color = 4; // Yellow
}
if(R<56 & R>46 & G<65 & G>55){
color = 5; // Brown
}
if (G<58 & G>45 & B<40 &B>26){
color = 6; // Blue
}
return color;
}

. . .
digitalWrite(S1, LOW);
topServo.attach(7);
bottomServo.attach(8);
. . .

Try replacing the happy face emoji with a different one and see if your code works better.

Don