As I'd like to add Arabic Numbers to my LCD I2C project, I followed the instructions in this tutorials.
and here is code provided by the Author on GIThub
And here is my version, All What I did is changed the sequence of the second array to display Arabic numbers instead of the English numbers.
#include <Adafruit_LiquidCrystal.h>
#include <Keypad.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'}
};
byte pin_rows[ROW_NUM] = {9, 8, 7, 6}; // connect to the row pinouts of the keypad
byte pin_column[COLUMN_NUM] = {5, 4, 3, 2}; // connect to the column pinouts of the keypad
Keypad keypad = Keypad(makeKeymap(keys), pin_rows, pin_column, ROW_NUM, COLUMN_NUM );
Adafruit_LiquidCrystal lcd_1(0);
uint8_t custChar[8][8] = {
{31, 31, 31, 0, 0, 0, 0, 0}, // Small top line - 0
{0, 0, 0, 0, 0, 31, 31, 31}, // Small bottom line - 1
{ B11111,
B00000,
B00000,
B00000, // This shows an alternative
B00000, // way of defining a custome character,
B00000, // a bit more 'visually' perhaps?
B00000,
B11111,
},
//{31, 0, 0, 0, 0, 0, 0, 31}, // Small lines top and bottom -2
{0, 0, 0, 0, 0, 0, 0, 31}, // Thin bottom line - 3
{31, 31, 31, 31, 31, 31, 15, 7}, // Left bottom chamfer full - 4
{28, 30, 31, 31, 31, 31, 31, 31}, // Right top chamfer full -5
{31, 31, 31, 31, 31, 31, 30, 28}, // Right bottom chamfer full -6
{7, 15, 31, 31, 31, 31, 31, 31}, // Left top chamfer full -7
};
// Define our numbers 0 thru 9
// 254 is blank and 255 is the "Full Block"
uint8_t bigNums[10][6] = {
{1, 254, 254, 0, 254, 254}, //0
{254, 255, 254, 254, 255, 254}, //1
{255, 0, 0, 255, 254, 254}, //2
{255, 3, 255, 255, 254, 254}, //3
{7, 2, 0, 5, 3, 1}, //4
{254, 1, 254, 4, 1, 6}, //5
{0, 0, 5, 254, 254,255}, //6
{255, 254, 255, 4, 1, 6}, //7
{7, 0, 5, 255, 254, 255}, //8
{255, 2, 5, 255, 254, 254}, //9
};
void setup() {
// Initiate the LCD:
lcd_1.begin(16,2);
}
int cursorColumn = 0;
void printBigNum(int number, int startCol, int startRow) {
// Position cursor to requested position (each char takes 3 cols plus a space col)
lcd_1.setCursor(startCol, startRow);
// Each number split over two lines, 3 chars per line. Retrieve character
// from the main array to make working with it here a bit easier.
uint8_t thisNumber[6];
for (int cnt = 0; cnt < 6; cnt++) {
thisNumber[cnt] = bigNums[number][cnt];
}
// First line (top half) of digit
for (int cnt = 0; cnt < 3; cnt++) {
lcd_1.print((char)thisNumber[cnt]);
}
// Now position cursor to next line at same start column for digit
lcd_1.setCursor(startCol, startRow + 1);
// 2nd line (bottom half)
for (int cnt = 3; cnt < 6; cnt++) {
lcd_1.print((char)thisNumber[cnt]);
}
}
void loop(){
char key = keypad.getKey();
if (key) {
lcd_1.setCursor(cursorColumn,0); // move cursor to (cursorColumn, 0)
//lcd_1.print(key); // print key at (cursorColumn, 0)
printBigNum(key, cursorColumn, 0);
cursorColumn+=4; // move cursor to next position
if(cursorColumn > 16) { // if reaching limit, clear LCD
lcd_1.clear();
cursorColumn = 0;
}
}
}
And here is the link to the simulation on tinkercad
it seems that my code works partially except for not being able to display the supposed Characters?
What is the possible fix for that.