Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // #include <PID_v1.h>
- // include motor
- //general status
- const String IDLE_STATUS = "idle";
- //irrigation status
- const String IRRIGATION_STATUS = "irrigation";
- const String IRRIGATION_ERROR_STATUS = "irrigation_error";
- const String IRRIGATED_STATUS = "irrigated";
- //calibration status
- const String CALIBRATION_STATUS = "calibration";
- const String CALIBRATION_ERROR_STATUS = "calibration_error";
- const String CALIBRATED_STATUS = "calibrated";
- //test status
- const String TEST_STATUS = "test";
- const String TEST_ERROR_STATUS = "test_error";
- const String TESTED_STATUS = "tested";
- // PID constants
- // const float ki = 1;
- // const float kp = 1;
- // const float kd = 1;
- class WaterPump {
- private:
- string id;
- string status;
- int pin;
- bool onError; //inUse
- AFMOTOR motor;
- // PID myPID;
- // double pid_input;
- // double pid_output;
- // double pid_setpoint;
- public:
- WaterPump (string id, int pin) {
- this->id = id;
- this->pin = pin;
- this->pin = IDLE_STATUS;
- this->onError = false;
- this->motor(this->pin);
- // this->myPID(&this->pid_input, &this->pid_output, &this->pid_setpoint, kp, ki, kd, DIRECT);
- }
- int calculateDelayTime (ml) {
- //freq
- //speed
- //time
- return //f(time, ml, freq, speed) =
- }
- void irrigation (float ml) {
- // validate if exist an error
- if (this->onError) {
- Serial.println("la bomba esta con error ->", this->status);
- return;
- }
- // validate if status equal to "irrigation"
- if (this->status == IRRIGATION_STATUS) {
- Serial.println("la bomba está regando ->", this->status);
- return;
- }
- // validate if status equal to "calibration"
- if (this->status == CALIBRATION_STATUS) {
- Serial.println("la bomba se está calibrando ->", this->status);
- return;
- }
- //change to irrigation status
- Serial.println("water pump changed status: ", IRRIGATION_STATUS);
- this->status = IRRIGATION_STATUS;
- //calculate and get magic time number for use inside delay method
- int delayTime = this->calculateDelayTime(ml)
- //turn on this motor to start irrigation
- Serial.println("la bomba se ha encendido");
- this->motor(FORWARD);
- //wait magic delay number
- Serial.println("esperando X segundos", delayTime);
- delay(delayTime);
- //turn off water pump irrigation
- Serial.println("la bomba se ha detenido");
- this->motor(RELEASE);
- //chage to irrigated status
- Serial.println("water pump changed status: ", IRRIGATED_STATUS);
- this->status = IRRIGATED_STATUS
- }
- void calibration (float ml) {}
- void test (float ml, float time) {
- // validate if water pump is in use
- //change to test status
- Serial.println("water pump changed status: ", TEST_STATUS);
- this->status = TEST_STATUS;
- irrigation (float ml)
- }
- }
Add Comment
Please, Sign In to add comment