Hi, i need some help taking the typed number from my 4x4 keypad and using them to send message, i need help, i know the my codes are quite dumb cause i'm still learning, i'm trying to make a phone using GSM/GPRS shield, 4x4 keypad, and lcd, here's my code
#include <LiquidCrystal.h>
#include <Wire.h>
#include <Keypad.h>
const byte rows = 4;
const byte cols = 4;
const int buttonPin = A0;
char keys[rows][cols] = {
{'1', '2', '3', 'A'},
{'4', '5', '6', 'B'},
{'7', '8', '9', 'C'},
{'*', '0', '#', 'D'}
};
byte rowPins[rows] = {13, 12, 11, 10};
byte colPins[cols] = {9, 8, 7, 6};
Keypad keypad = Keypad(makeKeymap(keys), rowPins, colPins, rows, cols);
LiquidCrystal lcd(5, 4, 3, 2, 1, 0);
int buttonPushCounter = 0;
int buttonState = 0;
int lastButtonState = 0;
void initLCDKeys()
{
for (int i = 0; i < sizeof(rowPins); i++)
pinMode(rowPins[i], OUTPUT);
for (int i = 0; i < sizeof(colPins); i++)
{
pinMode(colPins[i], INPUT);
digitalWrite(colPins[i], LOW);
}
}
void setup() {
char key = keypad.getKey();
lcd.clear();
delay(50);
lcd.begin(16, 2);
lcd.print("enter no.:");
lcd.setCursor(0, 1);
lcd.print("no. of pushes:");
pinMode(buttonPin, INPUT);
}
void loop() {
buttonState = digitalRead(buttonPin);
char key = keypad.getKey();
if (buttonState != lastButtonState)
{
if (buttonState == HIGH) {
buttonPushCounter++;
lcd.begin(16, 2);
lcd.print("enter no.:");
lcd.print(key);
lcd.setCursor(0, 1);
lcd.print("no. of pushes:");
lcd.println(buttonPushCounter);
}
delay(50);
}
lastButtonState = buttonState;
buttonState = digitalRead(buttonPin);
if (int(key) != 0)
{
lcd.begin(16, 2);
lcd.print("enter no.:");
lcd.print(key);
lcd.setCursor(0, 1);
lcd.print("no. of pushes:");
lcd.println(buttonPushCounter);
}
if (buttonPushCounter % 0 != 0) {
lcd.setCursor(0, 1);
lcd.print("no. of pushes:");
lcd.println(buttonPushCounter);
}
}
EB2FT.ino (1.7 KB)