Counter for times the buttons have been pressed

Good afternoon,
I need help adding a counter for times the buttons have been pressed.
I can not add .
would count on showing on the display the number of times it was pressed.

Botao1 = A2; (+1)
Botao2 = A1; (+2)
Botao3 = A0; (+1)

#include <LiquidCrystal.h>

const int Botao1 = A2;
const int Botao2 = A1;
const int Botao3 = A0;
const int led1 = 11;
const int led2 = 8;
const int led3 = 10;
const int lamp1 = 3;
const int lamp2 = 2;
LiquidCrystal lcd(12, 13, 7, 6, 5, 4);

void setup()
{
pinMode(Botao1, INPUT_PULLUP); // define o pino do BotaoPin como entrada "INPUT"
pinMode(Botao2, INPUT_PULLUP);
pinMode(Botao3, INPUT_PULLUP);
pinMode(led1, OUTPUT);
pinMode(led2, OUTPUT);
pinMode(led3, OUTPUT);
pinMode(lamp1, OUTPUT);
pinMode(lamp2, OUTPUT);
lcd.begin(16, 2);

}

void loop()
{

if (digitalRead(Botao1) == LOW)
{

digitalWrite(lamp1, HIGH);
lcd.clear();
lcd.setCursor(2, 0);
lcd.print("*PRATO ALTO*");
lcd.setCursor(5, 1);
lcd.print("*PULL*");
delay(random(200, 3000));
digitalWrite(led1, HIGH);
delay(400);
digitalWrite(lamp1, LOW);
digitalWrite(led1, LOW);
delay(3000);
lcd.clear();
lcd.setCursor(2, 0);
lcd.print("*AGUARDANDO*");
lcd.setCursor(3, 1);
lcd.print("*COMANDO*");

}

if (digitalRead(Botao2) == LOW)
{

digitalWrite(lamp1, HIGH);
digitalWrite(lamp2, HIGH);
lcd.clear();
lcd.setCursor(4, 0);
lcd.print("*DOUBLE*");
lcd.setCursor(5, 1);
lcd.print("*PULL*");
delay(random(200, 3000));
digitalWrite(led2, HIGH);
delay(400);
digitalWrite(lamp1, LOW);
digitalWrite(lamp2, LOW);
digitalWrite(led2, LOW);
delay(3000);
lcd.clear();
lcd.setCursor(2, 0);
lcd.print("*AGUARDANDO*");
lcd.setCursor(3, 1);
lcd.print("*COMANDO*");

}

if (digitalRead(Botao3) == LOW)
{

digitalWrite(lamp2, HIGH);
lcd.clear();
lcd.setCursor(2, 0);
lcd.print("*PRATO BAIXO*");
lcd.setCursor(5, 1);
lcd.print("*PULL*");
delay(random(200, 3000));
digitalWrite(led3, HIGH);
delay(400);
digitalWrite(lamp2, LOW);
digitalWrite(led3, LOW);
delay(3000);
lcd.clear();
lcd.setCursor(2, 0);
lcd.print("*AGUARDANDO*");
lcd.setCursor(3, 1);
lcd.print("*COMANDO*");

}
}

The state change detection example shows how to count button switch presses. My addition to that tutorial covers state change detection using active low (wired to ground) switches.

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