#define BUZZZER_PIN A2
void setup() {
// put your setup code here, to run once:
Serial.begin(115200);
Serial.println("Hello, STM32!");
pinMode(A2, OUTPUT);
}
void loop() {
// put your main code here, to run repeatedly:
if(Serial.available()){
char c= Serial.read();
if(c == 'b'){
Serial.println("Buzzer đang kêu");
tone(A2, 1000);
delay(2200);
noTone(A2);
Serial.println("Buzzer dừng lại");
}
else if(c != '\n' && c != '\r'){
Serial.print("Lỗi: không hiểu ký tự ");
Serial.println();
}
}
}Loading
st-nucleo-l031k6
st-nucleo-l031k6