I've dabbled but I'm not a "programmer" so be gentle.
This is debug code to see if I can get the loop working (which it apparently isn't). In the normal code, the compare values in the while statements will change but for this exercise I kept them constant to make this easier.
The loop executes fine the first time (ON time of 1500 and OFF for 500) but then nothing happens for a while then it will run again. The time between loops is not consistent. I've seen the delay as much as 2 minutes and as short as 12 seconds.
The commented code is various things I've tried.
Can anyone help?
#include <UTFT.h>
#include <URTouch.h>
#include <URTouchCD.h>
#include <EEPROM.h>
#define TOUCH_ORIENTATION PORTRAIT
// Initialize display
UTFT myGLCD(CTE32_R2, 38, 39, 40, 41);
// Initialize touchscreen
URTouch myTouch( 6, 5, 4, 3, 2);
extern uint8_t Retro8x16[];
int M_ON, M_OFF, S_ON, S_OFF, VS_ON, VS_OFF;
int activ_Pdr;
int ep_start_M = 4000;
int ep_start_P = 0;
int ea, ev, Spd, ON, OFF;
unsigned long Start_Time, ex, ex1;
unsigned long Cur_Time, F_ON, F_OFF;
unsigned long period, period_H, period_L;
void setup() {
myGLCD.InitLCD(0); // Portrait
myGLCD.clrScr();
pinMode(13, OUTPUT); // onboard LED
myTouch.InitTouch(TOUCH_ORIENTATION);
myTouch.setPrecision(PREC_MEDIUM);
myGLCD.setFont(Retro8x16);
activ_Pdr = 1;
// activ_Pdr = EEPROM.read(ep_start_P + 45);
ea = (ep_start_M - 100) + ((activ_Pdr - 1) * 24);
F_ON = EEPROM.read(ea) + (EEPROM.read(ea+1) * 256);
F_OFF = EEPROM.read(ea+2) + (EEPROM.read(ea+3) * 256);
myGLCD.setBackColor(0, 0, 0);
myGLCD.setColor(255, 255, 255);
//myGLCD.printNumI(F_ON, 25, 75, 4);
//myGLCD.printNumI(F_OFF, 25, 105, 4);
//ex= millis();
//delay (1500);
//ex1= millis();
//period=ex1-ex;
//myGLCD.printNumI(ex, 40, 140, 6);
//myGLCD.printNumI(ex1, 40, 180, 6);
//myGLCD.printNumI(period, 40, 220, 6);
}
void loop() {
//period = 0;
// Start_Time = millis();
while (myTouch.dataAvailable() == 0) // want to be able to stop by touching the screen
{
Start_Time = millis();
period_H = 0;
digitalWrite(13, HIGH);
while (period_H < F_ON){
Cur_Time = millis();
period_H = Cur_Time - Start_Time;
myGLCD.printNumI(period_H, 40, 260, 6);
}
Start_Time = millis();
period_L = 0;
digitalWrite(13, LOW);
while (period_L < F_OFF){
Cur_Time = millis();
period_L = Cur_Time - Start_Time;
myGLCD.printNumI(period_L, 100, 260, 6);
}
}
//return;
}