티스토리 뷰

int bell = 0;
//도레미파솔라시
unsigned int frqArray[7] = {262, 294, 330, 349, 392, 440, 494};

//똑같아요 동요 박자
int signatures[20] = {4, 4, 4, 4, 4, 4, 4, 4, 4, 2, 4, 4, 4, 4, 4, 4, 4, 4, 4, 2};

//똑같아요 동요 음계
int scale[20] = {0, 2, 4, 0, 2, 4, 5, 5, 5, 4, 3, 3, 3, 2, 2, 2, 1, 1, 1, 0};

void setup() {
  pinMode(2, INPUT_PULLUP);
  pinMode(11, OUTPUT);
  pinMode(12, OUTPUT);
  
  digitalWrite(11, HIGH);
}

void loop() {
  if(digitalRead(2) == LOW)  {
    bell = 0;
    noTone(12);
  }else if(digitalRead(2) == HIGH)  {
      unsigned long duration = 1000 / signatures[bell];
      tone(12, frqArray[scale[bell]], duration);
      delay(duration * 1.5);
      noTone(12);
      bell++; 
  }
}

댓글
공지사항
최근에 올라온 글
최근에 달린 댓글
Total
Today
Yesterday
TAG
more
«   2024/11   »
1 2
3 4 5 6 7 8 9
10 11 12 13 14 15 16
17 18 19 20 21 22 23
24 25 26 27 28 29 30
글 보관함