Paso 2: Construcción del protector de la vida
Copiar después de este--->
#define TILT_SWITCH_PIN A0
#define BUZZER_PIN 10
#define MAX 100
int tiltValue = 0;
int previousTiltValue = 0;
int valueThreshold = 5;
int timeThreshold = 2;
int hora = 0;
void setup()
{
pinMode (BUZZER_PIN, salida);
}
void loop()
{
tiltValue = analogRead(TILT_SWITCH_PIN);
Si (abs (tiltValue - previousTiltValue) > = valueThreshold)
{
tiempo = tiempo + 1;
}
otra cosa
{
RESET();
}
Si (tiempo > = timeThreshold)
{
analogWrite (BUZZER_PIN, MAX);
Delay(500);
RESET();
}
previousTiltValue = tiltValue;
Delay(500);
}
reset() vacío
{
tiempo = 0;
previousTiltValue = 0;
analogWrite (BUZZER_PIN, 0);
}