Ajuda com millis e multitarefas



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 tempo, retorne aos valores normais de = 100 , b = 500 e c = 1000 pontos.

a = a*5; b = b*5; c = c*5;

agradeço desde já , obrigado.


#include <liquidcrystal.h>
liquidcrystal lcd(12, 11, 5, 4, 3, 2);

bool button_0state = low; // current stable state of input pin
bool lastbutton_0state = low; // previous reading input pin
long lastdebounce_0time = 0; // last time output pin toggled

long debouncedelay = 50; // debounce time; increase if output flickers

boolean lastreadbutton1;
boolean lastreadbutton2;
boolean lastreadbutton3;
boolean lastreadbutton4;

unsigned int score = 0;
int ballnumber = 5;
int = 100;
int b = 500;
int c = 1000;


// setup===========================================
void setup() {

//input pins scoring triggers
pinmode(7, input);
pinmode(8, input);
pinmode(9, input);
pinmode(10, input);

// set lcd:
lcd.begin(16, 2);
lcd.clear();
}

//loop==============================================
void loop() {
//lcd top row: score / game on
lcd.setcursor(0, 0);

if (ballnumber < 0)
{
lcd.print("game on ");
}
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 , lastreadbutton4 == high)
{
a = a*5; b = b*5; c = c*5;
}
lastreadbutton4 = readbutton4;

 //placar de 100 pts //////////////////////////////////////
boolean readbutton1 = digitalread ( 8 ) ;

if (readbutton1 == low , lastreadbutton1 == high)
{
score = score + a;
}
lastreadbutton1 = readbutton1;

//placar de 500 pts //////////////////////////////////////
boolean readbutton2 = digitalread ( 9 ) ;

if (readbutton2 == low , lastreadbutton2 == high)
{
score = score + b;
}
lastreadbutton2 = readbutton2;

///bola perdida///game over///////////////////////////////////
bool reading = digitalread( 7 );

if (reading != lastbutton_0state) {
lastdebounce_0time = millis(); // reset time since last stable state
lastbutton_0state = reading;
}

if ((millis() - lastdebounce_0time) > debouncedelay) {
// test transition low-high or high-low
if (button_0state != lastbutton_0state) {
button_0state = lastbutton_0state;

if (button_0state == high) {
ballnumber = ballnumber - 1;
}
}
}
}

code: [select]

unsigned long bonustime = 0; //isto fica fora da função loop().
unsigned char bonuson = 0;    //isto também fica fora da função loop()

if (readbutton4 == low , lastreadbutton4 == high)
{
bonuson = 1;
a = a*5; b = b*5; c = c*5;
bonustime = millis();
}
lastreadbutton4 = readbutton4;


if (bonuson == 1 && (millis() - bonustime >= 60000) ) {
   bonuson = 0;
   a = 100;
   b = 500;
   c = 1000;

   



Arduino Forum > International > Portugues > Ajuda com millis e multitarefas


arduino

Comments

Popular posts from this blog

Flip address is out of range arduino uno r3

Arduino Uno not uploading

Indesign and MathType fonts