Using one button for two different things?

Hello and thanks for reading this!
I am working on a drink maker and I am trying to make a gui with an lcd and rotary encoder to select how much liquid you want and I need to code with 2 of these one for one liquid and one for another but I want to use one button to send the amount of liquid you want on both off them to the arduino but I don’t know how to do this with one button here is the code:

#include <LiquidCrystal_I2C.h>
LiquidCrystal_I2C lcd (0x27, 16, 2);
const int clk = 2;
const int dt = 3;
int counter = 0;
int currentStateclk;
int lastStateclk;
int pumpTime = 0;
const int pump = 7;
const int button = 6;
int buttonstate = 0;
const int led = 5;
const int mixer = 4;
int eight = 8;
void setup()
{
  pinMode(clk, INPUT);
  pinMode(dt, INPUT);
  pinMode(led, OUTPUT);
  pinMode(button, INPUT);
  pinMode(8, INPUT);
  lcd.init();
  lastStateclk = digitalRead(clk);
}
void loop()
{
  eight = digitalRead(8);
  pumpTime = counter / 10;
  buttonstate = digitalRead(button);
  if (eight == HIGH)
  {
    currentStateclk = digitalRead(clk);
    if (currentStateclk != lastStateclk  && currentStateclk == 1)
    {
      if (digitalRead(dt) != currentStateclk);
      {
        counter --;
        counter = counter - 4;
        if (counter < 0)
          counter = 0;
      }
    }
    else
    {
      counter ++;
      counter = counter + 4;
      if (counter > 1000)
        counter = 1000;
    }
  }
  lcd.setCursor(1, 0);
  lcd.backlight();
  lcd.print("How much do you want?");
  lcd.setCursor(2, 1);
  lcd.print(counter);
  if (buttonstate == HIGH && pump == LOW)
  {
    digitalWrite(pump, HIGH);
    delay(pumpTime);
    digitalWrite(pump, LOW);
    delay(5000);
    lcd.clear();
    lcd.setCursor(1, 0);
  }
  lcd.print("How much do you want?");
  lcd.print(counter);
  delay(2000);
  //code needed here
}

Please post your code rather than attaching it as it makes it easier to copy it to an editor for examination

Please follow the advice on posting code given in Read this before posting a programming question

In particular note the advice to Auto format code in the IDE and to use code tags when posting code here as it prevents some combinations of characters in code being interpreted as HTML commands such as italics, bold or a smiley character, all of which render the code useless

It said it was more than 9000 characters

It said it was more than 9000 characters

Not when I did it. You must have done something wrong

#include <LiquidCrystal_I2C.h>
LiquidCrystal_I2C lcd (0x27, 16, 2);
const int clk = 2;
const int dt = 3;
int counter = 0;
int currentStateclk;
int lastStateclk;
int pumpTime = 0;
const int pump = 7;
const int button = 6;
int buttonstate = 0;
const int led = 5;
const int mixer = 4;
int eight = 8;
void setup()
{
  pinMode(clk, INPUT);
  pinMode(dt, INPUT);
  pinMode(led, OUTPUT);
  pinMode(button, INPUT);
  pinMode(8, INPUT);
  lcd.init();
  lastStateclk = digitalRead(clk);
}
void loop()
{
  eight = digitalRead(8);
  pumpTime = counter / 10;
  buttonstate = digitalRead(button);
  if (eight == HIGH)
  {
    currentStateclk = digitalRead(clk);
    if (currentStateclk != lastStateclk  && currentStateclk == 1)
    {
      if (digitalRead(dt) != currentStateclk);
      {
        counter --;
        counter = counter - 4;
        if (counter < 0)
          counter = 0;
      }
    }
    else
    {
      counter ++;
      counter = counter + 4;
      if (counter > 1000)
        counter = 1000;
    }
  }
  lcd.setCursor(1, 0);
  lcd.backlight();
  lcd.print("How much do you want?");
  lcd.setCursor(2, 1);
  lcd.print(counter);
  if (buttonstate == HIGH && pump == LOW)
  {
    digitalWrite(pump, HIGH);
    delay(pumpTime);
    digitalWrite(pump, LOW);
    delay(5000);
    lcd.clear();
    lcd.setCursor(1, 0);
  }
  lcd.print("How much do you want?");
  lcd.print(counter);
  delay(2000);
  //code needed here
}

Well I did copy it from vs code and the text was colored and the background was black so maybe that was the problem?

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