I just used an enum to declare values that I use elsewhere.
From the header file:
// for returns from KeyPad()
enum keyValues
{
NoKey = 0,
SetKey,
TimeKey,
PgmKey,
FanKey, // This will be an int of 4
CoolKey,
HeatKey,
UpKey,
EscapeKey,
LeftKey,
RightKey,
DownKey,
EnterKey
};
Anything done with these returned values would be in Main loop or elsewhere as needed.
I just presented this as an example of one way to get a button press only once.
In your case you would increment your counter in Main loop like:
// assume your getKey function returns counterKey - not FanKey
if( counterKey )
{
if(++counter >= 4)
{
counter = 1;
}
}
// remember this doesn't debounce as I do that in hardware.
// You will have to debounce when reading keys / buttons.
I've attached the full program below.
From the header file:
// for returns from KeyPad()
enum keyValues
{
NoKey = 0,
SetKey,
TimeKey,
PgmKey,
FanKey, // This will be an int of 4
CoolKey,
HeatKey,
UpKey,
EscapeKey,
LeftKey,
RightKey,
DownKey,
EnterKey
};
Anything done with these returned values would be in Main loop or elsewhere as needed.
I just presented this as an example of one way to get a button press only once.
In your case you would increment your counter in Main loop like:
// assume your getKey function returns counterKey - not FanKey
if( counterKey )
{
if(++counter >= 4)
{
counter = 1;
}
}
// remember this doesn't debounce as I do that in hardware.
// You will have to debounce when reading keys / buttons.
I've attached the full program below.
Attachments
-
37.3 KB Views: 4
Last edited: