#include <LiquidCrystal_I2C.h>
LiquidCrystal_I2C lcd(0x27, 16, 2);
#include <Keypad.h>
const byte ROWS = 4;
const byte COLS = 4;
char hexaKeys[ROWS][COLS] = {
{'1', '2', '3', 'A'},
{'4', '5', '6', 'B'},
{'7', '8', '9', 'C'},
{'*', '0', '#', 'D'}
};
byte rowPins[ROWS] = {A15, A14, A13, A12};
byte colPins[COLS] = {A11, A10, A9, A8};
Keypad customKeypad = Keypad(makeKeymap(hexaKeys), rowPins, colPins, ROWS, COLS);
#include <TM1637Display.h>
#define CLK 3
#define DIO 2
TM1637Display display = TM1637Display (CLK, DIO);
int count;
const byte button = 22; // Push Button Pin D 2
const byte led = 4;
int status = false;
void setup()
{
lcd.init();
lcd.backlight();
display.setBrightness(4); // activate display
Serial.begin(9600);
pinMode(led, OUTPUT);
digitalWrite(led, LOW);
pinMode(button, INPUT_PULLUP);
}
void loop()
{
if (digitalRead(button) == true)
{
status = !status;
digitalWrite(led, !status);
}
while(digitalRead(button) == true);
delay(50);
char customKey = customKeypad.getKey();
if (customKey)
{
Serial.println(customKey);
lcd.setCursor(1, 1);
lcd.print(customKey);
count = customKey - '0';
display.showNumberDec(count);
}
}
With Arduino MEGA and above code I am trying to make a function like :
A push button (pin 22) acts as a toggle switch
An LED is present as indicator to show toggle action
Now this toggle switch system is added for the purpose to
activate the keypad keys to work as per it's code and
to deactivate the working of keypad completely
One of the toggle mode will activate and other will deactivate
I tried with code posted above, but it is working with a
"key press and hold" thing.
It has no relation with the toggle action added
If we use to press and hold the push button continuously
then the keypad use to get work and on release of the push button.
keypad function gets deactivate and no key gets print on LCD!!!!!
Please help !!!