I'm making a device for the visually disabled that makes a sound when the water in a bowl reach certain levels.
I've already made the sensors for three levels of water and if statements to make the sound, but I need the sound to be played just once for every level change and it loops over and over. How can I make it to sound just one time?
Here is my code:
#include <PCM.h>
const unsigned char sample[] PROGMEM = { //Here goes the sample
};
int low = 0;
int mid = 0;
int high = 0;
void setup() {
// put your setup code here, to run once:
Serial.begin(9600);
}
void loop() {
// put your main code here, to run repeatedly:
low = analogRead(A0);
mid = analogRead(A1);
high = analogRead(A2);
Serial.print("nivel agua: ");
if (high > 50){
Serial.print("Alto");
startPlayback(sample, sizeof(sample));
}
else if (mid >50){
Serial.print("Medio");
startPlayback(sample, sizeof(sample));
}
else if (low > 50){
Serial.print("Bajo");
startPlayback(sample, sizeof(sample));
}
delay(100);