«   2025/07   »
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 31
Archives
관리 메뉴

printf("ho_tari\n");

09_Tone 본문

Arduino

09_Tone

호타리 2023. 9. 2. 12:36
const int BUZZER = 10;

const int note[9] = {-1, 262, 294, 330, 349, 393, 440, 494, 523};

void setup() {
  // put your setup code here, to run once:
  Serial.begin(115200);
}

void loop() {
  // put your main code here, to run repeatedly:
  if(Serial.available())
  {
    char userInput = Serial.read();
    if('1' <= userInput && userInput <= '8')
    {
      int num = userInput - '0';

      tone(BUZZER, note[num]);
      delay(500);
    }
  }

  noTone(BUZZER);

}

'Arduino' 카테고리의 다른 글

11_Timer1_LED  (0) 2023.09.02
10_Ultrasonic  (0) 2023.09.02
08_Joystick  (0) 2023.09.02
07_Analog_Read  (0) 2023.09.02
06_Switch_Input_Interrupt  (0) 2023.09.02