void setMotorSpeed(mraa::Pwm &pwm, mraa::Gpio &dir, double speed) { assert(-1.0 <= speed && speed <= 1.0); if (speed < 0) { dir.write(1); } else { dir.write(0); } pwm.write(fabs(speed)); }
// Turn on the water void turn_on() { if (turnedOn) return; pump->write(1); turnedOn = true; turnedOff = false; message("on"); }
// Turn off the water void turn_off() { if (turnedOff) return; pump->write(0); turnedOn = false; turnedOff = true; message("off"); }
// Initialization function void init() { // pump attached to A2 (aka D16) pump = new mraa::Gpio(16); pump->dir(mraa::DIR_OUT); pump->write(0); // moisture sensor attached to A1 moisture = new upm::GroveMoisture(1); };
void stop(mraa::Pwm& pwm, mraa::Gpio& dir) { pwm.write(0); dir.write(0); }
// Stops the buzzer making noise void stop_buzzing() { buzzer->write(0); }
// Starts the buzzer making noise void start_buzzing() { buzzer->write(1); }
// Stops the alarm void stopAlarm() { buzzer->write(0); }
// Starts the alarm void alarm() { buzzer->write(1); }
// Sounds the alarm void alarm() { buzzer->write(0); sleep(1); stop_alarm(); }