I'm trying to display a timer which counts up to 70seconds however once it reaches 65, it restarts (loop). This happened after I added ' basetime=millis(); ' and ' currtime = millis()-basetime; ' . (It works when I remove those two but I added because I want the millis() to be reset to zero once it hits 70seconds). Anybody able to help me on this? I am using arduino Mega 2560
#include <SPI.h>
#include "Adafruit_GFX.h"
#include "Adafruit_RA8875.h"
#include "max6675.h"
// Library only supports hardware SPI at this time
// Connect SCLK to MEGA Digital #52 (Hardware SPI clock)
// Connect MISO to MEGA Digital #50 (Hardware SPI MISO)
// Connect MOSI to MEGA Digital #51 (Hardware SPI MOSI)
#define RA8875_INT 255//Not used #3
#define RA8875_CS 53
#define RA8875_RESET 255//Not used #13
int ktcSO = 48;
int ktcCS = 47;
int ktcCLK = 46;
MAX6675 ktc(ktcCLK, ktcCS, ktcSO);
int t;
Adafruit_RA8875 tft = Adafruit_RA8875(RA8875_CS, RA8875_RESET);
uint16_t tx, ty, t2x,t2y;
uint8_t minutes, seconds ,seconds2, hours, basetime, currtime;
char timeline[30];
void setup()
{
Serial.begin(9600);
Serial.println("------------------------------------------------");
Serial.println("RA8875 start");
/* Initialise the display using 'RA8875_480x272' or 'RA8875_800x480' */
if (!tft.begin(RA8875_800x480)) {
Serial.println("RA8875 Not Found!");
while (1);
}
Serial.println("Found RA8875");
tft.displayOn(true);
tft.GPIOX(true); // Enable TFT - display enable tied to GPIOX
tft.PWM1config(true, RA8875_PWM_CLK_DIV1024); // PWM output for backlight
tft.PWM1out(255);
// With hardware accelleration this is instant
tft.fillScreen(RA8875_WHITE);
tft.textMode();
//tft.cursorBlink(32);
tft.touchEnable(true);
pinMode(8, OUTPUT);
}
void loop()
{
basetime=millis();
seconds=0;
seconds2=0;
minutes=0;
tft.drawRect(0, 60, 400, 420, RA8875_GREEN);
//tft.fillRect(0, 0, 400, 240, RA8875_GREEN);
tft.drawRect(400, 60, 400, 420, RA8875_BLUE);
//tft.fillRect(400, 0, 400, 420, RA8875_BLUE);
tft.textSetCursor(400,10);
tft.textTransparent(RA8875_BLACK);
tft.textEnlarge(1);
tft.print("FAN");
tft.textSetCursor(200,240);
tft.print("ON");
tft.textSetCursor(600,240);
tft.print("OFF");
if (tft.touched())
{
tft.touchRead(&t2x, &t2y);
Serial.print(t2x); Serial.print(", "); Serial.println(t2y);
if((t2y>=50 && t2y<=1000 )&&(t2x>=0 && t2x <= 490))
{
tft.fillScreen(RA8875_WHITE);
for( seconds==0; seconds<=70; seconds++)
{
digitalWrite(8, HIGH);
time();
}
digitalWrite(8, LOW);
tft.touchRead(&tx, &ty);
tft.fillScreen(RA8875_WHITE);
}
else if ((t2y>=50 && t2y<=1000 )&&(t2x>=500 && t2x <= 1000))
{
tft.fillScreen(RA8875_WHITE);
for( seconds==0; seconds<=70 ;seconds++)
{
time();
}
tft.touchRead(&tx, &ty);
tft.fillScreen(RA8875_WHITE);
}
}
}
void time()
{
currtime = millis()-basetime;
tft.textSetCursor(100, 100);
tft.textColor(RA8875_WHITE, RA8875_RED);
sprintf(timeline,"%02d hours %02d mins %02d secs",hours, minutes, seconds2);
tft.print(timeline);
delay(1000);
tft.textSetCursor(200, 300);
tft.textColor(RA8875_WHITE, RA8875_RED);
tft.print("Deg C = ");
tft.print(ktc.readCelsius());
delay(1000);
seconds = currtime /1000;
minutes = (currtime/1000 ) / 60;
seconds2 = seconds - (minutes * 60);
//minutes = minutes - (hours * 60);
//hours = ( ( millis()/1000 ) / 60 ) / 60;
}