Hello, i am having troubles in my code. I want to return to the question 1, when the player finish all the questions (6 on total).
I have two buttons, in both I want to return to the question 1. On ButtonY the LED turn's on, and the ButtonN just a message, and then returns to question 1
Thanks
//-------Library-------//
#include <LiquidCrystal.h>
//-------Variables-------//
const int rs = 12, en = 11, d4 = 5, d5 = 4, d6 = 3, d7 = 2;
LiquidCrystal lcd(rs, en, d4, d5, d6, d7);
const int buttonY = 7;
const int buttonN = 6;
unsigned long Time;
const int ledPin1 = 13;
const int ledPin2 = 10;
const int ledPin3 = 9;
const int ledPin4 = 8;
int buttonStateY = 0;
int buttonStateN = 0;
int perguntas = 0;
bool escuta_botao = 0;
bool escuta_botao2 = 0;
bool firstpress = 0;
//-------Code-------//
void setup() {
pinMode(ledPin1, OUTPUT);
pinMode(ledPin2, OUTPUT);
pinMode(ledPin3, OUTPUT);
pinMode(ledPin4, OUTPUT);
pinMode(buttonY, INPUT_PULLUP);
pinMode(buttonN, INPUT_PULLUP);
Serial.begin(9600);
lcd.begin(16, 2); // set up the LCD's number of columns and rows
}
void loop() {
if (escuta_botao == 1) {
buttonStateY = digitalRead(buttonY); // check if the pushbutton is pressed.
// ButtonY
if (buttonStateY == LOW && firstpress == 0) {
if(perguntas == 6) {
digitalWrite(ledPin1, HIGH);
lcd.clear();
}
firstpress = 1;
perguntas++; // preguntasrand=rand(1,15);
}
if (buttonStateY == HIGH && firstpress == 1) {
firstpress = 0;
escuta_botao = 0;
}
}
if (escuta_botao2 == 1) {
buttonStateN = digitalRead(buttonN); // check if the pushbutton is pressed.
// ButtonN
if (buttonStateN == LOW && firstpress == 0) {
if(perguntas == 6) {
lcd.print("Não aceitou os termos "); // Print a message to the LCD.
delay(500);
Serial.println(perguntas);
}
firstpress = 1;
perguntas++; // preguntasrand=rand(1,15);
}
if (buttonStateN == HIGH && firstpress == 1) {
firstpress = 0;
escuta_botao2 = 0;
}
Serial.println(perguntas);
}
if (perguntas == 0) {
lcd.clear();
lcd.setCursor(3, 0);
lcd.print("Bem-Vindo!"); // Print a message to the LCD.
lcd.setCursor(0, 1);
lcd.print("Clique para iniciar"); // Print a message to the LCD.
delay(2000);
//scrool();
escuta_botao = 1;
escuta_botao2 = 1;
}
if (perguntas == 1) {
lcd.clear();
lcd.print("Pergunta 1");
lcd.setCursor(0, 1);
lcd.print("Sim Nao"); // Print a message to the LCD.
delay(500);
escuta_botao = 1;
escuta_botao2 = 1;
}
if (perguntas == 2) {
lcd.clear();
lcd.print("Pergunta 2");
lcd.setCursor(0, 1);
lcd.print("Sim Nao"); // Print a message to the LCD.
delay(500);
escuta_botao = 1;
}
if (perguntas == 3) {
lcd.clear();
lcd.print("Pergunta 3");
lcd.setCursor(0, 1);
lcd.print("Sim Nao"); // Print a message to the LCD.
delay(500);
escuta_botao = 1;
escuta_botao2 = 1;
}
if (perguntas == 4) {
lcd.clear();
lcd.print("Pergunta 4");
lcd.setCursor(0, 1);
lcd.print("Sim Nao"); // Print a message to the LCD.
delay(500);
escuta_botao = 1;
}
if (perguntas == 5) {
lcd.clear();
lcd.print("Pergunta 5");
lcd.setCursor(0, 1);
lcd.print("Sim Nao"); // Print a message to the LCD.
delay(500);
escuta_botao = 1;
escuta_botao2 = 1;
}
if (perguntas == 6) {
lcd.clear();
lcd.print("Aceite os termos para acender a vela");
lcd.setCursor(0, 1);
lcd.print("Sim Nao"); // Print a message to the LCD.
delay(500);
}
}