Olá pessoal, sou novo aqui e sei pouquíssimo sobre programação e gostaria de pedir ajuda de vocês num projeto que tenho , quero montar uma mini mesa de pinball e quero usar um arduino como placar, porém não sei usar o " millis " em multitarefas .
Gostaria de pedir ajuda de alguém que entenda sobre como criar um bónus com timer, quando o pino 10 (BONUS)for ativado, deve durar 60 segundos e multiplicar por 5 os valores dos outros pinos de pontos, como segue no código e ao fim do tempo, retorne aos valores normais de a = 100 , b = 500 e c = 1000 pontos.
a = a5; b = b5; c = c*5;
Agradeço desde já , obrigado.
#include <LiquidCrystal.h>
LiquidCrystal lcd(12, 11, 5, 4, 3, 2);
bool button_0State = LOW; // the current STABLE STATE of the input pin
bool lastButton_0State = LOW; // the previous reading from the input pin
long lastDebounce_0Time = 0; // the last time the output pin was toggled
long debounceDelay = 50; // the debounce time; increase if the output flickers
boolean lastReadButton1;
boolean lastReadButton2;
boolean lastReadButton3;
boolean lastReadButton4;
unsigned int score = 0;
int ballnumber = 5;
int a = 100;
int b = 500;
int c = 1000;
// SETUP===========================================
void setup() {
//input pins for scoring triggers
pinMode(7, INPUT);
pinMode(8, INPUT);
pinMode(9, INPUT);
pinMode(10, INPUT);
// set up the LCD:
lcd.begin(16, 2);
lcd.clear();
}
//LOOP==============================================
void loop() {
//LCD TOP ROW: SCORE / GAME OVER
lcd.setCursor(0, 0);
if (ballnumber < 0)
{
lcd.print("GAME OVER ");
}
else
{
lcd.print(“SCORE: BALL:”);
lcd.print(ballnumber);
}
//LCD BOTTOM ROW: NUMERIC SCORE
lcd.setCursor(0, 1);
lcd.print(score);
//BONUS faltando millis//////////////////////////////////////
boolean readButton4 = digitalRead( 10 ) ;
if (readButton4 == LOW and lastReadButton4 == HIGH)
{
a = a5; b = b5; c = c*5;
}
lastReadButton4 = readButton4;
//Placar de 100 PTS //////////////////////////////////////
boolean readButton1 = digitalRead ( 8 ) ;
if (readButton1 == LOW and lastReadButton1 == HIGH)
{
score = score + a;
}
lastReadButton1 = readButton1;
//Placar de 500 PTS //////////////////////////////////////
boolean readButton2 = digitalRead ( 9 ) ;
if (readButton2 == LOW and lastReadButton2 == HIGH)
{
score = score + b;
}
lastReadButton2 = readButton2;
///Bola perdida///GAME OVER///////////////////////////////////
bool reading = digitalRead( 7 );
if (reading != lastButton_0State) {
lastDebounce_0Time = millis(); // reset the time since last stable state
lastButton_0State = reading;
}
if ((millis() - lastDebounce_0Time) > debounceDelay) {
// test for a transition from low-high or high-low
if (button_0State != lastButton_0State) {
button_0State = lastButton_0State;
if (button_0State == HIGH) {
ballnumber = ballnumber - 1;
}
}
}
}