AWOL:
I was just thinking that if you reduced the size of your code, you could post it here, instead of forcing people to download it.
I have reduced the code (removed the config of the seven segment display driver which is only bitshifting):
// pins
// pins for the keypad
const unsigned char PinLedTest = 53;
const unsigned char PinBtn[10] = {34, 52, 50, 48, 46, 44, 42, 40, 38, 36};
// pins for controlling the seven segment display via MAX7219
const unsigned char SevenSegPinLatch = A0;
const unsigned char SevenSegPinClock = A2;
const unsigned char SevenSegPinData = A1;
// variables
// general variables
unsigned long int CurTime; // auxiliary variable for timeouts, button debouncing etc.
// variables for the keypad
unsigned char CurStateBtn[4] = {HIGH, HIGH, HIGH, HIGH}; // variable for debouncing the buttons
unsigned char OldStateBtn[4] = {HIGH, HIGH, HIGH, HIGH}; // variable for debouncing the buttons
unsigned char CurDigitCount = 0; // auxiliary variable for assigning the pressed button to the correct digit
unsigned char Digit[4] = {0, 0, 0, 0}; // auxiliary variable for buffering the single digits of EnteredNumber1 and EnteredNumber2 while they are entered
const unsigned char Tdeb = 10; // debouncing time of the buttons
// variables for the panel controller
unsigned char EnteredNumber1[10] = {}; // entered number 1 for further processing; maximum 10 values can be stored
unsigned char EnteredNumber2[10] = {}; // entered number 2 for further processing; maximum 10 values can be stored
unsigned char CurNumListEntries = 0; // auxiliary variable for counting the current number of list entries
// variables for the seven segment display
unsigned char SevenSegDigits = 4; // number of vailable digits on the seven segment display
unsigned char SevenSegDot = 0b10000000; // address of the dot of the seven segment display
unsigned char SevenSegDigit[4] = { 0x01, // = Digit 0 // addresses of the digits of the seven segment display
0x02, // = Digit 1
0x03, // = Digit 2
0x04, // = Digit 3
};
unsigned char SevenSegChar[11] = { 0b01111110, // = 0 // characters to be shown on the seven segment display
0b00110000, // = 1
0b01101101, // = 2
0b01111001, // = 3
0b00110011, // = 4
0b01011011, // = 5
0b01011111, // = 6
0b01110000, // = 7
0b01111111, // = 8
0b01111011, // = 9
0b00000000, // = blank
};
// functions
// functions for the keypad
// function for monitoring the buttons (true = one of the buttons is pressed)
bool BtnPressed() {
for(unsigned char x = 0; x <= 9; x++) { // number of buttons ("<= 9" for 10 buttons)
if(digitalRead(PinBtn[x])) {}
else { return true; }
}
return false;
}
// functions for the seven segment display
// function for reseting all COM pins of the seven segment display, respectively of the MAX7219
void SevenSegResetComPins() {
digitalWrite(SevenSegPinLatch, HIGH);
digitalWrite(SevenSegPinClock, LOW);
digitalWrite(SevenSegPinData, HIGH);
}
// function for sending the chosen digit/character to the seven segment display (via MAX7219)
void SendSevenSegNumber(unsigned char SevenSegDigit[], unsigned char SevenSegChar[], unsigned char SevenSegDot = 0b00000000) {
SevenSegResetComPins();
digitalWrite(SevenSegPinLatch, LOW);
shiftOut(SevenSegPinData, SevenSegPinClock, MSBFIRST, SevenSegDigit);
// adding a dot if explicitly specified (SevenSegDot)
if(SevenSegDot == 0b10000000) {
unsigned char a = SevenSegChar;
SevenSegChar = a | SevenSegDot;
}
shiftOut(SevenSegPinData, SevenSegPinClock, MSBFIRST, SevenSegChar);
digitalWrite(SevenSegPinLatch, HIGH);
}
// function for clearing the display of the seven segment display - except from the dot on the second digit
void SevenSegClearDisplay() {
SendSevenSegNumber(SevenSegDigit[0], SevenSegChar[10]);
SendSevenSegNumber(SevenSegDigit[1], SevenSegChar[10], SevenSegDot);
SendSevenSegNumber(SevenSegDigit[2], SevenSegChar[10]);
SendSevenSegNumber(SevenSegDigit[3], SevenSegChar[10]);
}
void setup() {
// Arduino setup
// starting serial monitor communication at baud rate 9600
Serial.begin(9600);
// keypad setup
// selecting pin mode for seven segment pins
for(byte i = 0; i <= 9; i++) { pinMode(PinBtn[i], INPUT_PULLUP); }
pinMode(PinLedTest, OUTPUT);
// sevent segment display setup
// selecting pin mode for seven segment pins
pinMode(SevenSegPinLatch, OUTPUT);
pinMode(SevenSegPinClock, OUTPUT);
pinMode(SevenSegPinData, OUTPUT);
/* ... config of the seven segment driver ... */
Serial.println("setup finished");
}
void loop() {
// checking if a button of the keypad is pressed and processing the entered numbers 1 and 2
if(BtnPressed()) {
if(CurDigitCount <= 3) { // number of digits to be entered ("<= 3" for 4 digits)
byte x;
for(x = 0; x <= 9; x++) { // number of buttons ("<= 9" for 10 buttons)
CurStateBtn[x] = digitalRead(PinBtn[x]);
// debouncing the button when pressing it
if(CurStateBtn[x] != OldStateBtn[x]) {
OldStateBtn[x] = CurStateBtn[x];
CurTime = millis();
while(millis() - CurTime < Tdeb) {}
}
if(CurStateBtn[x] == LOW) {
// activating the test LED when the button is pressed
digitalWrite(PinLedTest, HIGH);
// no further action as long as the button is pressed
while(CurStateBtn[x] == LOW) {
CurStateBtn[x] = digitalRead(PinBtn[x]);
// debouncing the button when releasing it
if(CurStateBtn[x] != OldStateBtn[x]) {
OldStateBtn[x] = CurStateBtn[x];
CurTime = millis();
while(millis() - CurTime < Tdeb) {}
}
}
// deactiving the test LED when the button has been released
digitalWrite(PinLedTest, LOW);
// assigning the value of the pressed button to the current digit
Digit[CurDigitCount] = x;
}
}
// displaying the entered value on the respective digit of the seven segment display
if(CurDigitCount == 1) { SendSevenSegNumber(SevenSegDigit[CurDigitCount], SevenSegChar[Digit[CurDigitCount]], SevenSegDot); }
else { SendSevenSegNumber(SevenSegDigit[CurDigitCount], SevenSegChar[Digit[CurDigitCount]]); }
CurDigitCount++;
// process after a value for every digit has been entered
if(CurDigitCount > 3) {
// displaying the complete entered value for a short time on the seven segment display
CurTime = millis();
while(millis() - CurTime < 2000) {}
Serial.println("serial monitor test");
// creating the entered numbers 1 and 2 out of the values of the entered digits
EnteredNumber1[CurNumListEntries] = (10 * Digit[0]) + (1 * Digit[1]);
EnteredNumber1[CurNumListEntries] = (10 * Digit[2]) + (1 * Digit[3]);
CurNumListEntries++;
SevenSegClearDisplay();
// reseting variables
CurDigitCount = 0;
for(byte i = 0; i <= 3; i++) { Digit[i] = 0; }
}
}
}
}