Serial.println in class in Arduino

I am trying to do Serial.println()inside a class in an Arduino environment. However, the compiler says it has Serialnot been declared in this area. Here is the code:

Code in Menu.h

class Menu
{
    public:
        int options[4];

        void test() {
          Serial.println("here");
        }

    private:

};

The code in the main file:

#include "Menu.h"

Menu menu;

void setup() {
    Serial.begin(9600);
    menu.test();
}

void loop() {
}
+3
source share
2 answers

The rule #includeis probably automatically added by Arduino to yours .pde. Try #include <WProgram.h>the top of yours Menu.h.

+4
source

I'm not sure if the code fragment is complete (if not, write the full one), but it looks like you forgot to include the corresponding header file that the class declares Serial.

0
source

All Articles