Advertisement
makispaiktis

ArduinoBasics - 7. Buzzer, button, LED alarm

Mar 22nd, 2021 (edited)
601
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. int led = 9;
  2. int buzzer = 10;
  3. int button = 11;
  4. bool isPressed;
  5.  
  6. void setup() {
  7.   pinMode(led, OUTPUT);
  8.   pinMode(buzzer, OUTPUT);
  9.   pinMode(button, INPUT);
  10. }
  11.  
  12. void loop() {
  13.   isPressed = digitalRead(button);
  14.   if(isPressed == true){
  15.     digitalWrite(led, HIGH);
  16.     tone(buzzer, 400);
  17.     delay(200);
  18.     digitalWrite(led, LOW);
  19.     noTone(buzzer);
  20.     delay(200);
  21.   }
  22.   else{
  23.     digitalWrite(led, LOW);
  24.   }
  25. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement