I have a program that works, until I type "#" which I thought would only have made the char str[17] equal to 16 spaces again, but when I press "#" the first column of the keypad stops responding.
What am I doing wrong here?
I thought I was being safe using char to hold the 17 length string instead of String, but I must be affecting the program to make it misbehave.
#include <Keypad.h>
#include <Wire.h>
#include <LiquidCrystal_I2C.h>
LiquidCrystal_I2C lcd(0x27,20,4);
const byte ROWS = 4; //four rows
const byte COLS = 4; //three columns
char keys[ROWS][COLS] = {
{'1','2','3','A'},
{'4','5','6','B'},
{'7','8','9','C'},
{'*','0','#','D'}
};
char str[17]=" ";
byte rowPins[ROWS] = {5, 4, 3, 2}; //connect to the row pinouts of the keypad
byte colPins[COLS] = {9, 8, 7, 6}; //connect to the column pinouts of the keypad
int d=0;
Keypad keypad = Keypad( makeKeymap(keys), rowPins, colPins, ROWS, COLS );
void setup(){
Serial.begin(9600);
lcd.init(); // initialize the lcd
lcd.init();
// Print a message to the LCD.
lcd.backlight();
lcd.setCursor(0,0);
lcd.print("PLAY SONG NUMBER....");
lcd.setCursor(0,1);
lcd.print("");
lcd.setCursor(0,2);
lcd.print("");
lcd.setCursor(0,3);
lcd.print("");
}
void loop(){
char key = keypad.getKey();
if (key=='#'){
str[17]=" ";
d=0;
}
if (key and key!='#' and d<16){
Serial.println(key);
str[d] = key;
d=d+1;
Serial.println(d);
lcd.setCursor(0,3);
lcd.print(str);
}
}