 const int RAIN_THRESHOLD = 700;
 const int SENSOR_PIN = A0;
 const int BUZZER_PIN = 2;
-  
+
 const int SILENCE_COMMAND = 1;
 
 enum mode {SOUND_ON, SOUND_OFF};

  if (Serial.available()) {
    if (Serial.read() == SILENCE_COMMAND) {
      deviceMode = SOUND_OFF;
    } 
  }

  int sensorReading = analogRead(SENSOR_PIN);
  Serial.println(sensorReading);

  if (sensorReading < RAIN_THRESHOLD) {
    if (deviceMode != SOUND_OFF) {
      //Serial.println("I'm singing in the rain");
      buzzerSound();
    }   
  }
  else {
    deviceMode = SOUND_ON;
  }

  delay(1000*20); // delay between reads = 1 minute
}

void buzzerSound() {

    delay(pauseBetweenNotes);
  }
}

/*
Message format:
5 bytes
1 - beginning of the message
2 - isRaining
3 - buzzerMode
4,5 - sensorReading
*/

void sendMessage(bool isRaining, int sensorReading) {
  byte message[] = {0xff, isRaining ? 1 : 0, deviceMode == SOUND_ON ? 1 : 0, lowByte(sensorReading), highByte(sensorReading)};
  Serial.write(message, 5);
}

