Can someone help me with this? I need it for school and I have no idea how to fix it.

So we built a counter in school with a lcd attached to it.
When i press a button the counter goes up by 1 how its supposed to be.
The problem is that when I keep the button pressed, the counter will go up the whole time.Tekst sformatowany
In conclusion, does someone know how to fix this?, it should only go up by 1 no matter how long i will keep the button pressed.

Heres the script:

#include <LiquidCrystal.h>

int button=8;

int val;

int count=0;

int press;

LiquidCrystal lcd(12, 11, 5, 4, 3, 2);

void setup() {

lcd.begin(16, 2);

pinMode(8,INPUT);

}

void loop() {

val=digitalRead(button);

if(val==HIGH){

press=count++;

delay(250);

}

lcd.setCursor(0, 0);

lcd.print("Counter");

lcd.setCursor(0, 1);

lcd.print(press);

}

How does your task/problem/solution/code compare to this "change detection" example?

1 Like

I did some tweaking with your help and it works now, thanks a lot!

You're welcome. Please post your code in code tags, edit your question to be useful, and mark the question solved.

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