Hey Everyone,
I am working on a some hardware that keeps track of moisture levels in 4 different plants.
I spent the last two days learning about c++, and this is my first attempt at writing anything. I am running into a small problem. I know the problem I am having is a name scape issue, but I am not sure how to correctly reference the proper name scape.
class moistureSensor{
public: // Access specifier
String input;
const int airValue = 620;
const int waterValue = 310;
int moistureValue = 0;
double moisturePercent = 0;
double getSoilMoisture(){
moistureValue = analogRead(input);
moisturePercent = map(moistureValue, airValue, waterValue, 0, 100);
if(moisturePercent >= 100){
moisturePercent = 100;
}
if(moisturePercent <=0){
moisturePercent = 0;
}
return moisturePercent;
};
};
void setup() {
Serial.begin(9600);
moistureSensor ms1;
ms1.input = "A0";
moistureSensor ms2;
ms2.input = "A1";
moistureSensor ms3;
ms3.input = "A2";
moistureSensor ms4;
ms4.input = "A3";
}
void loop() {
ms1.getSoilMoisture();
Serial.println(ms1.input);
Serial.println(ms1.getSoilMoisturePercent());
ms2.getSoilMoisture();
Serial.println(ms2.input);
Serial.println(ms2.getSoilMoisturePercent());
ms3.getSoilMoisture();
Serial.println(ms3.input);
Serial.println(ms3.getSoilMoisturePercent());
ms4.getSoilMoisture();
Serial.println(ms4.input);
Serial.println(ms4.getSoilMoisturePercent());
delay(250);
}
I am getting an error because I am trying to reference ms1, ms2, ms3, ms4 in loop(), while they were referenced in setup()
Also, I suspect calling
analogRead(input);
might give me problems, because I don't know if "string" in the proper variable type.
Can anyone help?
Thanks