Compile Issue with 7-Segment LED Project...using the LedControl Library

Good Morning All,

I've having a compile issue with the sketch below. I keep getting an error message on line 16. Please help. Thanks so much!

Sketch is:

// Project 39: Ultrasonic Distance Display

#include <LedControl.h>

#define sensorPin 9
#define switchPin 7
#define DataIn 2
#define CLK 4
#define LOAD 3
#define NumChips 1
#define samples 5.0

float pwmRange, averageReading, inch, cm;
LedControl lc=LedControl(DataIn,CLK,LOAD,NumChips); // ??? ISSUE STARTS HERE

void setup() {

lc.shutdown(0, false);
lc.setIntensity(0,8);
lc.clearDisplay(0);

pinMode(sensorPin, INPUT);
pinMode(switchPin, INPUT);
}

void loop() {

averageReading = 0;

for (int i=0; i<samples; i++) {

pwmRange = pulseIn(sensorPin, HIGH);
averageReading += pwmRange;
}

averageReading /= samples;

inch = averageReading / 147;
cm = inch * 2.54;

if(digitalRead(switchPin)) {

displayDigit(inch);
}

else {

displayDigit(cm);
}
}

void displayDigit(float value) {

int number = value * 100;
lc.setDigit(0, 4, number / 10000, false);
lc.setDigit(0, 3, (number % 10000) / 1000, false);
lc.setDigit(0, 2, (number % 1000) / 100, true);
lc.setDigit(0, 1, (number % 100) / 10, false);
lc.setDigit(0, 0, number % 10, false);
}

Good Afternoon,

And the exact error message would be?

And can you please post your code using code (</>) tags, it makes it easier to read, and to others copy and paste into their IDE?

Hey,

I get the following error messages:

'LedControl' does not name a type
Project_39_Ultrasonic_Distance_Display:16: error: 'LedControl' does not name a type
Project_39_Ultrasonic_Distance_Display.ino: In function 'void setup()':
Project_39_Ultrasonic_Distance_Display:21: error: 'lc' was not declared in this scope
Project_39_Ultrasonic_Distance_Display.ino: In function 'void displayDigit(float)':
Project_39_Ultrasonic_Distance_Display:61: error: 'lc' was not declared in this scope

... Also, could you provide me with a very short example of how to properly post source code using (</>) tags? I'm new to this.

Thanks again!

At a rough guess you haven't downloaded, or correctly installed, the LedControl library?

Please read the post at the top of each section entitled 'How to use this forum' for details on forum etiquette, including the use of code tags.

I'm pretty sure I've downloaded the LedControl library correctly, and have it placed in the correct folder. I've downloaded and used several other libraries before, and had no issue.

Could you please try and compile the code that I posted and see if it compiles correctly for you?

Thanks so much.

Here's the code again:

// Project 39:  Ultrasonic Distance Display

#include <LedControl.h>


#define sensorPin 9
#define switchPin 7
#define DataIn 2
#define CLK 4
#define LOAD 3
#define NumChips 1
#define samples 5.0

float pwmRange, averageReading, inch, cm;
LedControl lc=LedControl(DataIn,CLK,LOAD,NumChips);  // ??? ISSUE STARTS HERE


void setup() {
 
  lc.shutdown(0, false);
  lc.setIntensity(0,8);
  lc.clearDisplay(0);
 
  pinMode(sensorPin, INPUT);
  pinMode(switchPin, INPUT);
}


void loop() {
 
  averageReading = 0;
 
  for (int i=0; i<samples; i++) {
   
    pwmRange = pulseIn(sensorPin, HIGH);
    averageReading += pwmRange;
  }
 
  averageReading /= samples;
 
  inch = averageReading / 147;
  cm = inch * 2.54;
 
 
  if(digitalRead(switchPin)) {
   
    displayDigit(inch);
  }
 
  else {
   
    displayDigit(cm);
  }
}


void displayDigit(float value) {
 
  int number = value * 100;
  lc.setDigit(0, 4, number / 10000, false);
  lc.setDigit(0, 3, (number % 10000) / 1000, false);
  lc.setDigit(0, 2, (number % 1000) / 100, true);
  lc.setDigit(0, 1, (number % 100) / 10, false);
  lc.setDigit(0, 0, number % 10, false);
}

[code]

It's not often that I will go away and download a library...

I downloaded LedControl-Master.zip from GitHub. I use an older version of the IDE so I have to unpack the library manually and the renamed it by removing the '-master' part of the folder name. The first thing I noticed is the absence of the .h and .cpp files where I would expect them, so to be consistent on my system I moved them up one level from src to LedControl.

You did as requested, thank you, and used code tags so I copied your code into my IDE window (which I had obviously restarted to pick up the new library), clicked the compile button and got:

Binary sketch size: 4,154 bytes (of a 32,256 byte maximum)

I'm on IDE 1.6.5 and it compiles fine for me too. Your library can't be properly installed in some way.

Sketch uses 3,864 bytes (12%) of program storage space. Maximum is 30,720 bytes.
Global variables use 113 bytes (5%) of dynamic memory, leaving 1,935 bytes for local variables. Maximum is 2,048 bytes.

Paul

Well, thanks so much for compiling the code. I'll check to see where all the different files are located at and try to compile it again.

All compiled correctly!

My .cpp & .h files were not in the main LedControl folder... like you said.

Lesson learned...haha

Thanks again.