Hello. Long time lurker first time poster. I did read the how to and I'm trying to adhere to the rules as much as possible. If I'm in error in one of them please let me know.
I have a watering program. There is a bunch more code but in trying to debug I've removed as much of the code as I can to make sure it there isn't something else causing the problem. It's worked for me before in solving problems but this time the code is about as simple as it can get and I'm still getting the error.
The object I am trying to create is a irrigation valve. The valve will have, for now, three attributes. It will have the pin that energizes the valve, a duration for how long it will be active, and a setpoint that once surpassed will activate the valve, after which it will return to zero. For now all I want to do is initialize those attributes and store them in the private section? of the class. This is the first time I've created a library and a class so perhaps you can point me toward where I'm making a mistake in my syntax or initialization. I know I'm not supposed to excessively use defines and in the future the user will be prompted at setup to define these parameters in addition to the many other valves that will be added but I will use them during prototyping for simplicity. Did I fail to create the object? If so what is the syntax for it Station Station; perhaps?
The error I am getting is the following:
Irrigation_5_0.ino: In function 'void setup()':
Irrigation_5_0:20: error: expected unqualified-id before '.' token
This is the code in my sketch:
#include <Station.h>
#define valve 9// valve wired to pin 9
#define duration 10000// valve on for 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 is my header file:
#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
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 to pin 9
#define duration 10000// valve on for 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()
{
}
Thanks for your input. I adhered as best I could to the tutorial on creating libraries( http://arduino.cc/en/Hacking/LibraryTutorial ) in the learning section but it looks like I have some reading to do to understand what you just said Paul. Maybe I didn't read far enough. Is this what they refer to as an "instance"?
googleing class static member to learn.
The objects' attributes such as valve, duration, and setpoint will remain constant except when the user decides to change them. When I get those attributes working properly I will be adding a fourth property, currentAccumulation. This fourth property will be augmented every ten seconds and the value in the class updated. Essentially when currentAccumulation>=setpoint, valve will be energized(HIGH) for n Duration. Is there any other aspect of classes I need to read up on to get it to act in the aforementioned manner?
So I've got that all up and running. I've taken the next step and added a bit more complexity to the program. Now I don't want to deal with one valve but multiple valves. I'm practicing sending arrays as parameters to my class. I've got it to compile. When I print out the values I've placed in the private portion of the class they changed. I only have the arduino IDE right now so it's a bit hard to know what is happening to the values I've loaded. Can anyone help me out?
My serial window prints the following upon execution of the program:
9
10
11
12
13
0
0
999
0
109
This is the main sketch:
#include <Station.h>
int i=5;
int userInvalve []={9,10,11,12,13};
Station st;
void setup(){
Serial.begin(9600);
for(int n=0; n<i; n++){
int value;
value=userInvalve[n];
Serial.println(value);
delay(500);
}
st.storevalve(userInvalve, i);
for(int n=0; n<i; n++){
int value;
value=st.getvalve(n);
Serial.println(value);
delay(500);
}
}
void loop(){
}
The header file:
#ifndef Station_h
#define Station_h
#include "Arduino.h"
class Station
{
public:
void storevalve(int userInvalve[],int i);
int getvalve(int n);
private:
int newvalve[];
};
#endif