I have the following components:
- Arduino Mega
- 7-segment display
- 12-digit key-pad
For my project, I would like to display on the 7-segment display the number that the user presses on the keypad.
Arduino Stack Exchange is a question and answer site for developers of open-source hardware and software that is compatible with Arduino. It only takes a minute to sign up.
Sign up to join this communityI have the following components:
For my project, I would like to display on the 7-segment display the number that the user presses on the keypad.
Try this: please note that you have to fill in the last function in order to get an int value from your keypad. The 7-segments part of the code should be fine.
const int segment[7] = {2,3,4,5,6,7,8}; //pins for each segment
const int nums[10][7] = //declaring array
{
{1,1,1,1,1,1,0}, //0
{0,1,1,0,0,0,0}, //1
{1,1,0,1,0,0,1}, //2
{1,1,1,1,0,0,1}, //3
{0,1,1,0,0,1,1}, //4
{1,0,1,1,0,1,1}, //5
{1,0,1,1,1,1,1}, //6
{1,1,1,0,0,0,0}, //7
{1,1,1,1,1,1,1}, //8
{1,1,1,0,0,1,1} //9
};
void setup() {
for(int i=2; i<=8; i++) //shorcut for declaring a buch of pin modes
{
pinMode(i, OUTPUT);
}
}
//=======================================================================
void loop() {
number(keypadInput);
}
//=======================================================================
void number(int num) //num is the number to display
{
for(int i=0; i<7; i++)
{
digitalWrite(segment[i], nums[num][i]);
}
}
int (keypadInput)
{
//code for getting the input of your keypad
}