1

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.

8
  • 1
    What error are your recieving? Or what result? First, you need a constructor and declare a new instance....
    – jabujavi
    Jul 29, 2015 at 11:40
  • error: 'string' has not been declared void TestPrint(string w, string h); How do i do that? in c# I know but in c++/arduino I am new at this. I tried to set up an array of char[] but it does not work for me.
    – Dany Maor
    Jul 29, 2015 at 11:43
  • Try with String. See also : link
    – jabujavi
    Jul 29, 2015 at 11:53
  • i get : error: 'String' has not been declared void TestPrint(String w, String h);
    – Dany Maor
    Jul 29, 2015 at 12:07
  • did you try putting #include "Arduino.h" in the h file instead of the cpp one? And of course use the capital S for String... Anyway... This is just a test library, ok. But... I suggest you to avoid using complex types such as String.. Fixed sized buffers (e.g. char mystring[10]) are much better
    – frarugi87
    Jul 29, 2015 at 12:21

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Browse other questions tagged or ask your own question.