Creating my first class and library
hello. long time lurker first time poster. did read how , i'm trying adhere rules as possible. if i'm in error in 1 of them please let me know.
i have watering program. there bunch more code in trying debug i've removed of code can make sure there isn't else causing problem. it's worked me before in solving problems time code simple can , i'm still getting error.
the object trying create irrigation valve. valve have, now, 3 attributes. have pin energizes valve, duration how long active, , setpoint once surpassed activate valve, after return zero. want initialize attributes , store them in private section? of class. first time i've created library , class perhaps can point me toward i'm making mistake in syntax or initialization. know i'm not supposed excessively use defines , in future user prompted @ setup define these parameters in addition many other valves added use them during prototyping simplicity. did fail create object? if syntax station station; perhaps?
the error getting following:
irrigation_5_0.ino: in function 'void setup()':
irrigation_5_0:20: error: expected unqualified-id before '.' token
this code in sketch:
this header file:
this cpp file:
i have watering program. there bunch more code in trying debug i've removed of code can make sure there isn't else causing problem. it's worked me before in solving problems time code simple can , i'm still getting error.
the object trying create irrigation valve. valve have, now, 3 attributes. have pin energizes valve, duration how long active, , setpoint once surpassed activate valve, after return zero. want initialize attributes , store them in private section? of class. first time i've created library , class perhaps can point me toward i'm making mistake in syntax or initialization. know i'm not supposed excessively use defines , in future user prompted @ setup define these parameters in addition many other valves added use them during prototyping simplicity. did fail create object? if syntax station station; perhaps?
the error getting following:
irrigation_5_0.ino: in function 'void setup()':
irrigation_5_0:20: error: expected unqualified-id before '.' token
this code in sketch:
code: [select]
#include <station.h>
#define valve 9// valve wired pin 9
#define duration 10000// valve on 10 seconds
#define setpoint 20//valve on when accumulating value reaches 20 points or more
void setup()
{
station.begin(valve, duration, setpoint);//error located here
}
void loop()
{
}
this header file:
code: [select]
#ifndef station_h
#define station_h
#include "arduino.h"
class station
{
public:
void begin(int valve, int duration, int setpoint);
private:
int newvalve;
int newduration;
int newvpdsetpoint;
};
#endif
this cpp file:
code: [select]
#include "station.h"
#include "arduino.h"
station::begin(int valve, int duration, int setpoint)
{
newvalve = valve;
newduration = duration;
newsetpoint = setpoint;
}
here compiles...
code: [select]
class station
{
public:
void begin(int valve, int duration, int setpoint);
private:
int newvalve;
int newduration;
int newsetpoint;
};
void station::begin(int valve, int duration, int setpoint)
{
newvalve = valve;
newduration = duration;
newsetpoint = setpoint;
}
#define valve 9// valve wired pin 9
#define duration 10000// valve on 10 seconds
#define setpoint 20//valve on when accumulating value reaches 20 points or more
station st;
void setup()
{
st.begin(valve, duration, setpoint);//error located here
}
void loop()
{
}
Arduino Forum > Using Arduino > Programming Questions > Creating my first class and library
arduino
Comments
Post a Comment