Advertisement
Muzaffar79

Kombinasi Buzzer dan Button Menggunakan Arduino UNO R3

Nov 26th, 2017
187
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.81 KB | None | 0 0
  1.  #define DO 262 //DO
  2.  #define RE 294 //RE
  3.  #define MI 330 //MI
  4.  #define FA 349 //FA
  5.  #define SOL 392 //SOL
  6.  #define LA 440 //LA
  7.  #define SI 494 //SI
  8.  #define DOO 523 //DO
  9.  
  10. int buzz = 13;
  11.  
  12. int switchPin = 12;
  13.  
  14. int lastButtonState = 0;
  15.  
  16. void setup()
  17. {
  18.   Serial.begin(9600);
  19.  
  20.    pinMode(buzz, OUTPUT);  
  21.  pinMode (switchPin, INPUT);
  22. }
  23.  
  24. void loop(){
  25.  
  26.  int buttonState = digitalRead(switchPin);
  27. if (buttonState == 1)
  28. {
  29.   tone(buzz, DO, 500);
  30.   delay(1000);
  31.   tone(buzz, RE, 500);
  32.   delay(1000);
  33.   tone(buzz, MI, 500);
  34.   delay(1000);
  35.   tone(buzz, FA, 500);
  36.   delay(1000);
  37.   tone(buzz, SOL, 500);
  38.   delay(1000);
  39.   tone(buzz, LA, 500);
  40.   delay(1000);
  41.   tone(buzz, SI, 500);
  42.   delay(1000);
  43.   tone(buzz, DOO, 500);
  44.   delay(1000);
  45. }
  46.   else {
  47.   digitalWrite (buzz, LOW);
  48. }
  49.  
  50.   }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement