Seven Segment Display code problem

I’ve been trying to get this code made from various elements in the Led Contol Playground Article at http://www.arduino.cc/playground/Main/MAX72XXHardware but can’t get it to compile correctly.

The Arduino IDE throws the following error:

"too few arguments to function ‘void printNumber(int)’

Does anyone know what is wrong with that part of the code?

Thanks in advance.

// Prints an int value (-999..999) on a display with 4 digits

#include "LedControl.h"

/*
 pin 12 is connected to the DataIn 
 pin 11 is connected to the CLK 
 pin 10 is connected to LOAD 
 Using a single MAX7219
 */
 
LedControl lc=LedControl(12,11,10,1);
unsigned long delaytime=250;

void setup() {
  lc.shutdown(0,false);   // MAX72XX is in power-saving mode on startup, do a wakeup call
  lc.setIntensity(0,8);   // Set the brightness to a medium values
  lc.clearDisplay(0);     // clear the display
}

void printNumber(int v) {
    int ones;
    int tens;
    int hundreds;
    boolean negative;      

    if(v < -999 || v > 999) 
       return;
    if(v<0) {
        negative=true;
        v=v*-1;
    }
    ones=v%10;
    v=v/10;
    tens=v%10;
    v=v/10;
    hundreds=v;                  
    if(negative) {
             
       lc.setChar(0,3,'-',false);   //print character '-' in the leftmost column
    }
    else {
       
       lc.setChar(0,3,' ',false);   //print a blank in the sign column
    }
    
    lc.setDigit(0,2,(byte)hundreds,false);   // Print the numbers digit by digit
    lc.setDigit(0,1,(byte)tens,false);
    lc.setDigit(0,0,(byte)ones,false);
}



void scrollDigits() {           // Scroll all the hexa-decimal numbers and letters
  for(int i=0;i<13;i++) {
    lc.setDigit(0,3,i,false);
    lc.setDigit(0,2,i+1,false);
    lc.setDigit(0,1,i+2,false);
    lc.setDigit(0,0,i+3,false);
    delay(delaytime);
  }
  lc.clearDisplay(0);
  delay(delaytime);
}

void loop() { 
  printNumber();
  scrollDigits();
}

You defined the function printNumber() to take an integer as an argument, but in loop() you are attempting to call it without an argument. You actually need to tell it the number you want to print. This is one case where the compiler error is actually quite helpful.

  • Ben

Thanks Ben

But I thought the 'void printNumber(int)' part of the code would print the numbers -999 through to 999?

I'm obviously missing something major. How should I modify the code in loop() ?

From the comments at the top of your program, it would seem that it's intended to print out a single number (the restrictions on that number is that it be from -999 to 999). You should modify the code in loop to print out the numbers you want printed. I can't really tell you more than this because I'm not personally familiar with the hardware you're working with.

  • Ben

Thanks very much Ben

I'll keep working on getting a better understanding of the code.

Appreciate your help.