Drink dispenser project

Hey, i have been working on a drink dispenser project for some days now and think i need some help with my code. Currently i have found and edited a code for the projects with 2 water pumps to run for a certain amount, of time which works fine. But i want to implement a wash program for each pump. What i am thinking is that the 2 buttons has two functions each, for example if i press the switch once the pump will start pouring the drink for a certain amount of time, and if i press the same button the wash program will start (only powering the pump on for about 50 seconds to pump water through to wash). Here is the current code.

#include <ezButton.h> // include ezButton library
#include <ezOutput.h> // include ezOutput library

ezOutput pump(2);    // create ezOutput object attached to pin 2
ezButton button(A5); // create ezButton object attached to pin A5

void setup() {
  button.setDebounceTime(50); // set debounce time to 50 milliseconds
  pump.low(); // turn pump off

void loop() {
  pump.loop();   // MUST call the loop() function first
  button.loop(); // MUST call the loop() function first

  if (button.isPressed()) {
    Serial.println("Pump is started");
    pump.pulse(10000); // turn on for 10000 milliseconds ~ 10 seconds
    // after 10 seconds, pump will be turned off by pump.loop() function

If anyone has the time to help me out it is very much appreciated :slight_smile:

think you need a state machine for each button, e.g. three states

algorith something like

if button press 
  if state == NO PRESS
     state = FIRST PRESS
     start pouring drink
    if state == FIRST PRESS
       state = SECOND PRESS
       start washing

when pouring drink or washing complete state returns to NO PRESS

possible modification after the first press you wait a second - if nothing happens then pour drink if you get a second press (within the second) start washing

If all you want is two functions per button a library with a long press feature may work. There's probably one in the IDE library manager you could use.

How the pump physically change from pumping a drink to pumping water?

I see i will try this soon thank you for ur help! This goes inside the void setup?

I physically change the tube from the drink to a water source, the reason why i want it able to have two states is so its more water than the amount of a shot being pumped

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