#include <EEPROM.h>
#include <keypad.h>
#define ROWS 4
#define COLS 3
keypad kpd = keypad(ROWS, COLS);
int m_digit = 0;
int m_dollar = 1;
int prevalue;
int value;
int value_dollar;
int value_dollar_fixed;
// Definition of the block of pins to be used with pull-up pins in the INPUT
int lin0 = 8; // Line 1 - Pin 3 - Understands characters 1 2 3
int lin1 = 7; // Line 2 - Pin 2 - Understands characters 4 5 6
int lin2 = 6; // Line 3 - Pin 1 - Understands characters 7 8 9
int lin3 = 5; // Line 4 - Pin 0 - Understands characters * 0 #
int LedPin = 13 ; // indicates that the pin 13 is connected to the LED
//Pin connected to ST_CP of 74HC595
int latchPin = 10;
//Pin connected to SH_CP of 74HC595
int clockPin = 12;
////Pin connected to DS of 74HC595
int dataPin = 11;
//holders for infromation you're going to pass to shifting function
int dataDOLLARa[] = {0xBF, 0x94, 0xF7, 0xF7, 0xFD, 0xEF, 0xEF, 0x97, 0xFF, 0xFF};
int dataDOLLARaBLANK = 0x00;
int dataDOLLARaALL = 0xFF;
int dataDOLLARb[] = {0x1F, 0x12, 0x1D, 0x1E, 0x12, 0x1E, 0x1F, 0x12, 0x1F, 0x12};
int dataDOLLARbBLANK = 0x00;
int dataDOLLARbALL = 0xFF;
void setup() {
//set pins to output because they are addressed in the main loop
pinMode(lin0, INPUT); // Transforms the input to pin 3
pinMode(lin1, INPUT); // Transforms the input to pin 2
pinMode(lin2, INPUT); // Transforms the input pin 1 in
pinMode(lin3, INPUT); // Transforms the input pin 0 in
kpd.init(); // Starts at the keyboard matrix 4x3
pinMode(LedPin, OUTPUT); // Set the LED pin as output
pinMode(latchPin, OUTPUT);
digitalWrite(lin0, HIGH); // indicates use of the Pull-Up Line 1
digitalWrite(lin1, HIGH); // indicates use of the Pull-Up Row 2
digitalWrite(lin2, HIGH); // indicates use of the Pull-Up Line 3
digitalWrite(lin3, HIGH); // indicates use of the Pull-Up Line 4
Serial.begin (9600), // Start the serial connection at 9600 baud
Serial.print("Hello, how are you today?"); // indicates to the operator
Serial.print('\n');
value_dollar = EEPROM.read(m_dollar);
value_dollar_fixed = value_dollar - 48;
delay(100);
Serial.print(value_dollar_fixed);
shiftOut(dataPin, clockPin, dataDOLLARaBLANK);
shiftOut(dataPin, clockPin, dataDOLLARbBLANK);
shiftOut(dataPin, clockPin, dataDOLLARa[value_dollar_fixed]);
shiftOut(dataPin, clockPin, dataDOLLARb[value_dollar_fixed]);
EEPROM.write(0, 0);
}
void loop() {
char key = kpd.get_key();
if(key != '\0')
{
digitalWrite(LedPin, HIGH);
delay(100);
digitalWrite(LedPin, LOW);
shiftOut(dataPin, clockPin, dataDOLLARaBLANK);
shiftOut(dataPin, clockPin, dataDOLLARbBLANK);
value = EEPROM.read(m_digit);
delay(100);
if (value == 0)
{
EEPROM.write(1, key);
EEPROM.write(0, 1);
Serial.begin(9600);
Serial.print("key1=");
Serial.print(key);
Serial.print('\n');
if(key == '1')
{
digitalWrite(latchPin, 0);
shiftOut(dataPin, clockPin, dataDOLLARaBLANK);
shiftOut(dataPin, clockPin, dataDOLLARbBLANK);
delay(50);
shiftOut(dataPin, clockPin, dataDOLLARaBLANK);
shiftOut(dataPin, clockPin, dataDOLLARbBLANK);
delay(50);
shiftOut(dataPin, clockPin, dataDOLLARa[1]);
shiftOut(dataPin, clockPin, dataDOLLARb[1]);
digitalWrite(latchPin, 1);
}
}
if (value == 1)
{
EEPROM.write(2, key);
EEPROM.write(0, 2);
Serial.begin(9600);
Serial.print("key2=");
Serial.print(key);
Serial.print('\n');
if(key == '1')
{
digitalWrite(latchPin, 0);
shiftOut(dataPin, clockPin, dataDOLLARaBLANK);
shiftOut(dataPin, clockPin, dataDOLLARbBLANK);
delay(50);
shiftOut(dataPin, clockPin, dataDOLLARaBLANK);
shiftOut(dataPin, clockPin, dataDOLLARbBLANK);
delay(50);
shiftOut(dataPin, clockPin, dataDOLLARa[1]);
shiftOut(dataPin, clockPin, dataDOLLARb[1]);
digitalWrite(latchPin, 1);
}
}
if (value == 2)
{
EEPROM.write(3, key);
EEPROM.write(0, 0);
Serial.begin(9600);
Serial.print("key3=");
Serial.print(key);
Serial.print('\n');
if(key == '1')
{
digitalWrite(latchPin, 0);
shiftOut(dataPin, clockPin, dataDOLLARaBLANK);
shiftOut(dataPin, clockPin, dataDOLLARbBLANK);
delay(50);
shiftOut(dataPin, clockPin, dataDOLLARaBLANK);
shiftOut(dataPin, clockPin, dataDOLLARbBLANK);
delay(50);
shiftOut(dataPin, clockPin, dataDOLLARa[1]);
shiftOut(dataPin, clockPin, dataDOLLARb[1]);
digitalWrite(latchPin, 1);
}
}
}
}
// the heart of the program
void shiftOut(int myDataPin, int myClockPin, byte myDataOut) {
// This shifts 8 bits out MSB first,
//on the rising edge of the clock,
//clock idles low
//internal function setup
int i=0;
int pinState;
pinMode(myClockPin, OUTPUT);
pinMode(myDataPin, OUTPUT);
//clear everything out just in case to
//prepare shift register for bit shifting
digitalWrite(myDataPin, 0);
digitalWrite(myClockPin, 0);
//for each bit in the byte myDataOut?
//NOTICE THAT WE ARE COUNTING DOWN in our for loop
//This means that %00000001 or "1" will go through such
//that it will be pin Q0 that lights.
for (i=7; i>=0; i--) {
digitalWrite(myClockPin, 0);
//if the value passed to myDataOut and a bitmask result
// true then... so if we are at i=6 and our value is
// %11010100 it would the code compares it to %01000000
// and proceeds to set pinState to 1.
if ( myDataOut & (1<<i) ) {
pinState= 1;
}
else {
pinState= 0;
}
//Sets the pin to HIGH or LOW depending on pinState
digitalWrite(myDataPin, pinState);
//register shifts bits on upstroke of clock pin
digitalWrite(myClockPin, 1);
//zero the data pin after shift to prevent bleed through
digitalWrite(myDataPin, 0);
}
//stop shifting
digitalWrite(myClockPin, 0);
}
Thank you