// 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 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() {
        // buzzer connected to digital 15 aka A1
        buzzer = new mraa::Gpio(15);
        buzzer->dir(mraa::DIR_OUT);
        stop_buzzing();

        // air sensor connected to analog A2
        sensor = new upm::MQ2(2);
    };
  // Initialization function
  void init() {
    // buzzer connected to A1 (aka digital out 15)
    mraa_init();

    buzzer = new mraa::Gpio(15);
    buzzer->dir(mraa::DIR_OUT);
    stop_alarm();

    // moisture sensor on analog (A2)
    moisture = new upm::GroveMoisture(2);
  }
  // Initialization function
  void init() {
    mraa_init();

    // temperature sensor connected to A1 (analog in)
    temps = new mraa::Aio(1);

    // buzzer connected to A2 (aka digital out 16)
    buzzer = new mraa::Gpio(16);
    buzzer->dir(mraa::DIR_OUT);
    stopAlarm();

    // flame sensor on A3
    flame = new mraa::Aio(3);
  }
Пример #8
0
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();
 }