Very new to arduino and programming in general.
brief explanation of my project - i have been restoring old espresso machine for some time and recent wanted to incorporate some basic smarts into an old manual machine.
The machine has two group heads, (water outlets), flick a switch on and the water comes out, flick the switch off and the water turns off. The amount of water out is basically a ratio of how much coffee you start with and extracting that amount of water over an acceptable amount of time.
ie 20grams of coffee at a ratio of 3:1 = 60ml of water.
My hardware setup is as follows
ESP32Node32s
2x momentary buttons
1x 2 channel relay
desired outcome -
push button - relay activate for 25sec then turns off
at anytime i can interrupt by pressing the button again.
I have been able to code with success pushing either button to turn on or off the relays but can't work out how to add the run time. I have been researching and following tutorials and watching youtube and have been unsuccessful in getting any working result. When finding something remotely close and asking the creator for assistance im general met with "research millis and add that to you code"... im now having dreams about millis i have read so much and watched tutorials for the past 2 weeks and still can't seem to work it out...
the link is to the code that has no millis yet added. this is a sketch i have modified from an online tutorial which im happy with todate.
I'd really appreciate some help with one
/*
*
*/
const int pushButton[] ={22,23};// button inputs
const int relayPin[]={26,27};// output pins relays
String relayNames[] ={"CH1", "CH2"};// name for relays
int pushed[] ={0,0};// status of each buttons
int relayStatus[] ={HIGH,HIGH};// initial status of relay
void setup() {
Serial.begin(9600);// initialize serial monitor
for(int i=0; i<2; i++)
{
pinMode(pushButton[i], INPUT_PULLUP);
pinMode(relayPin[i], OUTPUT);
digitalWrite(relayPin[i], HIGH);// initial relay status to be OFF
}
}
void loop() {
for(int i=0; i<2; i++)
{
int val = digitalRead(pushButton[i]);
if(val == HIGH && relayStatus[i] == LOW){
pushed[i] = 1-pushed[i];
delay(50);
}// if
relayStatus[i] = val;
if(pushed[i] == HIGH){
Serial.print(relayNames[i]);
Serial.println(" ON");
digitalWrite(relayPin[i], LOW);
}else{
Serial.print(relayNames[i]);
Serial.println(" OFF");
digitalWrite(relayPin[i], HIGH);
}// else
}// for
Serial.println("==");
delay(50);
}// loop end