I have an arduino project and need to create a library. I'm fine calling in a void in a constructor that does not return any value.
But I just cannot figure out how to return a string.
Below is just the template from a tutorial, please ignore the name of the header and source code file.
Morse.h.
Morse.cpp
in the end I want to be able to do this.
Eeprm.readdata(1) passws the integer [1] to the void which then reads from address [1] and then returns the value which was read from address 1 in the memory of the arduino.
Please note: have basic experience with c++ i mostly make use standard if this then, some for loops.
But I just cannot figure out how to return a string.
Below is just the template from a tutorial, please ignore the name of the header and source code file.
Morse.h.
Code:
/*
Morse.h - Library for flashing Morse code.
Created by David A. Mellis, November 2, 2007.
Released into the public domain.
*/
#ifndef Morse_h
#define Morse_h
#include "Arduino.h"
class Eeprm
{
public:
Eeprm(int Nothing);
void writedata(int addr,String datatowrite );
void readdata(String addr);
private:
};
#endif
Morse.cpp
I left out void writedata(int addr,String datatowrite ); from the source code because its working fine./*
Morse.cpp - Library for flashing Morse code.
Created by David A. Mellis, November 2, 2007.
Released into the public domain.
*/
#include <WString.h> // include the String library
#include <EEPROM.h>
#include "Arduino.h"
#include "Morse.h"
Eeprm::Eeprm(int Nothing ){}
void Eeprm::readdata(int addr)
{
return "aaaa";
}
in the end I want to be able to do this.
String Myreturneddata;
Myreturneddata=Eeprm.readdata(1);
Eeprm.readdata(1) passws the integer [1] to the void which then reads from address [1] and then returns the value which was read from address 1 in the memory of the arduino.
Please note: have basic experience with c++ i mostly make use standard if this then, some for loops.
Last edited: