Olá, eu estou a tentar criar um projeto que consiste num quiz com 6 perguntas. No entanto, gostava de armazenar cerca de 15 perguntas diferentes, e sempre que uma pessoa fosse começar o quiz, aparecia perguntas diferentes.
No entanto, existe um pequeno pormenor, que é, a 6 pergunta, tem que ser sempre a mesma, da 1 à 5 pergunta é que pode ser diferente, mas a 6 pergunta (a ultima no caso) tem que ser sempre a mesma questão.
Será que podem ajudar? Eu ainda sou um iniciante no arduino.
Obrigado
//-------Library-------//
#include <Wire.h> // Library for I2C communication
#include <LiquidCrystal_I2C.h> // Library for LCD
//-------Variables-------//
//const int rs = 12, en = 11, d4 = 5, d5 = 4, d6 = 3, d7 = 2;
//LiquidCrystal lcd(rs, en, d4, d5, d6, d7);
LiquidCrystal_I2C lcd = LiquidCrystal_I2C(0x27, 16, 2); // Change to (0x27,20,4) for 20x4 LCD.
const int buttonY = 11;
const int buttonN = 12;
unsigned long Tempo = millis(); // Inicia variáveis de tempo
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.init();
lcd.backlight();
}
void loop() {
acenderled();
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);
acenderled();
lcd.clear();
perguntas = -1;
}
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("Sou sociável?");
lcd.setCursor(0, 1);
lcd.print("Sim Nao"); // Print a message to the LCD.
delay(2000);
escuta_botao = 1;
escuta_botao2 = 1;
}
if (perguntas == 2) {
lcd.clear();
lcd.print("Lido bem com o stress?");
lcd.setCursor(0, 1);
lcd.print("Sim Nao"); // Print a message to the LCD.
delay(500);
acenderled();
escuta_botao = 1;
}
if (perguntas == 3) {
lcd.clear();
lcd.print("Sou descuidado?");
lcd.setCursor(0, 1);
lcd.print("Sim Nao"); // Print a message to the LCD.
delay(2000);
escuta_botao = 1;
escuta_botao2 = 1;
}
if (perguntas == 4) {
lcd.clear();
lcd.print("Tenho pouca criatividade?");
lcd.setCursor(0, 1);
lcd.print("Sim Nao"); // Print a message to the LCD.
delay(2000);
escuta_botao = 1;
}
if (perguntas == 5) {
lcd.clear();
lcd.print("Acredito em Deus?");
lcd.setCursor(0, 1);
lcd.print("Sim Nao"); // Print a message to the LCD.
delay(2000);
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(2000);
}
}
//-------------- Funções --------------//
void scrool() {
for (int positionCounter = 0; positionCounter < 40; positionCounter++) { // scroll 13 positions to the left
lcd.scrollDisplayLeft(); // scroll one position left
delay(250); // wait a bit
}
}
void acenderled(){
if((millis() - Tempo) > 6000){
digitalWrite(ledPin1, LOW);
}
if((millis() - Tempo) < 6000){
Tempo = millis();
}
}