Combining keypad and 8 digit 7 segment display (SKU DFR0646\DFR0645)
Hi
I am trying to write to the individual digits of the “8 digit 7 segment display”, but I am not able to do it based on an array (or other variables).
I am able to write both to the individual segments and send doubles into it, but I would like the input to come from an array.
So instead of:
LEDDisplaySegmentObject.print("1","2","3","4","5","6","7","8")I would like the individual segments to come from an array (that have 8 values that comes from the keypad):
LEDDisplaySegmentObject.print(KeypadInputArray[0], KeypadInputArray[1], KeypadInputArray[2], KeypadInputArray[3], KeypadInputArray[4], KeypadInputArray[5], KeypadInputArray[6], KeypadInputArray[7]);
The reason why I would like to do it as sending to the individual digits, is because the remaining figures should be “blank”.
I think that the problem is because of the value comming from the keypad is “char” and then it instert it in the print-command of the segment display as 48, 49, 50 etc. instead of 0, 1, 2 etc.
Thanks in advance - I have tried for five hours and I am getting kind of frustated.
/Henrik
// Libraries
#include <Keypad.h>
#include "DFRobot_LedDisplayModule.h"
// Set Up KeypadObject
const byte ROWS = 4;
const byte COLS = 3;
char keys[ROWS][COLS] = {
{'1','2','3'},
{'4','5','6'},
{'7','8','9'},
{'*','0','#'}
};
byte rowPins[ROWS] = {6, 11, 10, 8}; // Row pinouts of the keypad
byte colPins[COLS] = {7, 5, 9}; // Column pinouts of the keypad
// Create KeypadObject
Keypad KeypadObject = Keypad( makeKeymap(keys), rowPins, colPins, ROWS, COLS );
// Create LEDDisplaySegmentObject
DFRobot_LedDisplayModule LEDDisplaySegmentObject(&Wire, 0xE0);
// Create Variables
int KeypadInputNo = -1;
int KeypadInputArray[8] = {"","","","","4","","",""};
////////////////////////////////////////////
//// Setup
////////////////////////////////////////////
void setup(){
Serial.begin(9600);
/*Wait for the chip to be initialized completely, and then exit*/
while(LEDDisplaySegmentObject.begin(LEDDisplaySegmentObject.e8Bit) != 0)
{
Serial.println("Failed to initialize the chip , please confirm the chip connection!");
delay(1000);
}
//Set LEDDisplaySegmentObject Display Area
LEDDisplaySegmentObject.setDisplayArea(1,2,3,4,5,6,7,8);
//Clear LEDDisplaySegmentObject Display Area
LEDDisplaySegmentObject.print("","","","","","","","");
//Print "KLAR"
Serial.println("<<<KLAR>>>");
}
////////////////////////////////////////////
//// Main Loop
////////////////////////////////////////////
void loop(){
//Get CurrentKeyPress
char CurrentKeyPress = KeypadObject.getKey();
if (CurrentKeyPress){
if ((CurrentKeyPress == 48) || (CurrentKeyPress == 49) || (CurrentKeyPress == 50) || (CurrentKeyPress == 51) || (CurrentKeyPress == 52) || (CurrentKeyPress == 53) || (CurrentKeyPress == 54) || (CurrentKeyPress == 55) || (CurrentKeyPress == 56) || (CurrentKeyPress == 57)){
//Update KeypadInputNo
KeypadInputNo = KeypadInputNo + 1;
//Update KeypadInputArray
KeypadInputArray[KeypadInputNo] = CurrentKeyPress;
//Write Current Input To Serial Monitor
Serial.print("No. ");
Serial.print(KeypadInputNo);
Serial.print(" - ");
Serial.println(KeypadInputArray[KeypadInputNo]);
//Update Display LEDDisplaySegmentObject.print(KeypadInputArray[0],KeypadInputArray[1],KeypadInputArray[2],KeypadInputArray[3],KeypadInputArray[4],KeypadInputArray[5],KeypadInputArray[6],KeypadInputArray[7]);
//Check For Correct Input If Last Digit
if (KeypadInputNo == 7){
CheckForCorrectInput(KeypadInputNo);
}
}
}
}
////////////////////////////////////////////
//// Check For Correct Input
////////////////////////////////////////////
void CheckForCorrectInput(int& KeypadInputNo){
//Write Status To Serial Monitor
Serial.println("TEST FULL INPUT");
//Reset KeypadInputNo
KeypadInputNo = -1;
//Perform Code For Wrong Input
InputIsWrong();
}
////////////////////////////////////////////
//// Input Is Correct
////////////////////////////////////////////
void InputIsCorrect(){
}
////////////////////////////////////////////
//// Input Is Wrong
////////////////////////////////////////////
void InputIsWrong(){
//Make Display Flash For Two Seconds
LEDDisplaySegmentObject.flashHalfs();
delay(2000);
LEDDisplaySegmentObject.stopFlash();
//Reset Display
LEDDisplaySegmentObject.print("","","","","","","","");
}