Has anyone a code example that shows how to read values from an int array that is located in an Library.
Function in library
myval:Result()
.
.
Res[0]=Jw;
Res1]=Mw;
Res2]=Tw;
Res[3]=Store;
return ???
Thanks for all answers
Wolfgang
Has anyone a code example that shows how to read values from an int array that is located in an Library.
Function in library
myval:Result()
.
.
Res[0]=Jw;
Res1]=Mw;
Res2]=Tw;
Res[3]=Store;
return ???
Thanks for all answers
Wolfgang
Has anyone a code example that shows how to read values from an int array that is located in an Library.
If the library contains a class, one set of answers is possible.
If the library contains just a collection of functions, another set of answers is possible.
There is no general way applicable to all libraries. You'll need to provide more details, including code that makes sense.
Even after too much to drink, my code looks better than that. That looks more like the morning after.
Here my smal sample codes.
Please tell me what to do to read values from aray res[] into Arduino sketch.
:~
//Arduino Test sketch
#include <PV.h>
#include <SoftwareSerial.h>
PV pv;
int Tw;
void setup()
{
Serial.begin(9600);
}
void loop()
{
//Here I wont read the content of the array res
??=pv.AddValues();
Serial.print(??);
delay(1000)
}
/*
PV.cpp - Library
*/
#include "Arduino.h"
#include "PV.h"
PV::PV()
{
}
//-----------------------------------------------------------------------
int PV::AddValues()//Addiere Ertragswerte und Speichere ggf. aud SD Karte
{
Store=0;
if ((Year < YearOld) || (Year > YearOld)){ // Jahreswechsel
Store=1;
YearOld=Year; //Jahreszahl
JwOld=Jw;
Jw=0;
} //Jahreswert löschen
else{
Jw=Jw+1;
}
if ((Month < MonthOld) || (Month > MonthOld)){ // Monatswechsel
Store=1;
MonthOld=Month; //Monats Nummer
MwOld=Mw; //Monatswert in Vormonatwert speichern
Mw=0;
} //Monatswert löschen
else{
Mw=Mw+1;
}
if ((Hour==0) && (Minute==1)){// Tageswechsel
if (TwDone==0){//Damit wird dieser Teil nur 1* in Minute 1 durchlaufen
Store=1;
TwDone=1;
TwOld=Tw;
Tw=0;
}
}
else if ((Hour==0) && (Minute>=2)){
Tw=Tw+1;
TwDone=0;
}
res[0]=Jw;
res[1]=Mw;
res[2]=Tw;
res[3]=Store;
return ???; //<-------------- Here should returned the int array res[]
}// Ende AddValues
/*
PV.h - Library
*/
#ifndef PV_h
#define PV_h
#include "Arduino.h"
class PV
{
public:
PV();
int AddValues();//Addiere Ertragswerte
private:
int res[6];
int i;
int Year;
int YearOld;
int Month;
int MonthOld;
int Hour;
int Minute;
int Day;
int DayOld;
int Tw; //Tageswert
int TwOld; //Vortageswert
int Mw;
int MwOld;
int Jw;
int JwOld;
int TwDone;
int Store;
};
#endif
Please tell me what to do to read values from aray res[] into Arduino sketch.
private:
int res[6];
You can't.
You can provide a method that returns the ith value in the array. Something like:
public:
int GetArrayVal(int index);
int PV::GetArrayVal(int index)
{
if(index >= 0 && index < 6)
return res[index];
else
return -9999;
}
for(byte b=0; b<6; b++)
{
Serial.print("pv.res[");
Serial.print(b);
Serial.print("] = ");
Serial.println(pv.GetArrayVal(b));
}
Thanks a lot for your quick and very helpfull answer.