I am using the mega 2560. When I just use .ino and .h files, if I use Serial, it works fine, without even using:
#include <SoftwareSerial.h>
However, when I add a .cpp file I start getting 2 errors, one is solved by adding the aforementioned include, the second one, after adding it, is :
'Serial' was not declared in this scope
I know I can declare it manually and use the RX/TX pins, but I would like to be able to use the default Serial so that I don't have to occupy more pins. Especially since it works file w/o the .cpp file. Can anyone explain to me why this happens? Is it because I specify a C++ file so the compiler changes?
1 Answer 1
A CPP file isn't an Arduino file. It doesn't know about anything Arduino-esque unless you tell it about it.
The simplest way is to just add, at the top of the file:
#include <Arduino.h>
-
Ah, damn once you say it it becomes so obvious, thank you.Bbit– Bbit2020年07月04日 15:01:03 +00:00Commented Jul 4, 2020 at 15:01