Hi everyone,
I have a code which I wrote with help from some nice people on the forum a few years ago. It has been working fine up until now, but I urgently need some help with adding something to it.
The code is used to control up to 24 relays in a infinite loop with a Mega 2560, where I can adjust the time between every relay, and how long the relay stays on for. The relays control blower motors.
I have it so that I can enter seconds for the delay between each relay, as well as seconds for each relay to be on.
What I need now is help with a decimal point for the delay between each relay. How will I do this?
I've been looking around and read about floating numbers, and various other options, but I'm not sure which one will work for my application. I would like two decimal points and was wondering how can I get the display to show 000.00 and when I enter the number on the keypad it comes in from right to left and replaces the 0s.
The hardware that I have is a Mega, 3.2' screen, relays and a 4x4 keypad.
The code that I'm working with at the moment includes the following for the keypad.
Code: [Select]
// 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 );
unsigned int InputNumber;
int pressedKeyCount = 0;
Code: [Select]
char key = keypad.getKey();
void IncreaseNewTime(char key)
{
if (CurrentMode == SetOffTimeMode || CurrentMode == SetOnTimeMode)
{
InputNumber = InputNumber * 10 + key - '0';
pressedKeyCount ++;
myGLCD.setColor(VGA_RED);
myGLCD.printNumI(InputNumber, CENTER, 84);
if (pressedKeyCount > 5)
InputNumber = 0,
pressedKeyCount = 0,
tooManyNumbers();
}
}
void SaveNewTime()
{
if (CurrentMode == SetOffTimeMode)
{
offTime = InputNumber;
offTimeSaved();
}
if (CurrentMode == SetOnTimeMode)
{
onTime = InputNumber;
onTimeSaved();
}
}
void keypadEvent (KeypadEvent key)
{
if (keypad.getState() == PRESSED)
{
switch (key)
{
case 'A':
CurrentMode = TitleMode;
title();
InputNumber = 0;
break;
case 'B':
CurrentMode = SetOffTimeMode;
offTimeChange();
InputNumber = 0;
break;
case 'C':
CurrentMode = SetOnTimeMode;
onTimeChange();
InputNumber = 0;
break;
case 'D':
examplesPage();
break;
case '0' ... '9':
IncreaseNewTime(key);
break;
case '*':
if (InputNumber > 0)
{
InputNumber = 0;
reset();
}
break;
case '#':
if (InputNumber > 0)
{
SaveNewTime();
InputNumber = 0;
}
break;
}
}
}
I hope someone can give me some advise.
Thanks a lot