the source code for libraries is located in specific directories known to the Arduino IDE.
the #include in an .ino file identifies the library by name. when the .ino is built, it along with other files including the library files are copied into a build directly from when the binary is built and downloaded to the board
sounds like you copied the library file to the directory containing the .ino file, hence there are multiple copies and duplicate definitions
the compiler will firs look in the sketch directory for the file and if not found then in the sub folders of the libraries folder of your Sketchbook. Loading a .h file implies that there is a corresponding .cpp in the same folder and if so then that is loaded too
(Profile - UKHeliBob - Arduino Forum);
I did not know that loading the .h file implied that there was a corresponding .cpp file
that automatically gets loaded.
Is including the code #include "PS2Keyboard_nano_33_ble.cpp" wrong?
I am trying to get a morse code keyboard that worked on the simple NANO
to work on the NANO 33 BLE. The problem is leading me to the .cpp file.
I wanted to bring it(.cpp) into the IDE for troubleshooting.
The only way I know to do that is by declaring it an #Include.
yes.
the include copies that file into the file the #include is in. if there's also a copy of the file in the directory with the .ino, then there's effectively two copies of the code
To make it show up as a tab in the IDE, copy the file to your sketch directory. It will always be compiled as part of your sketch.
NOTE: I think the problem is having: #include "PS2Keyboard_nano_33_ble.h"
in your sketch without having "PS2Keyboard_nano_33_ble.h" in your sketch directory. That will cause the compiler to look through all of the library directories for the library that contains "PS2Keyboard_nano_33_ble.h". If it finds that file in a library it will include all of the .cpp files for that library in your build. IF you have a copy of "PS2Keyboard_nano_33_ble.cpp" in your sketch directory AND in the library that contains "PS2Keyboard_nano_33_ble.h" you will get BOTH included in your build and a lot of duplicate definitions.
If you put "PS2Keyboard_nano_33_ble.cpp" in your sketch directory so it shows up as a tab in your sketch, also do that for "PS2Keyboard_nano_33_ble.h".
John,
My sketch directory has the directory "PS2Keyer_NANO_33_BLE".
Under that directory is "PS2Keyer_NANO_33_BLE.ino" and another directory
named libraries.
Under the libraries directory are four folders, Adafruit_BusIO, Adafruit_GFX_Library, Adafruit_SSD1306, and the important one:PS2Keyboard_nano_33_ble.
It contains the directory "examples" and the .h and .cpp files.
I'm messing with the library because the .h file contained the line "include avr/io.h.
This isn't in the core for the NANO 33 BLE and prevented compiling.
I remarked it out and am trying to see what trouble I am in.
I got the .cpp into the IDE by unremarking its #include, right clicking it and selecting "go to Definition. Then I remarked the .cpp out again.