#include <TM1637.h>
#include <Keypad.h>
const uint8_t ROWS = 4;
const uint8_t COLS = 4;
char keys[ROWS][COLS] = {
{ '1', '2', '3', 'A' },
{ '4', '5', '6', 'B' },
{ '7', '8', '9', 'C' },
{ '*', '0', '#', 'D' }
};
uint8_t colPins[COLS] = { 33, 32, 22, 21 }; // Pins connected to C1, C2, C3, C4
uint8_t rowPins[ROWS] = { 14, 27, 26, 25 }; // Pins connected to R1, R2, R3, R4
int playerScores[2];
int playerLegs[2];
char inData[4];
// Counter for character entries
byte dataCount = 0;
// Character to hold key input
char customKey;
TM1637 TM1, TM2; // Each display needs its own object
Keypad keypad = Keypad(makeKeymap(keys), rowPins, colPins, ROWS, COLS);
void setup() {
Serial.begin(115200);
Serial.println("Ready\n");
// -----------------------------------------
// First display
// -----------------------------------------
TM1.begin(18, 19, 4); // clockpin, datapin, #digits
TM1.displayClear();
TM1.setBrightness(7); // full brightness, default is 3
// -----------------------------------------
// Second display
// -----------------------------------------
TM2.begin(16, 17, 4); // clockpin, datapin, #digits
TM2.displayClear();
TM2.setBrightness(7); // full brightness, default is 3
}
void loop() {
char buffer[5];
// put your main code here, to run repeatedly:
delay(10); // this speeds up the simulation
// Look for keypress
customKey = keypad.getKey();
if (customKey) {
// Enter keypress into array and increment counter
if (customKey != '#') {
int temp = customKey - '0';
//Serial.print(temp);
inData[dataCount] = customKey;
Serial.print(temp * pow(10, dataCount + 1), 0);
playerScores[0] = (int)(temp * pow(10, (dataCount)) + playerScores[0]);
//TM1.displayInt(tempDisplay);
dataCount++;
} else{
Serial.println();
playerScores[0] = atoi(inData);
inData[0] = '\0';
dataCount = 0;
}
}
//playerScores[0] = 501;
playerScores[1] = 301;
playerLegs[0] = 0;
playerLegs[1] = 0;
int displayOne = (playerScores[0] * 10) + playerLegs[0];
int displayTwo = (playerLegs[1] * 1000) + playerScores[1];
TM1.displayInt(displayOne);
TM2.displayInt(displayTwo);
}