Double digit led control with max7219

Hello everybody

For a project for school I’m trying to make a scoreboard with 2 double digit seven segment displays. I also use a max7219 for which i use the library ledcontrol.
So I use 2 pushbuttons, one for each display. When I only write my code for the first pushbutton (= knop1) the display adds one every time i press the pushbutton. But when I add the same code for the second display, I can only take turns to raise the display each. So when I push button 1 (=knop1) it adds one to the first display, but when I push it again it does nothing until i push button 2 (knop2) which first adds one to the second display before i can add one to the first display again. I hope someone can helpt me with this problem.

Thanks in advance,
an Arduino learning student.

The code:

#include “LedControl.h” //bibliotheek voor aansturing 2 digit 7 segment LED display via de max7219

LedControl lc = LedControl(12,11,10,1); //duidt aangesloten pinnen aan van de max7219 (din, clock,load, aantal max7219 IC’s)

int knop1 = 2;
int knop2 = 3;

int display1 = 0;
int display2 = 0;

int linkerdigit;
int rechterdigit;

int statusknop1;
int statusknop2;

void setup() {

lc.shutdown(0,false); // Wake up MAX7219

lc.setIntensity(0,7); // Set brightness to medium


pinMode (knop1, INPUT_PULLUP); //stelt knop 1 als input
pinMode (knop2, INPUT_PULLUP); //stelt knop 2 als input



void scorethuis () {


rechterdigit = display1%10;
linkerdigit = display1%100/10;


while (!digitalRead(knop1)) {

void scoreuit (){


rechterdigit = display2%10;
linkerdigit = display2%100/10;


while (!digitalRead(knop2)) {

void loop() {

if (!digitalRead(knop1)){

if (!digitalRead(knop2)){

@aarondw topic moved from Installations and Troubleshooting

Duplicate topics moved and merged

Cross-posting is against the rules of the forum. The reason is that duplicate posts can waste the time of the people trying to help. Someone might spend 15 minutes (or more) writing a detailed answer on this topic, without knowing that someone else already did the same in the other topic.

Repeated cross-posting will result in a timeout from the forum.

In the future, please take some time to pick the forum board that best suits the topic of your question and then only post once to that forum board. This is basic forum etiquette, as explained in the sticky "How to use this forum - please read." post you will find at the top of every forum board. It contains a lot of other useful information. Please read it.

Thanks in advance for your cooperation.

To add to what noiasca points out, OK, first things first.

You need to go and read the forum instructions so that you can go back and modify your original post (not re-post it) - using the “More → Modify” option below the right hand corner of your post - to mark up your code as such using the “</>” icon in the posting window. Just highlight each section of code (or output if you later need to post that) from the IDE and click the icon.

In fact, the IDE itself has a “copy for forum” link to put these markings on a highlighted block for you so you then just paste it here in a posting window. But even before doing that, don’t forget to use the “Auto-Format” (Ctrl-T) option first to make it easy to read. While you were lucky so far, If you do not post it as “code” it can easily be quite garbled and is always more difficult to read due to the font.

It is inappropriate to attach it as a “.ino” file unless it is clearly too long to include in the post proper. People can usually see the mistakes directly and do not want to have to actually load it in their own IDE. And even that would also assume they are using a PC and have the IDE running on that PC.

Also tidy up your blank space. Do use blank lines, but only single blanks between complete functional blocks.

Why do we think this is more important than just having your question answered? Because it is really difficult to write code properly - as with any other task requiring care - if everything is disorganised!