Advertisement
Guest User

Untitled

a guest
Mar 22nd, 2019
76
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 0.71 KB | None | 0 0
  1. const int buzzerPin = 2;
  2.  
  3. const int defaultDelay = 250;
  4.  
  5. int currentDelay = defaultDelay;
  6.  
  7. void setup () {
  8.   Serial.begin(115200);
  9.   pinMode(buzzerPin, OUTPUT);
  10. }
  11.  
  12. void loop () {
  13.   digitalWrite(buzzerPin, LOW);
  14.   delay(currentDelay);
  15.   digitalWrite(buzzerPin, HIGH);
  16.   Serial.println(currentDelay);
  17.   delay(currentDelay);
  18.  
  19.   if (currentDelay == 0){  // Si es igual a cero, ha acabado y por lo tanto "explota"
  20.     currentDelay = defaultDelay;
  21.     Serial.println("Explota");
  22.     digitalWrite(buzzerPin, HIGH);
  23.     delay(1000);
  24.     digitalWrite(buzzerPin, LOW);
  25.     delay(2500);
  26.     Serial.println("\nReinicia");  // El \n sirve para que deje una linea en blanco
  27.   } else {
  28.     currentDelay -= 5;
  29.   }
  30. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement