Olá galera, sou iniciante ainda e não estou conseguindo aplicar o debounce em um programa que estou desenvolvendo, gostaria que me ajudassem, segue abaixo o código:
#include "LiquidCrystal.h" // biblioteca LCD
LiquidCrystal lcd(12, 11, 5, 4, 3, 2); // Pinos utilizados
const int b1 = 8; // pinos dos botões
const int b2 = 9; // pinos dos botões
const int b3 = 10; // pinos dos botões
int button1 = 0; // Variável para leitura
int button2 = 0; // Variável para leitura
int button3 = 0; // Variável para leitura
int x = 0; // Muda as tabelas
int y = 0; // SOMA
void setup() {
pinMode(b1, INPUT_PULLUP); // botão 1 entrada
pinMode(b2, INPUT_PULLUP); // botão 2 entrada
pinMode (b3, INPUT_PULLUP); // botão 3 entrada
digitalWrite (b1, HIGH); // ativa resistores de pull up
digitalWrite (b2, HIGH); // ativa resistores de pull up
digitalWrite (b3, HIGH); // ativa resistores de pull up
lcd.begin(16, 2); // Inicializa LCD
}
void loop(){
if ( x == 0){
lcd.setCursor(0,0);
lcd.print ("1 3 5 7 9 11 13 15 15 17 19 21 23 25 27 29 31 "); // 1º tabela
}
if ( x == 1) {
lcd.setCursor(0,0);
lcd.print("2 3 6 7 10 11 14 15 18 19 22 23 26 27 30 31 "); // 2º tabela
}
if ( x == 2) {
lcd.setCursor(0,0);
lcd.print ("4 5 6 7 12 13 14 15 20 21 22 23 28 29 30 31 "); // 3º tabela
}
if ( x == 3) {
lcd.setCursor(0,0);
lcd.print ("8 9 10 11 12 13 14 15 24 25 26 27 28 29 30 31 "); // 4º tabela
}
if (x == 4) {
lcd.setCursor(0,0);
lcd.print("16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 "); // 5º tabela
}
button1 = digitalRead(b1); // leitura do estado dos botões
button2 = digitalRead(b2); // leitura do estado dos botões
button3 = digitalRead(b3); // leitura do estado dos botões
if (( button1 == LOW)|| (button2 == LOW)) {
x++ ; // Muda as tabelas
}
if ((button1 == LOW)&&(x==1)){
y = 0 + 1;
} // Soma 1
if ((button1 == LOW)&&(x==2)){
y = y + 2;
} // Soma 2
if ((button1 == LOW)&&(x==3)){
y = y + 4;
} // Soma 4
if ((button1 == LOW)&&(x==4)){
y = y + 8; // Soma 8
}
if ((button1 == LOW)&&(x==5)){
y = y + 16;
} // Soma 16
if (x == 5 ) {
lcd. clear ();
lcd.setCursor(0,0);
lcd. print ( y ); // Mostra Soma
lcd. print (" Soma");
}
}
Tags:
Bem-vindo a
Laboratorio de Garagem (arduino, eletrônica, robotica, hacking)
© 2024 Criado por Marcelo Rodrigues. Ativado por