Need someone to modify this code

I have this code , and i went to change from using button to 3 Capacitive Touch sensor with these options ;
1st Switch:

  • Gives an option of 1tsp scale (5ml)

2nd Switch:

  • Gives an option of 1tbsp scale (15ml)

3rd Switch: (Cup Scale)
This have 3 options inside of it,

  • 1/4 Cup (62.5 ml)
  • 1/2 Cup (125 ml)
  • 1 Cup (250 ml)

how can I build it ?

#include <LiquidCrystal_I2C.h> 
#include <Servo.h>
Servo servo;
// Set the LCD address to 0x27 for a 16 chars and 2 line display
LiquidCrystal_I2C lcd(0x27, 16, 2);


int z = 1;
int led1 = 2;
int led2 = 3;
int led3 = 4;
int filled_led = 5;
int sensor = 6;
// servo = 7
int pump = 8;
int mode = 9;
int buzzer = 10;
int start = 11;


 
void setup() 
{

  // initialize the LCD
  lcd.begin();
  // Turn on the blacklight and print a message.
 lcd.backlight();
 tone(buzzer, 500);
  delay(100);
  noTone(buzzer);
  
   lcd.setCursor(0,0); // column, row
  lcd.print("     Welcome    ");
  lcd.setCursor(0,1); // column, row 
  lcd.print(" Experiment UAE ");
  delay(3500);
  
  lcd.setCursor(0,0); // column, row
  lcd.print(" Pow_Fill ver.1 ");
  lcd.setCursor(0,1); // column, row
  lcd.print("      2020      ");
  delay(2500);
   if(digitalRead(sensor) == HIGH)
 tone(buzzer, 500);
  delay(100);
  noTone(buzzer);
                                                                                                                                                                       
   
 lcd.clear();
 pinMode(start, INPUT_PULLUP);
 pinMode (led1,OUTPUT);
 pinMode (led2,OUTPUT);
 pinMode (led3,OUTPUT);
  pinMode(pump, OUTPUT);
 pinMode (filled_led,OUTPUT);
 pinMode (buzzer,OUTPUT);
 pinMode (sensor, INPUT);
 servo.attach(7);
 servo.write(180);

}
void loop()
{

   int button = digitalRead(mode);
  
  if (button == HIGH)
  {
 tone(buzzer, 500);
  delay(150);
  noTone(buzzer);
  {
    if(z<3)
    z ++;
    else
    z=1;
  }
  }
////////////////////////////////////////////////MODE 1
  
  if 
  (z==1)
  
  {
  digitalWrite (led2,LOW);
  digitalWrite (led3,LOW);
  digitalWrite (led1,HIGH);
   lcd.setCursor(0,0); // column, row
  lcd.print(" PACK 1 #  25Gr"); 
  }
  while(digitalRead(start) == LOW)
{
  if(digitalRead(sensor) == LOW)
  {
      lcd.setCursor(0,1); // column, row
  lcd.print("  Press Start   ");
  }
 if(digitalRead(sensor) == HIGH)
  {
   lcd.setCursor(0,1); // column, row
  lcd.print("   Place Bag    ");
  
  }

  
  if (digitalRead (button) == HIGH)
  break;
}
  ///////////////////////////////////////////////MODE 2
  
  if 
  (z==2)
  {
  digitalWrite (led2,HIGH);
  digitalWrite (led3,LOW);
  digitalWrite (led1,LOW);
   lcd.setCursor(0,0); // column, row
  lcd.print(" PACK 2 #  50Gr"); 
  }
  while(digitalRead(start) == LOW)
{
  if(digitalRead(sensor) == LOW)
  {
       lcd.setCursor(0,1); // column, row
  lcd.print("  Press Start   ");
  }
 if(digitalRead(sensor) == HIGH)
  {
   lcd.setCursor(0,1); // column, row
  lcd.print("   Place Bag    ");
  }

  
  if (digitalRead (button) == HIGH)
  break;
}

//////////////////////////////////////////////////MODE 3
  
   if 
  (z==3
    
  )
  {
  digitalWrite (led2,LOW);
  digitalWrite (led3,HIGH);
  digitalWrite (led1,LOW);
   lcd.setCursor(0,0); // column, row
  lcd.print(" PACK 3 #  75Gr"); 
  }
  while(digitalRead(start) == LOW)
{
  if(digitalRead(sensor) == LOW)
  {
     lcd.setCursor(0,1); // column, row
  lcd.print("  Press Start   ");
  }
 if(digitalRead(sensor) == HIGH)
  {
   lcd.setCursor(0,1); // column, row
  lcd.print("   Place Bag    ");
  
  }

  
  if (digitalRead (button) == HIGH)
  break;
}

/////////////////////////////////////////////////////////////////////////////////////////////////////////////
    delay(200);


     if(digitalRead(start) == HIGH && z==1 && digitalRead(sensor) == LOW ) 
{
 tone(buzzer,500);
  delay(100);
  noTone(buzzer);
   lcd.setCursor(0,1); // column, row
  lcd.print("   Filling... ");
  digitalWrite (pump,HIGH);
   //<<<=========================================<<< To Calibrate MODE 1, Change this Value
 servo.write(30);
 delay(1000);
  digitalWrite (pump,LOW);
  servo.write(180);

 
  
  lcd.setCursor(0,1); // column, row
  lcd.print("Packing Complete");
  
  
  digitalWrite (filled_led,HIGH);
  delay(400);
  tone(buzzer, 500);
  delay(300);
  noTone(buzzer);
  delay(30);
   tone(buzzer, 500);
  delay(150);
  noTone(buzzer);
  delay(30);
   tone(buzzer, 500);
  delay(300);
  noTone(buzzer);
  delay(1000);
  digitalWrite (filled_led,LOW);
  
  while(digitalRead(sensor) == LOW) 
  {
    if(digitalRead(start) == HIGH)
    {
  lcd.setCursor(0,1); // column, row
  lcd.print(" Place New Bag  ");
   tone(buzzer, 500);
  delay(100);
  noTone(buzzer);
  delay(30);
   tone(buzzer, 500);
  delay(100);
  noTone(buzzer);
  
    }
if(digitalRead(mode) == HIGH)
    {
  lcd.setCursor(0,1); // column, row
  lcd.print("   Remove BAG   ");
   tone(buzzer, 500);
  delay(200);
  noTone(buzzer);
  delay(30);
   tone(buzzer, 500);
  delay(200);
  noTone(buzzer);
  
    }
    
 if(digitalRead(sensor) == HIGH)
 break;
}
 delay(200);
}
if(digitalRead(start) == HIGH && z==1 && digitalRead(sensor) == HIGH ) 

{
   lcd.setCursor(0,1); // column, row
  lcd.print(" Error! No BAG ");
   tone(buzzer, 500);
  delay(1000);
  noTone(buzzer);

}

 
if(digitalRead(start) == HIGH && z==1 && digitalRead(sensor) == HIGH ) 

{
   lcd.setCursor(0,1); // column, row
  lcd.print("   Place Bag    ");
   tone(buzzer, 500);
  delay(1000);
  noTone(buzzer);
  delay(30);
   tone(buzzer, 500);
  delay(1000);
  noTone(buzzer);

}



     if(digitalRead(start) == HIGH && z==2 && digitalRead(sensor) == LOW ) 
{
 tone(buzzer,500);
  delay(100);
  noTone(buzzer);
   lcd.setCursor(0,1); // column, row
  lcd.print("   Filling... ");
  digitalWrite (pump,HIGH);
   //<<<=========================================<<< To Calibrate MODE 1, Change this Value
 servo.write(30);
 delay(2000);
  digitalWrite (pump,LOW);
  servo.write(180);


  
  lcd.setCursor(0,1); // column, row
  lcd.print("Packing Complete");
  
  
  digitalWrite (filled_led,HIGH);
  delay(400);
  tone(buzzer, 500);
  delay(300);
  noTone(buzzer);
  delay(30);
   tone(buzzer, 500);
  delay(150);
  noTone(buzzer);
  delay(30);
   tone(buzzer, 500);
  delay(300);
  noTone(buzzer);
  delay(1000);
  digitalWrite (filled_led,LOW);
  
  while(digitalRead(sensor) == LOW) 
  {
    if(digitalRead(start) == HIGH)
    {
  lcd.setCursor(0,1); // column, row
  lcd.print(" Place New Bag  ");
   tone(buzzer, 500);
  delay(100);
  noTone(buzzer);
  delay(30);
   tone(buzzer, 500);
  delay(100);
  noTone(buzzer);
  
    }
if(digitalRead(mode) == HIGH)
    {
  lcd.setCursor(0,1); // column, row
  lcd.print("   Remove Bag   ");
   tone(buzzer, 500);
  delay(200);
  noTone(buzzer);
  delay(30);
   tone(buzzer, 500);
  delay(200);
  noTone(buzzer);
  
    }
    
 if(digitalRead(sensor) == HIGH)
 break;
}
 delay(200);
}
if(digitalRead(start) == HIGH && z==2 && digitalRead(sensor) == HIGH ) 

{
   lcd.setCursor(0,1); // column, row
  lcd.print(" Error! No Bag ");
   tone(buzzer, 500);
  delay(1000);
  noTone(buzzer);

}

 
if(digitalRead(start) == HIGH && z==2 && digitalRead(sensor) == HIGH ) 

{
   lcd.setCursor(0,1); // column, row
  lcd.print("   Place Bag    ");
   tone(buzzer, 500);
  delay(1000);
  noTone(buzzer);
  delay(30);
   tone(buzzer, 500);
  delay(1000);
  noTone(buzzer);

}



     


     if(digitalRead(start) == HIGH && z==3 && digitalRead(sensor) == LOW ) 
{
tone(buzzer,500);
  delay(100);
  noTone(buzzer);
   lcd.setCursor(0,1); // column, row
  lcd.print("   Filling... ");
  digitalWrite (pump,HIGH);
   //<<<=========================================<<< To Calibrate MODE 1, Change this Value
 servo.write(30);
 delay(3000);
  digitalWrite (pump,LOW);
  servo.write(180);


  
  lcd.setCursor(0,1); // column, row
  lcd.print("Packing Complete");
 
  
  digitalWrite (filled_led,HIGH);
  delay(400);
  tone(buzzer, 500);
  delay(300);
  noTone(buzzer);
  delay(30);
   tone(buzzer, 500);
  delay(150);
  noTone(buzzer);
  delay(30);
   tone(buzzer, 500);
  delay(300);
  noTone(buzzer);
  delay(1000);
  digitalWrite (filled_led,LOW);
  
  while(digitalRead(sensor) == LOW) 
  {
    if(digitalRead(start) == HIGH)
    {
  lcd.setCursor(0,1); // column, row
  lcd.print(" Place New Bag  ");
   tone(buzzer, 500);
  delay(100);
  noTone(buzzer);
  delay(30);
   tone(buzzer, 500);
  delay(100);
  noTone(buzzer);
  
    }
if(digitalRead(mode) == HIGH)
    {
  lcd.setCursor(0,1); // column, row
  lcd.print("   Remove Bag   ");
   tone(buzzer, 500);
  delay(200);
  noTone(buzzer);
  delay(30);
   tone(buzzer, 500);
  delay(200);
  noTone(buzzer);
  
    }
    
 if(digitalRead(sensor) == HIGH)
 break;
}
 delay(200);
}
if(digitalRead(start) == HIGH && z==3 && digitalRead(sensor) == HIGH ) 

{
   lcd.setCursor(0,1); // column, row
  lcd.print(" Error! No Bag ");
   tone(buzzer, 500);
  delay(1000);
  noTone(buzzer);

}

 
if(digitalRead(start) == HIGH && z==3 && digitalRead(sensor) == HIGH ) 

{
   lcd.setCursor(0,1); // column, row
  lcd.print("   Place Bag    ");
   tone(buzzer, 500);
  delay(1000);
  noTone(buzzer);
  delay(30);
   tone(buzzer, 500 );
  delay(1000);
  noTone(buzzer);

}
}

Something smells very bad.

Different new user here, but they have the same request as another new user.

What’s going on ?

nooralsadah ahmad2030

1 Like

agreed - ditto.

Looks like they are opposite. They should just swap code files and be happy.

-jim lee

thank for your replay , but
I don’t understand … how it can be ?

My mistake… They are identical.

“i went to change from using button to 3 Capacitive Touch sensor”
“i went to change from using button to 3 Capacitive Touch sensor”

even down to the misspellings.

You DO know that pretending to be someone else AND reposting the same question is like double social suicide around here? Right?

-jim lee

2 Likes

This forum works like this:

You post your best attempt how you think the coding is done.
Of course as a beginner you will have a lot of questions. All these questions will be answered if you show some own effort to improve your knowledge.

The question you have posted is a diplomatic masked way of asking

“Can somebody write the code for me?”

The work you are asking for is much more than
“can somebody please post the 1024 characters long cheat-code to reach platinum-level?”

Write a description of your knowledge-level about coding. Make a first try how a first step of modification might look like.

With this information your potential helpers can give adequate advice what step to do next.

So whatever your concrete question related to a line of your code you have ask this question.

best regards Stefan