#include <LiquidCrystal.h>
#include <LedControl.h>
#include <Keypad.h>
#ilude <stdio.h>
byte inc=0;
const byte ROWS = 4; //four rows
const byte COLS = 3; //three columns
char store[20];
char keys[ROWS][COLS] = {
{'1','2','3'},
{'4','5','6'},
{'7','8','9'},
{'*','0','#'}
};
byte rowPins[ROWS] = {25, 24, 23, 22}; //connect to the row pinouts of the keypad
byte colPins[COLS] = {28, 27, 26}; //connect to the column pinouts of the keypad
Keypad keypad = Keypad( makeKeymap(keys), rowPins, colPins, ROWS, COLS );
/*
Now we need a LedControl to work with.
***** These pin numbers will probably not work with your hardware *****
pin 12 is connected to the DataIn
pin 11 is connected to the CLK
pin 10 is connected to LOAD
We have only a single MAX72XX.
*/
LedControl lc=LedControl(50,51,53,2);
LiquidCrystal lcd(35, 34, 33, 32, 31, 30);
void setup() {
/*
The MAX72XX is in power-saving mode on startup,
we have to do a wakeup call
*/
for(byte intro=0 ; intro<=1; intro++)
{
lc.shutdown(intro,false);
/* Set the brightness to a medium values */
lc.setIntensity(intro,8);
/* and clear the display */
lc.clearDisplay(intro);
}
// set up the LCD's number of columns and rows:
lcd.begin(20, 4);
}
void MAX(char val[],byte addr)
{
unsigned long temp_val = atoi(val);
if(temp_val>=0 && temp_val<=9)
{
lc.setChar(addr,0,(byte)temp_val,false);
}
else if(temp_val>=10 && temp_val<=99)
{
int one,ten;
one = temp_val%10;
ten = (temp_val/10)%10;
lc.setChar(addr,0,(byte)ten,false);
lc.setChar(addr,1,(byte)one,false);
}
else if(temp_val>=100 && temp_val<=999)
{
int one,ten,hundred;
one = temp_val%10;
ten = (temp_val/10)%10;
hundred = (temp_val/100)%10;
lc.setChar(addr,0,(byte)hundred,false);
lc.setChar(addr,1,(byte)ten,false);
lc.setChar(addr,2,(byte)one,false);
}
else if(temp_val>=100 && temp_val<=999)
{
int one,ten,hundred;
one = temp_val%10;
ten = (temp_val/10)%10;
hundred = (temp_val/100)%10;
lc.setChar(addr,0,(byte)hundred,false);
lc.setChar(addr,1,(byte)ten,false);
lc.setChar(addr,2,(byte)one,false);
}
else if(temp_val>=1000 && temp_val<=9999)
{
int one,ten,hundred,thousand;
one = temp_val%10;
ten = (temp_val/10)%10;
hundred = (temp_val/100)%10;
thousand = (temp_val/1000)%10;
lc.setChar(addr,0,(byte)thousand,false);
lc.setChar(addr,1,(byte)hundred,false);
lc.setChar(addr,2,(byte)ten,false);
lc.setChar(addr,3,(byte)one,false);
}
else if(temp_val>=10000 && temp_val<=99999)
{
int one,ten,hundred,thousand;
long tenthousand;
one = temp_val%10;
ten = (temp_val/10)%10;
hundred = (temp_val/100)%10;
thousand = (temp_val/1000)%10;
tenthousand = (temp_val/10000)%10;
lc.setChar(addr,0,(byte)tenthousand,false);
lc.setChar(addr,1,(byte)thousand,false);
lc.setChar(addr,2,(byte)hundred,false);
lc.setChar(addr,3,(byte)ten,false);
lc.setChar(addr,4,(byte)one,false);
}
}
void loop()
{
char key = keypad.getKey();
if(key == '#' || key == '*')
{
if(key == '#')
{
lcd.print(store);
MAX(store,0);
inc=0;
}
if(key == '*')
{
lcd.clear();
for(byte erase=0 ; erase<=20 ; erase++)
store[erase]=0;
for(byte dig_clear=0 ; dig_clear<=6 ; dig_clear++)
lc.setChar(0,dig_clear,' ',false);
inc=0;
}
}
else if(key)
{
store[inc] = key;
inc++;
}
}