my library for arduino don't work. why?

This is my first attempt to build a library for arduino. This is just an example for me to understand how to transfer values to functions in librarys on arduino. But it does not work and I do not understand why.

TESTDUINO.cpp

#include "Arduino.h"
#include "TESTDUINO.h"

void TESTDUINO::TestPrint(string w, string h){
    Serial.println("TestPring#" + w + "#" + h);
}

TESTDUINO.h

#ifndef Test_h
#define Test_h

class TESTDUINO{
public:
    void TestPrint(string w, string h);
};

#endif

arduino file

#include <TESTDUINO.h>

TESTDUINO testduino;

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

void loop() {
 testduino.TestPrint("200","200");
}

I am a C# Programmer and not so familiar with the C language so I’m sure I made a beginner’s mistake.

But it does not work and I do not understand why.

"it does not work" is rather lame. "The code compiles, links, uploads, but does not print anything" conveys far more information. "The stupid mess won't even compile" conveys something entirely different.

So, what does "it does not work" really mean?

void TESTDUINO::TestPrint(string w, string h){
    Serial.println("TestPring#" + w + "#" + h);
}

A "string" ?

the error msg:

Arduino: 1.6.5 (Windows 7), Board: "Arduino Uno"

In file included from sketch_jul29c.ino:1:0: C:\Program Files (x86)\Arduino\libraries\TESTDUINO/TESTDUINO.h:6:17: error: 'string' has not been declared void TestPrint(string w, string h); ^ C:\Program Files (x86)\Arduino\libraries\TESTDUINO/TESTDUINO.h:6:27: error: 'string' has not been declared void TestPrint(string w, string h); ^ sketch_jul29c.ino: In function 'void loop()': sketch_jul29c:10: error: invalid conversion from 'const char*' to 'int' [-fpermissive] In file included from sketch_jul29c.ino:1:0: C:\Program Files (x86)\Arduino\libraries\TESTDUINO/TESTDUINO.h:6:7: error: initializing argument 1 of 'void TESTDUINO::TestPrint(int, int)' [-fpermissive] void TestPrint(string w, string h); ^ sketch_jul29c:10: error: invalid conversion from 'const char*' to 'int' [-fpermissive] In file included from sketch_jul29c.ino:1:0: C:\Program Files (x86)\Arduino\libraries\TESTDUINO/TESTDUINO.h:6:7: error: initializing argument 2 of 'void TESTDUINO::TestPrint(int, int)' [-fpermissive] void TestPrint(string w, string h); ^ invalid conversion from 'const char*' to 'int' [-fpermissive]

This report would have more information with "Show verbose output during compilation" enabled in File > Preferences.

error: 'string' has not been declared

So, where do you think you defined it? The Arduino is not, in case you hadn't noticed, programmed in C#.

AWOL:

void TESTDUINO::TestPrint(string w, string h){

Serial.println(“TestPring#” + w + “#” + h);
}



A "string" ?

I did not understand. What no string in C++? I am c# Programmer and this is my first attempt to write Arduino library. So how can I fix it???

What no string in C++?

In C++, a string is a NULL terminated array of chars.

So how can I fix it?

    void TestPrint(char *w, char *h);

Of course, you'll need to change your implementation, too. And, read up on C strings.

in c# I know but in c++/arduino I am new at this. I tried to set up an array of char[] ןnstead of the string but it does not work for me.

I tried to set up an array of char[] ןnstead of the string but it does not work for me.

WHERE IS THE DAMNED CODE?

#include “Arduino.h”
#include “TESTDUINO.h”

void TESTDUINO::TestPrint(const char* w, const char* h){

Serial.println(“TestPring#” + w + “#” + h);
}

public:
void TestPrint(const char* w, const char* h);
};

i get error :

Arduino: 1.6.5 (Windows 7), Board: “Arduino Uno”

C:\Program Files (x86)\Arduino\libraries\TESTDUINO\TESTDUINO.cpp: In member function ‘void TESTDUINO::TestPrint(const char*, const char*)’:
C:\Program Files (x86)\Arduino\libraries\TESTDUINO\TESTDUINO.cpp:6:32: error: invalid operands of types ‘const char [11]’ and ‘const char*’ to binary ‘operator+’
Serial.println(“TestPring#” + w + “#” + h);
^
Error compiling.

From what I understand I need to convert char to string and send it over Serial.println. is it true? If so, how do i do it?

void TESTDUINO::TestPrint(const char* w, const char* h){
   
   Serial.print(F("TestPring#"));
   Serial.print(w);
   Serial.print('#');
   Serial.println("h);
}

& instead of + ?

evanmars: & instead of + ?

If you can't add strings, it seems unlikely that you can logically AND them, doesn't it?

Yes, was thinking in a different programming language. My bad.

Could you use concat to build a string to send to Serial.print(), although, I guess it's just as easy to use multiple Serial.prints.

I need to send it in one command.

Must be a way to do it :-) I would love to get more ideas on how to fix it.

maordany: I need to send it in one command.

Really? Why?

Well, there's strcat or sprintf

I need to send it in one command.

Nonsense. The data is written to a buffer, and shifted out one byte at a time. It does not matter how many bytes you wrote to the buffer at one time.