I have found my main issue seems to be timers. Cut down to basics code, took out lcd commands and substitued serial so I can see whats happening.
Edited shown here code:
#include <EEPROM.h>
#include "Arduino.h"
#include <nmea.h> //include nmea library
#include <SMARTGPU.h> //include the SMARTGPU library!
char RPM[5]; //char array for display
char TENTHS[6]; //char array tenths of hour
char HOURS[6]; //char array for display
//variables
int rpm = 200;
float mph = 0.0;
int hours;
int s = 0; // time in seconds
int t; //time in tenths of hour
unsigned long TimerA = 0;
unsigned long TimerB = 0;
//pin assignments
int sensor1 = 2;
void setup() {
pinMode (sensor1, INPUT);
Serial.begin(9600);
}
void loop(){
itoa(rpm,RPM,10);
if (rpm > 1){ // enter counter here
TimerB = millis();
if (TimerB >= 1000UL){ // s will wait untill timer hits first 1000 then begins incrementing per loop
s++;}
if (millis() - TimerB >= 1000UL){ //if I take out the if statement and timer remains 0 forever
TimerB = 0;} // with this staement timer increments forever
}
if (rpm == 0){
for (int i=0; i<6; i++){
TENTHS[i] = EEPROM.read(i);} //read EEPROM data
}
if (s >= 360){
t++;
s = 0;
if (t >999) {
t = 0;}
itoa(t,TENTHS,10); //changes number, into char, base10 number
for (int i=0; i<6; i++){
if (TENTHS[i] != EEPROM.read(i)) EEPROM.write(i, TENTHS[i]);}
}
hours = t /10;
if (hours < 1){
hours = 0;}
itoa(hours,HOURS,DEC);
//lcd.string(140,100,270,120,BLACK,FONT7,TRANS,HOURS);
Serial.write (HOURS);
Serial.print ("\t");
Serial.write (RPM);
Serial.print ("\t");
Serial.print (s);
Serial.print ("\t");
Serial.print (t);
Serial.print ("\t");
Serial.print (hours);
Serial.print ("\t");
Serial.print (rpm);
Serial.print ("\t");
Serial.print (TimerB);
Serial.print ("\t");
Serial.println ("char hours, char rpm, sec, tenths, hours, rpm, timerb");
}
I want the "s" to increment each time the timer hits 1000 ms. Then I either need the timer to reset to 0 and start over or make the "s" wait until timer hits 2000ms before it incements again.