1

this is the sample code where the user enters A to set the number of times the pet needs to be fed. When I click A on the keypad it asks for the user to set the number. However, the keypad still somehow saves the input of A that is initially pressed. I want the system to ask for another input. How would I clear the memory of the keypad? Here is the code attached

    /* Hello Wokwi! */
#include <Keypad.h>
#include <LiquidCrystal_I2C.h>
const int ROW_NUM    = 4; // four rows
const int COLUMN_NUM = 4; // four columns
char keys[ROW_NUM][COLUMN_NUM] = {
  {'1','2','3', 'A'},
  {'4','5','6', 'B'},
  {'7','8','9', 'C'},
  {'*','0','#', 'D'}
};
int col = 0, row =0;
byte pin_rows[ROW_NUM] = {10,9,8,7};      // connect to the row pinouts of the keypad
byte pin_column[COLUMN_NUM] = {6,5,4,3}; // connect to the column pinouts of the keypad
LiquidCrystal_I2C lcd(0x27, 16, 2); // I2C address 0x27, 16 column and 2 rows
Keypad keypad = Keypad(makeKeymap(keys), pin_rows, pin_column, ROW_NUM, COLUMN_NUM );

void setup () {

lcd.init(); // initialize the lcd lcd.backlight(); lcd.setCursor(col,row); // move cursor to (cursorColumn, 0) lcd.print("HI OWNER"); delay(3000); } int h1,h2,hf1,min1,min2,minf1; int numfed,setnofeed=0;

void loop() {

char key = keypad.getKey(); if(!key){ displaytime(); }

switch(key){ case 'A': lcd.setCursor(col,row); lcd.print("SET NO. OF"); lcd.setCursor(col,1); lcd.print("FEEDING TIMES"); delay(3000);

lcd.clear();
lcd.setCursor(col,row);
lcd.print(&quot;MAX 5 MIN 2&quot;);
col=0;
lcd.setCursor(col,1);
if (col==0&amp;&amp;setnofeed==0){
  numfed=key-48;
  lcd.print(numfed);
  delay(1000);
  col=1;
}
else if(col==1){
lcd.setCursor(col,1);
lcd.clear();
lcd.print(&quot;NO. OF FEEDING&quot;);
lcd.setCursor(col,1);
lcd.print(&quot;SET&quot;);
delay(2000);
setnofeed=1;
}

break;


}

} void displaytime(){

  lcd.setCursor(0,0); // move cursor to   (cursorColumn, 0)
lcd.print(&quot;Time now:&quot;);

}

jsotola
  • 1,554
  • 2
  • 12
  • 20

0 Answers0