Library will not compile

I wrote a simple "bit-banging" sketch to send data between a pair of Arduino Uno's, and it works well.

While I know I'm reinventing the wheel here, in view of the availability of SPI, I2C, Serial... it was
an interesting process, and may well work over fairly long(ish) distances when serial isn't an option (eg all used up).

Alternatives comms processes exist, but I really need some help getting to the bottom of my problem, that being, trying to turn the working sketch into a library (my first). I've stared at the code for ages, checked the header and class files were formatted correctly based on my research, but it just won't compile.

The variable scError is declared in the .H file, but on compiling, I get...

C:\arduino-1.8.9\portable\sketchbook\libraries\SimpleComms\SimpleComms.cpp: In function 'int scSendByte(char)':
C:\arduino-1.8.9\portable\sketchbook\libraries\SimpleComms\SimpleComms.cpp:216:3: error: 'scError' was not declared in this scope

If I sneak the variable declaration into the .CPP file, compilation errors indicating the functions aren't declared. It's almost like the .H file isn't being included, but if I "include" a non-existent file in the code, I get the appropriate error indicating the file doesn't exist.... I'm at a loss....

All the files are in the attached zip, the working sketch in examples\working, the test sketch for the library in examples\sc1.

Be gentle with me, it's my first posting :slight_smile:

SimpleComms.zip (6.12 KB)

Not many people are happy about opening strange .zip files.

Post your files directly using code tags.

If they exceed the forum's character limit, you can either attach the .ino, .cpp, .h files or show them in-line (using code tags) in successive posts.

Do you notice a difference between these ...

SimpleComms::SimpleComms(void) {
int SimpleComms::SendString(char stringToSend[], uint8_t stringLength) {
int SimpleComms::GetString(char stringBuffer[]) {
int SimpleComms::DataAvailable(void) {
int SimpleComms::ErrorNumber(void) {

... and these ...

void scSetDataDirection(int inOrOut) {
void scClockOut(int level) {
void scDataOut(int level) {
int scClockInLevel(void) {
int scDataInLevel(void) {
int scWaitForClockIn(int highOrLow, int waitMs) {
int scSyncComms(int outOrIn) {
int scSendByte(char dataByte) {
char scGetByte(void) {
void scAckNak(int outOrIn, int ack) {

... which are all part of the class?

oqibidipo - Is it the SimpleComms:: prefix that you refer to? If so, I may be mistaken but I was thinking that this is the way to differentiate between the public "callable" functions and the private functions used within the library.

gfvalvo - Ah yes, I can see the problem there. Having looked at posts previously, I thought maybe supplying the full code of all the relevant files would be the way to go, and a zip would do the job.

NickDavison:
I may be mistaken

You are. You need SimpleComms:: on all member functions whether they are public, protected or private. Without it those functions are completely unrelated to the class.

oqibidipo - Oh my word, I added SimpleComms:: as a prefix to all the private functions, and now it compiles and works as expected.

Many thanks, I'm very grateful for your advice. The error I was getting totally threw me off track.
My first library at last. I'll know better next time.

Many thanks again.

Regards, Nick