Not declared in this scope error

Hi all,

Please forgive me if this is 'obvious and basic' but I am totally new to Arduino and C++ so am struggling to understand where the problem is.

I am trying to build a project called Tiny Altimeter and slowly working my way through the various parts of the hardware and software to get it up and running.

Currently I am working on a sketch called altimetre_oled_bmp180_04.ino which has the code in the first attachment

(can't post code here because it exceeds text length of 9000 characters)

and when I attempt to verify the code the IDE throws the following errors

Using library button_1_0_0 at version 1.0.0 in folder: /home/ubuntu/opt/libraries/latest/button_1_0_0

Using library EEPROM at version 2.0 in folder: /home/ubuntu/opt/cores/arduino/avr/libraries/EEPROM

/tmp/466659420/Tiny_Altimeter/Tiny_Altimeter.ino:40:37: error: 'BUTTON_PULLDOWN' was not declared in this scope

Button button1 = Button(BUTTON1_PIN,BUTTON_PULLDOWN);

^

/tmp/466659420/Tiny_Altimeter/Tiny_Altimeter.ino: In function 'void setup()':

/tmp/466659420/Tiny_Altimeter/Tiny_Altimeter.ino:63:11: error: 'class Button' has no member named 'releaseHandler'

button1.releaseHandler(handleButtonReleaseEvents);

^

/tmp/466659420/Tiny_Altimeter/Tiny_Altimeter.ino:64:11: error: 'class Button' has no member named 'holdHandler'

button1.holdHandler(handleButtonHoldEvents,2000);

^

/tmp/466659420/Tiny_Altimeter/Tiny_Altimeter.ino:91:11: error: 'class Button' has no member named 'isPressed'

button1.isPressed();

^

/tmp/466659420/Tiny_Altimeter/Tiny_Altimeter.ino: In function 'void loop()':

/tmp/466659420/Tiny_Altimeter/Tiny_Altimeter.ino:100:11: error: 'class Button' has no member named 'isPressed'

button1.isPressed();

^

exit status 1

Obviously something is not right with the BUTTON stuff, but I am at a loss to try and track it down.
Any guidance would be very greatly appreciated, thanks in advance.

altimetre_oled_bmp180_04.ino (8.94 KB)

Perhaps I should have also included the Button.h code so here it is

/* $Id$
||
|| @author         Alexander Brevig <abrevig@wiring.org.co>
|| @url            http://wiring.org.co/
|| @url            http://alexanderbrevig.com/
|| @contribution   Brett Hagman <bhagman@wiring.org.co>
||
|| @description
|| | Hardware Abstraction Library for Buttons.
|| | It provides an easy way of handling buttons.
|| |
|| | Wiring Cross-platform Library
|| #
||
|| @license Please see cores/Common/License.txt.
||
*/

#ifndef BUTTON_H
#define BUTTON_H

#include <stdint.h>

#define BUTTON_PULLUP HIGH
#define BUTTON_PULLUP_INTERNAL 2
#define BUTTON_PULLDOWN LOW

class Button;
typedef void (*buttonEventHandler)(Button&);

class Button
{
  public:

    Button(uint8_t buttonPin, uint8_t buttonMode = BUTTON_PULLUP_INTERNAL);

    void pullup(uint8_t buttonMode);
    void pulldown();

    bool isPressed();
    bool wasPressed();
    bool stateChanged();
    bool uniquePress();

    void setHoldThreshold(unsigned int holdTime);
    bool held(unsigned int time = 0);
    bool heldFor(unsigned int time);

    void pressHandler(buttonEventHandler handler);
    void releaseHandler(buttonEventHandler handler);
    void clickHandler(buttonEventHandler handler);
    void holdHandler(buttonEventHandler handler, unsigned int holdTime = 0);

    unsigned int holdTime() const;
    inline unsigned int presses() const
    {
      return numberOfPresses;
    }

    bool operator==(Button &rhs);

  private:
    uint8_t pin;
    uint8_t mode;
    uint8_t state;
    unsigned long pressedStartTime;
    unsigned int holdEventThreshold;
    buttonEventHandler cb_onPress;
    buttonEventHandler cb_onRelease;
    buttonEventHandler cb_onClick;
    buttonEventHandler cb_onHold;
    unsigned int numberOfPresses;
    bool triggeredHoldEvent;
};

#endif
// BUTTON_H

At the top of this Forum there is a "Useful Links". In that post there is a section called "C++ Programming" and within that is a section on Scope. Read that and see if it helps.

econjack:
At the top of this Forum there is a "Useful Links". In that post there is a section called "C++ Programming" and within that is a section on Scope. Read that and see if it helps.

Thanks I will check it out

econjack:
At the top of this Forum there is a "Useful Links". In that post there is a section called "C++ Programming" and within that is a section on Scope. Read that and see if it helps.

I am sure that you were trying to be helpful with this reply, however as far as I can see there is no such "Useful Links" anywhere within the Arduino site.

If you were referring to this bit of info (https://www.arduino.cc/reference/en/language/variables/variable-scope--qualifiers/scope/) then I am afraid that I am still too new for this to be of any real assistance.

As I said in my original post

Please forgive me if this is 'obvious and basic' but I am totally new to Arduino and C++ so am struggling to understand where the problem is.

Thanks anyway

Here's your clue:

GrahamM:

Using library button_1_0_0 at version 1.0.0 in folder: /home/ubuntu/opt/libraries/latest/button_1_0_0

The Button library used is the one in the Library Manager index:

That is a completely different library from the one your code was written for. You must import the button library your code was written for. I'll assume that is GitHub - tigoe/Button: A fork of Alexander Brevig's Button library for Arduino. If not, then adjust the below instructions accordingly. Unfortunately, the author of the Button library didn't use the correct folder name for the example sketches, which causes the import process to fail in the Arduino Web Editor. This adds some extra steps:

  • Download the library: https://github.com/tigoe/Button/archive/master.zip
  • Unzip the downloaded file.
  • Rename the Examples folder to examples.
  • Zip the modified library.
  • Start the Arduino Web Editor.
  • Click the "Libraries" tab.
  • Click the Import button (upward pointing arrow)
  • If you get a popup about importing your sketchbook, click the "Import" button.
  • Select the zip file that contains the modified Button library.
  • Click "Open".
  • Wait until you get a popup that confirms the library has been imported.

Awesome, thanks pert

I did as suggested and re-verified the sketch, no more references to button!!!

It now throws another bunch of errors but I suspect they relate to similar library issues so I will work my way through the error messages to try and resolve them further.

Really appreciate the guidance and the clear, easy way in which you laid it out - very helpful.

I'm glad if I was able to be of assistance.

It might be helpful to understand where this unwanted Button library came from. With the regular Arduino IDE, there are a handful of official Arduino libraries that come pre-installed. You can also choose from thousands of 3rd party libraries to easily install via Library Manager (Sketch > Include Library > Manage Libraries), but these are not pre-installed. With the Arduino Web Editor, they decided they'd pre-install all the thousands of 3rd party libraries in the Library Manager index. That can end up causing troubles when a different library than the one you wanted happens to have a file that matches the #include directive in your code (in this case, Button.h). It can be tricky to fix because you have no way to remove the unwanted pre-installed libraries. So it's a good idea to pay attention to the output that tells you which library is being used. The ones under the /home/ubuntu/opt/libraries folder are the pre-installed libraries. The libraries you import are under a folder that looks something like /tmp/703997053/custom.

Regards, Per

I came across your issue report on GitHub and I can see now that that it includes the Button library, and others under the libs folder:

Once again, thanks for the excellenty help and extra information.

Regarding the unwanted library files is there a way to force the sketch to use my /tmp/ library instead of the pre-installed ones?

Cheers,
Graham

The most reliable way I've found to do that is to add a dummy .h file, which has a filename that will not be found in any other library, to the library you import. For example, you could name the file UseThisButtonLibrary.h. You need to add some content to the file, otherwise the Arduino Web Editor won't import it. I recommend using an explanatory comment for this purpose:

// This file is used to force this library to be used

The library which contains a file from a previous #include directive will be used. So if you do this in your code:

#include <UseThisButtonLibrary.h>
#include <Button.h>

You'll be sure that the library you imported is used.

Great thanks, really appreciate the help :slight_smile:

GrahamM:
I am sure that you were trying to be helpful with this reply, however as far as I can see there is no such "Useful Links" anywhere within the Arduino site.

If you were referring to this bit of info (https://www.arduino.cc/reference/en/language/variables/variable-scope--qualifiers/scope/) then I am afraid that I am still too new for this to be of any real assistance.

As I said in my original post
Thanks anyway

No, that is not the one I was referring to. The one I'm referring to appears at the very top of this Forum:

Programming Questions - Arduino Forum.

and carries the title:

Useful links - check here for reference posts / tutorials

It's put together by Nick Gammon, probably one of the most knowledgeable people on this site.