loops - Arduino_Doorbell_Muscial_Loop -


i'm building smart home project i'm having difficulty code regarding doorbell. i'm quite new using arduino i'm hoping create code musical tone play once clicks button.

#include "pitches.h"  const int buttonpin = 2;      const int buzzerpin =  3;      int buttonstate = 0;          int melody[] = {     note_c4, note_g3, note_g3, note_a3, note_g3, 0, note_b3, note_c4 };  int notedurations[] = {     4, 8, 8, 4, 4, 4, 4, 4 };  void setup() {     (int thisnote = 0; thisnote < 8; thisnote++) {          int noteduration = 1000 / notedurations[thisnote];         tone(8, melody[thisnote], noteduration);          int pausebetweennotes = noteduration * 1.30;         delay(pausebetweennotes);          notone(8);         pinmode(buzzerpin, output);          pinmode(buttonpin, input);     } }  void loop() {     buttonstate = digitalread(buttonpin);      if (buttonstate == high) {         digitalwrite(buzzerpin, high);     } else {         digitalwrite(buzzerpin, low);     } } 


Comments

Popular posts from this blog

ubuntu - PHP script to find files of certain extensions in a directory, returns populated array when run in browser, but empty array when run from terminal -

php - How can i create a user dashboard -

javascript - How to detect toggling of the fullscreen-toolbar in jQuery Mobile? -