#define BUZZ PA1 // Buzzer Pin
#define LED PC13 // LED Pin
#define FSA PB12 // Footswitch A Pin
#define FSB PB13 // Footswitch B Pin
#define FSC PB14 // Footswitch C Pin
#define FSD PB15 // Footswitch D Pin
#define FSE PA11 // Footswitch E Pin
#define FS0 PA12 // Footswitch 0 Pin
#define EC_CLK PA8 // Encoder CLK Pin
#define EC_DT PA9 // Encoder DT Pin
// Variable & Const
const int dotDuration = 50;
const int dashDuration = dotDuration * 5;
const int beepFreq = 550;
void setup() {
// Input Pin
pinMode(FSA, INPUT_PULLUP);
pinMode(FSB, INPUT_PULLUP);
pinMode(FSC, INPUT_PULLUP);
pinMode(FSD, INPUT_PULLUP);
pinMode(FSE, INPUT_PULLUP);
pinMode(FS0, INPUT_PULLUP);
// Output Pin
pinMode(BUZZ, OUTPUT);
pinMode(LED, OUTPUT);
//Ignitions
beep(".-- . .-.. -.-. --- -- .");
}
void loop() {
if (digitalRead(FSA) == LOW) {
// Jika FSA aktif, panggil fungsi untuk melakukan beep satu kali
beep(".");
// Tambahkan penundaan untuk menghindari beberapa detik beep yang terus-menerus
delay(100);
}
}
// Custom Function
void beep(String message) {
for (int i = 0; i < message.length(); i++) {
char character = message.charAt(i);
switch (character) {
case '.':
beepDot();
break;
case '-':
beepDash();
break;
case ' ':
delay(dotDuration * 2);
break;
}
delay(dotDuration * 2);
}
}
void beepDot() {
tone(BUZZ, beepFreq, dotDuration);
digitalWrite(LED, HIGH);
delay(dotDuration * 2);
digitalWrite(LED, LOW);
noTone(BUZZ);
}
void beepDash() {
tone(BUZZ, beepFreq, dotDuration * 3);
digitalWrite(LED, HIGH);
delay(dotDuration * 2);
digitalWrite(LED, LOW);
noTone(BUZZ);
}