Buenas a todos.
Estoy haciendo un cronometro regresivo sobre arduino UNO y una pantalla tft ILI9341.
El caso es que estoy comenzando en todo esto de programar con arduino y me encuentro totalmente atascado.
He realizado mil busquedas en foros, google, youtube....... pero no consigo hacerlo funcionar como deseo.
Al tema; necesito que mi cuenta atras finalice en "0" desde un tiempo ya prefijado y unico (59min59seg) y que luego cuando presione el pulsador, el loop() se reinicie desde el principio.
Mi código:
#include <gfxfont.h>
#include "Fonts/FreeSans9pt7b.h"
#include <TFT_ILI9341.h>
#include <max6675.h>
#include "SPI.h"
#include "Adafruit_GFX.h"
#include "Adafruit_ILI9341.h"
#include <SPI.h>
#define PULSADOR 3
#define TFT_DC 9
#define TFT_CS 10
Adafruit_ILI9341 tft = Adafruit_ILI9341(TFT_CS, TFT_DC);
int S = 59; // cuenta segundos
int M = 59; // cuenta minutos
int H = 00; // cuenta horas
void setup() {
pinMode(PULSADOR, INPUT_PULLUP);
tft.fillScreen (ILI9341_BLACK);
tft.setTextColor (ILI9341_WHITE, ILI9341_BLACK); //punteros cronometro
tft.setFont ();
tft.setTextSize (4);
tft.setCursor(93, 180);
tft.print (":");
tft.setCursor(203, 180);
tft.print (":");
}
void loop(void) {
//////cronometro//////
if(digitalRead(PULSADOR)==HIGH);{
S--;
tft.setTextColor (ILI9341_WHITE, ILI9341_BLACK);
tft.setTextSize (7);
if(S<0)
{
M--;
S=59;
}
if(M<0)
{
H--;
M=59;
}
if(H<0) { H=00; M=00; S=00;
tft.print("FIN");}
if(M>9)
{
tft.setCursor(120,170);
tft.print(M);
}
else
{
tft.setCursor(120,170);
tft.print("0");
tft.setCursor(160,170);
tft.print(M);
}
if(S>9)
{
tft.setCursor(230,170);
tft.print(S);
}
else
{
tft.setCursor(230,170);
tft.print("0");
tft.setCursor(270,170);
tft.print(S);
}
if(H>9)
{
tft.setCursor(10,170);
tft.print (H);
}
else
{
tft.setCursor(10,170);
tft.print("0");
tft.setCursor(50,170);
tft.print(H);
}
}
return loop();
}
Alguna sugerencia de como poder hacer lo que me propongo?
Gracias a todos