Advertisement
nRikee

Buzzer 3 pins example

Nov 22nd, 2013
132
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 0.68 KB | None | 0 0
  1. const int buzzerPin =  3;   // Número del pin donde está el buzzer       
  2. long tono1 = 150;       // Tono 1
  3. long tono2 = 250;       // Tono 2
  4. long b = 0;
  5.  
  6. // Se ejecuta al principio, prepara el programa
  7. void setup() {
  8.   pinMode(buzzerPin, OUTPUT);      // Marca el buzzerPin como pin de salida.
  9. }
  10.  
  11. // Este método se ejecuta en bucle
  12. void loop()
  13. {
  14.   if (b){               // Si b es 1:
  15.     tone( buzzerPin, tono1, 250 );  // enmite el tono 1 durante 0.25 segundos
  16.     b = 0;              // haz que b valga 0
  17.   }
  18.   else {                // Si no es 1:
  19.     tone( buzzerPin, tono2, 250 );  // enmite el tono 2 durante 0.25 segundos
  20.     b = 1;              // haz que b valga 1
  21.   }
  22.   delay(100);               // Para el programa 0.1 segundos
  23. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement