Please help, i dont know what is wrong with my code, the lcd on blynk app wotn update the value
#include <SoftwareSerial.h>
SoftwareSerial SwSerial(10, 11); // RX, TX
#include <BlynkSimpleStream.h>
char auth[] = "20f26fd8dbfb4d41b138e777a939f336";
WidgetLCD lcd1(V4);
WidgetLCD lcd2(V5);
BlynkTimer timer;
#include <Servo.h>
Servo TopServo;
Servo BottomServo;
#include <LiquidCrystal.h>
LiquidCrystal lcd(8, 9, 10, 11, 12, 7);
// define some values used by the panel and buttons
int lcd_key = 0;
int adc_key_in = 0;
#define btnUP 1
#define btnDOWN 2
#define btnLEFT 3
#define S0 2 //Color Sensor Attaching Number
#define S1 3
#define S2 4
#define S3 5
#define sensorOut 6
#define work11 7
#define work22 8
int candy = 0;
int candy_in = 0;
int frequency = 0;
int color = 0;
int blue;
int green;
int red;
int bluee;
int greenn;
int redd;
int blueee;
int greennn;
int reddd;
int readColor() {
digitalWrite(S2, LOW);
digitalWrite(S3, LOW); // Setting red filtered photodiodes to be read
frequency = pulseIn(sensorOut, LOW); // Reading the output frequency
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);
digitalWrite(S2, HIGH); // Setting Green filtered photodiodes to be read
digitalWrite(S3, HIGH);
frequency = pulseIn(sensorOut, LOW); // Reading the output frequency
int G = frequency; // Printing the value on the serial monitor
Serial.print("G= "); //printing name
Serial.print(frequency); //printing GREEN color frequency
Serial.print(" ");
delay(50);
digitalWrite(S2, LOW); // Setting Blue filtered photodiodes to be read
digitalWrite(S3, HIGH);
frequency = pulseIn(sensorOut, LOW); // Reading the output frequency
int B = frequency; // Printing the value on the serial monitor
Serial.print("B= "); //printing name
Serial.print(frequency); //printing BLUE color frequency
Serial.println(" ");
delay(50);
if(R < G && R < B ){
color = 1;
}
if(G < R && G < B ){
color = 2;
}
if(B < G && B < R ){
color = 3;
}
return color;
}
int read_candy(){
candy_in = analogRead(1);
Serial.println(analogRead(1));
if (candy_in < 200) return work11;
if (candy_in > 500) return work22;}
// read the buttons
int read_LCD_buttons()
{
adc_key_in = analogRead(0); // read the value from the sensor
Serial.println(analogRead(0));
if (adc_key_in < 250) return btnUP;
if (adc_key_in < 450) return btnDOWN;
if (adc_key_in < 650) return btnLEFT;
}
void project (){
Blynk.virtualWrite(V0, millis() / 1000);
Blynk.virtualWrite(V1, millis() / 60000);
lcd1.print(0, 0, " COLOR SORTING ");
blueee = bluee;
lcd2.print(0, 1, " ");
lcd2.print(1, 1, "Blue Candy = ");
lcd2.print(14, 1, blueee);
reddd = redd;
lcd1.print(0, 1, " ");
lcd1.print(0, 1, "Red Candy = ");
lcd1.print(13, 1, reddd);
greennn = greenn;
lcd2.print(0, 0, " ");
lcd2.print(0, 0, "Green Candy = ");
lcd2.print(14, 0, greennn);
lcd.setCursor(0,1); // move to the begining of the second line
lcd_key = read_LCD_buttons(); // read the buttons
switch (lcd_key) // depending on which button was pushed, we perform an action
{
case btnDOWN:
{
redd = red;
lcd.print("Red Candy = "); //printing name
lcd.print(redd); //printing RED color frequency
lcd.print(" ");
break;
}
case btnLEFT:
{
greenn = green;
lcd.print("Green Candy= "); //printing name
lcd.print(greenn); //printing GREEN color frequency
lcd.print(" "); //GREEN
break;
}
case btnUP:
{
bluee = blue;
lcd.print("Blue Candy= "); //printing name
lcd.print(bluee); //printing BLUE color frequency
lcd.print(" "); //BLUE
break;
}
}
candy = read_candy();
switch (candy)
{
case work11:
{
lcd.setCursor(0,0); // move to the begining of the first line
lcd.print(" CANDY DETECTED ");
Serial.println("CANDY DETECTED");
for(int i = 120; i > 55; i--) {
TopServo.write(i);}
delay(1000);
color = readColor();
switch (color) {
case 1:{
BottomServo.write(60);
delay(1000);
for(int i = 55; i > 35; i--) {
TopServo.write(i);}
red = red +1;
Serial.print("Red Candy = "); //printing name
Serial.print(red); //printing RED color frequency
Serial.println(" ");
break;}
case 2:{
BottomServo.write(120);
delay(1000);
for(int i = 55; i > 35; i--) {
TopServo.write(i);
}
green = green +1;
Serial.print("Green Candy= "); //printing name
Serial.print(green); //printing GREEN color frequency
Serial.println(" "); //GREEN
break;}
case 3:{
BottomServo.write(180);
delay(1000);
for(int i = 55; i > 35; i--) {
TopServo.write(i);
}
blue = blue +1;
Serial.print("Blue Candy= "); //printing name
Serial.print(blue); //printing BLUE color frequency
Serial.println(" ");
break;
}}
delay(300);
for(int i = 35; i < 120; i++) {
TopServo.write(i);
delay(2);
}
delay(500);
}
case work22:{
lcd.setCursor(0,0); // move to the begining of the second line
lcd.print(" NO CANDY ");
Serial.println(" NO CANDY ");
}
}
return;}
void setup()
{
SwSerial.begin(9600);
Serial.begin(9600);
timer.setInterval(1000L, project);
Blynk.begin(Serial, auth);
lcd.begin(16, 2); // start the library
lcd.setCursor(0,0);
lcd.print("Color Sensor"); // print a simple message
pinMode(LED_BUILTIN, OUTPUT);
pinMode(S0, OUTPUT);
pinMode(S1, OUTPUT);
pinMode(S2, OUTPUT);
pinMode(S3, OUTPUT);
pinMode(sensorOut, INPUT);
digitalWrite(S0, HIGH); //Setting frequency-scaling to 20%
digitalWrite(S1, LOW);
TopServo.attach (A2); //Servo Attaching number
BottomServo.attach(A3);
TopServo.write (120);
delay(500);
BottomServo.write (120);
delay(500);
lcd1.clear();
lcd2.clear();
lcd1.print(0, 0, " COLOR SORTING "); // use: (position X: 0-15, position Y: 0-1, "Message you want to print")
lcd1.print(0, 1, " MACHINE ");
lcd2.print(0, 0, " COLOR SORTING "); // use: (position X: 0-15, position Y: 0-1, "Message you want to print")
lcd2.print(0, 1, " MACHINE ");
}
void loop()
{
Blynk.run();
timer.run();
}