Include file is found, but routine in it shows up as undeclared in this scope

Hi,
I’ve created my own library (AvinoLib) which resides in the project folder of the sketch in question. I include it using quotes since it’s local to the project folder.

// include the LCD library code:
#include <Wire.h>
#include <hd44780.h>                       // main hd44780 header
#include <hd44780ioClass/hd44780_I2Cexp.h> // i2c expander i/o class header

#include "AvinoLib.h"

// Set the pins used
#define cardSelect 4
#define BAG1 A2       // Bag1 input, LED connected to pin A2

There is also a version in my library path, but I don’t think that’s the issue because I don’t get a “file not found” error on the library file. Inside the .h file I have the function in question, getSmoothedSample():

class AvinoLib {
	private:
		uint8_t analogPin;
	public:
		// Constructor of the library class
		AvinoLib();

    // Gets a smoothed sample
    float getSmoothedSample(uint8_t analogPin);
};

I also have it in the .cpp file, which is in the same directory:

float AvinoLib::getSmoothedSample(uint8_t analogPin){
  const uint8_t nReads = 10;            //gather 10 readings each time we "sample"
  uint8_t pauseTime = 10;               //us to delay between samples
...

But when I try to compile, I get an error that getSmoothedSample is not declared in this scope. Here’s the code:

#include <SPI.h>
#include <SD.h>

// include the LCD library code:
#include <Wire.h>
#include <hd44780.h>                       // main hd44780 header
#include <hd44780ioClass/hd44780_I2Cexp.h> // i2c expander i/o class header

#include "AvinoLib.h"

#define VAC_CTRL 1    // Vacuum on/off input connected to pin D1
#define FILL_MODE 5   // Fill mode input connected to pin D5
#define GREEN_LED 8
#define DiffP A1      //input connected to A1

hd44780_I2Cexp lcd;   // declare lcd object: auto locate & auto config expander chip

// Set things up
void setup() {

  int LCDstatus;
  
  // connect serial at 115200
  Serial.begin(115200);
  Serial.println("\r\Adalogger M0 test");

  // set up the LCD
  LCDstatus = lcd.begin(20, 4);            // our display has 16 cols, 2 rows
  if(LCDstatus) // non zero status means it was unsuccesful
    {
    // hd44780 has a fatalError() routine that blinks an led if possible
    // begin() failed so blink error code using the onboard LED if possible
    hd44780::fatalError(LCDstatus); // does not return
    }
  lcd.print("Adalogger M0 test");       //say hi to the LCD.
  lcd.setCursor(0, 1);                  //go to next line
 
  pinMode(GREEN_LED, OUTPUT);            //Green LED next to SD card
  pinMode(FILL_MODE, INPUT);             //on/off switch is an input
}
  
void loop() {
  if(digitalRead(FILL_MODE)) {
    lcd.print("Sampling");                //show status on LCD.
    digitalWrite(GREEN_LED, HIGH);
    Serial.println(getSmoothedSample(DiffP));
    delay(10);
  }
  else {
    lcd.print("Standby");                //show status on LCD.
    digitalWrite(GREEN_LED, LOW);  
  }
}

What’s weird is that this library and the function worked fine a few days ago on a different computer. Any thoughts?
Thanks!

You forgot the object identifier for the class function.

What’s weird is that this library and the function worked fine a few days ago

That’s hard to believe - something has changed (or the other computer has a catastrophically bad compiler)

I can't see an instance of that class either.

countrypaul:
I can’t see an instance of that class either.

Well, it could be in the part(s) of “AvinoLib.h” that we can’t see, but it isn’t used in the body of the sketch shown.

TheMemberFormerlyKnownAsAWOL:
Well, it could be in the part(s) of "AvinoLib.h" that we can't see, but it isn't used in the body of the sketch shown.

Ah, I assumed that was the whole of "AvinoLib.h", but usually not good practice to declare an instance in the header file.

Well,of course not, but that’s the problem with snippets.

Thanks all,
Feeling stupid. You're all correct that I hadn't instantiate the library class in the sketch. The code that I recall working on the other computer was obviously something else. I need to install some new memory :confused:

This topic was automatically closed 120 days after the last reply. New replies are no longer allowed.