I've taken out the screen section, keypad section and a few other things that I don't think have to do with what I need. (Did this so that the code would fit into the post)
// Codes
#include <UTFT.h>
#include <Keypad.h>
// TFT and Fonts
UTFT myGLCD(CTE32HR, 38, 39, 40, 41);
extern uint8_t BigFont[];
extern uint8_t Grotesk32x64[];
// Keypad
const byte ROWS = 4; // Four rows
const byte COLS = 4; // Four columns
char keys[ROWS][COLS] =
{
{'1', '2', '3', 'A'},
{'4', '5', '6', 'B'},
{'7', '8', '9', 'C'},
{'*', '0', '#', 'D'}
};
byte rowPins[ROWS] = {9, 8, 7, 6};
byte colPins[COLS] = {5, 4, 3, 2};
Keypad keypad = Keypad(makeKeymap(keys), rowPins, colPins, ROWS, COLS );
int InputNumber;
int pressedKeyCount = 0;
// Serial Number, change for each new unit
int serialNum = 4001; // 1xxx for 8 relay, 2xxx for 4 relay, 3xxx for 2 relay, 4xxx FOR 16 relay,
//Blowers
const byte Machine1 = A0; // I/O pin connected by the first relay
const byte Machine2 = A1;
const byte Machine3 = A2;
const byte Machine4 = A3;
const byte Machine5 = A4;
const byte Machine6 = A5;
const byte Machine7 = A6;
const byte Machine8 = A7;
const byte Machine9 = A8;
const byte Machine10 = A9;
const byte Machine11 = A10;
const byte Machine12 = A11;
const byte Machine13 = A12;
const byte Machine14 = A13;
const byte Machine15 = A14;
const byte Machine16 = A15;
typedef struct
{
byte Pin;
unsigned long StartedTime;
} Blower;
Blower Blowers[] = {
{ Machine1, 0 },
{ Machine2, 0 },
{ Machine3, 0 },
{ Machine4, 0 },
{ Machine5, 0 },
{ Machine6, 0 },
{ Machine7, 0 },
{ Machine8, 0 },
{ Machine9, 0 },
{ Machine10, 0 },
{ Machine11, 0 },
{ Machine12, 0 },
{ Machine13, 0 },
{ Machine14, 0 },
{ Machine15, 0 },
{ Machine16, 0 }
};
byte BlowerCount = (sizeof Blowers) / (sizeof Blowers[0]);
unsigned long BlowerStartTime;
byte CurrentBlower = 0;
int onTime = 8 ; // seconds on
int offTime = 1 ; // seconds off
unsigned long blows = 0;
unsigned long activeDays = 0;
unsigned long activeHours = 0;
unsigned long powderUsed = 0;
//Display modes
enum DisplayMode { TitleMode, SetOffTimeMode, SetOnTimeMode, ExamplesMode};
DisplayMode CurrentMode = TitleMode;
void setup()
{
for (int i = 0; i < BlowerCount; i++)
{
pinMode(Blowers[i].Pin, OUTPUT);
digitalWrite(A0,HIGH);
digitalWrite(A1,HIGH);
digitalWrite(A2,HIGH);
digitalWrite(A3,HIGH);
digitalWrite(A4,HIGH);
digitalWrite(A5,HIGH);
digitalWrite(A6,HIGH);
digitalWrite(A7,HIGH);
digitalWrite(A8,HIGH);
digitalWrite(A9,HIGH);
digitalWrite(A10,HIGH);
digitalWrite(A11,HIGH);
digitalWrite(A12,HIGH);
digitalWrite(A13,HIGH);
digitalWrite(A14,HIGH);
digitalWrite(A15,HIGH);
}
void loop() {
ManageBlowers();
int activeDs = millis() / 86400000UL;
int activeHrs = millis() / 3600000UL;
activeDays = activeDs;
activeHours = activeHrs;
int powderUse = blows * 50 / 1000;
powderUsed = powderUse;
char key = keypad.getKey();
// Serial.println(activeDs);
// Serial.println(activeHours);
// Serial.println(blows);
}
void ManageBlowers() {
if (millis() - BlowerStartTime > offTime * 1000UL)
{
StartBlower(CurrentBlower);
CurrentBlower++;
if (CurrentBlower >= BlowerCount)
CurrentBlower=0;
}
for (int i = 0; i < BlowerCount;i++)
{
if(millis()-Blowers[i].StartedTime > onTime * 1000UL)
{
StopBlower(i);
}
}
}
void StopBlower(int BlowerIndex)
{
digitalWrite(Blowers[BlowerIndex].Pin, HIGH);
}
void StartBlower(int BlowerIndex)
{
digitalWrite(Blowers[BlowerIndex].Pin, LOW);
blows ++;
BlowerStartTime=Blowers[BlowerIndex].StartedTime = millis();
myGLCD.setColor(VGA_WHITE);
myGLCD.print((char*)"LAST APPLICATOR TO BLOW", CENTER, 239);
myGLCD.setFont(Grotesk32x64);
myGLCD.setColor(VGA_RED);
myGLCD.print((char*)"'", 192, 255);
myGLCD.print((char*)"'", 256, 255);
myGLCD.printNumI(BlowerIndex + 1, CENTER, 255);
myGLCD.setFont(BigFont);
}