adding reset button on count - solved

Problem solved.
help was from arduino how to use if statement
https://www.arduino.cc/reference/en/language/structure/control-structure/if/

added sentence
if(digitalRead(resetbutton) == HIGH) { count = 20; lcd.begin(7, 2); lcd.print(“counter”); lcd.print(count); }

SOLVED ! :slight_smile:

hi,
i have done the code, but i need to reset counter , when the button is pressed.something like…
if(digitalRead(resetbutton) == LOW) { count = 0; }…
but as i’m beginner, i hae little stucked there …
here is my working code (yes, it has 1 disadvantage, it does not stop counting when reaches zero :smiley: )
i have did button to pin 8, so only need somewhere to write IF sentence. thought it will be easy as excel, but it’s not …
it uses infrared gate and counts down from 20. when button pressed should counter reset back .

CODE ::::

//
#include <LiquidCrystal.h>
LiquidCrystal lcd(12, 11, 5, 4, 3, 2);
int count =20;
int gate = 7;
int resetbutton = 8; // need to input somewhere in code , to reset the counter when button pressed, when low/or higt
bool item_detected = false;

void setup() {
// set up the LCD’s number of columns and rows:
lcd.begin(7, 2);
// Print a message to the LCD.
lcd.print(“counter”);
lcd.print(count);
pinMode(gate,INPUT);
}

void loop()
{
int val = digitalRead( gate );

if( (item_detected == false) && ( val == 0 )){
item_detected = true;
count–;
updateCounter();
}

else if( (item_detected == true) && ( val == 1 )){
item_detected = false;

}
}
void updateCounter(){

lcd.clear();
lcd.setCursor(0,0);
lcd.print(“Left”);
lcd.setCursor(0,1);
lcd.print(count);
}