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.

closed as too broad by Mattia, KIIV, Avamander Oct 31 '16 at 22:37

Please edit the question to limit it to a specific problem with enough detail to identify an adequate answer. Avoid asking multiple distinct questions at once. See the How to Ask page for help clarifying this question. If this question can be reworded to fit the rules in the help center, please edit the question.


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() {


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
  • Thank you for your answer. I will definitely add this code once I get my keypad. Thanks a lot. – Zhamepace Oct 15 '16 at 2:03

Not the answer you're looking for? Browse other questions tagged or ask your own question.