#include <Keypad.h>
#include <LiquidCrystal_I2C.h>
#include <Wire.h>
LiquidCrystal_I2C lcd(0x27, 20, 4); // I2C address 0x27, 20 column and 4 rows
#define pulsesensor 3
const byte ROWS = 4;
const byte COLS = 4;
char keys[ROWS][COLS] = {
{'1','2','3','A'},
{'4','5','6','B'},
{'7','8','9','C'},
{'*','0','#','D'}
};
byte rowPins[ROWS] = { A9, A8, A7, A6 };
byte colPins[COLS] = { A5, A4, A3, A2 };
Keypad keypad = Keypad(makeKeymap(keys), rowPins, colPins, ROWS, COLS);
volatile int turns = 0;
int pulse = 0;
int cursorColumn = 10;
void setup() {
pinMode(pulsesensor, INPUT);
attachInterrupt(digitalPinToInterrupt(3), calculatepulse, HIGH);
lcd.init(); // initialize the lcd
lcd.backlight();
}
void loop(){
lcd.setCursor(7, 0);
lcd.print ("16C #8");
lcd.setCursor(0, 2);
lcd.print("ACTUAL COUNT=");
lcd.print(turns);
lcd.setCursor(18, 2);
lcd.print ("FT");
lcd.setCursor(0, 3);
lcd.print ("STOP AT=");
lcd.setCursor(18, 3);
lcd.print ("FT");
char key = keypad.getKey();
if (key) {
lcd.setCursor(cursorColumn, 3);// print key at (cursorColumn, 3)
lcd.print(key);
cursorColumn++; // move cursor to next position
if(cursorColumn == 16) { // if reaching limit, clear LCD
lcd.clear();
cursorColumn = 10; // reset cursor position
}
}
}
void calculatepulse(){
if (pulse < 80)
pulse = pulse + 1;
if (pulse == 80)
turns = turns + 1;
if (pulse >= 80)
pulse = 0;
}
Welcome to the forum
Thank You! I am currently reading your breakdowns of the keypad use and is very helpful
This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.