Buzzer tests

This commit is contained in:
2025-12-04 19:30:17 +01:00
parent 74991a9107
commit 53b456f856
2 changed files with 35 additions and 5 deletions

View File

@@ -17,7 +17,7 @@
#define KEY_DST GPIO_NUM_17 // D8
// Buzzer
#define BUZZER GPIO_NUM_0 // ! B1 <-> LED green
#define BUZZER GPIO_NUM_43 // TX
#define LEDC_CHANNEL 0
#define LEDC_TIMER_8_BIT 8
#define LEDC_BASE_FREQ 5000

View File

@@ -287,17 +287,15 @@ void setup() {
digitalWrite(LED_USER, LOW);
// Buzzer
/*
ledcSetup(LEDC_CHANNEL, LEDC_BASE_FREQ, LEDC_TIMER_8_BIT);
ledcAttachPin(BUZZER, LEDC_CHANNEL);
// Test tone while booting
if (ledcWriteTone(BUZZER, 4000) == 0) {
if (ledcWriteTone(LEDC_CHANNEL, 4000) == 0) {
Serial.println("Error setting buzzer tone");
} else {
delay(750);
ledcWriteTone(BUZZER, 0); // Buzzer off
ledcWriteTone(LEDC_CHANNEL, 0); // Buzzer off
}
*/
// Startup sequence: test all led and short beep buzzer
@@ -374,6 +372,25 @@ void setup() {
}
void atariKeyclick() {
/*
* Anderer 12V-fähiger Buzzer!
*
Buzzer + → 12V
Buzzer → IRLZ44N Drain
IRLZ44N Source → GND
ESP32 GPIO43 → 1kΩ resistor → Gate
ESP32 GND must be connected to the same GND as the 12V supply.
* */
ledcWriteTone(LEDC_CHANNEL, 3200);
delayMicroseconds(3000);
ledcWriteTone(LEDC_CHANNEL, 0);
delayMicroseconds(800);
ledcWriteTone(LEDC_CHANNEL, 3200);
delayMicroseconds(2000);
ledcWriteTone(LEDC_CHANNEL, 0);
}
void loop() {
// Button pressed? (active low)
@@ -415,6 +432,9 @@ void loop() {
if (digitalRead(KEY_4) == LOW) {
Serial.println("Button detected: 4");
button += 8;
atariKeyclick();
digitalWrite(LED_USER, HIGH); // Turn LED on
delay(500); // Keep it on 0.5s
digitalWrite(LED_USER, LOW); // Turn LED off
@@ -422,6 +442,11 @@ void loop() {
if (digitalRead(KEY_5) == LOW) {
Serial.println("Button detected: 5");
button += 16;
ledcWriteTone(LEDC_CHANNEL, 3200);
delay(8);
ledcWriteTone(LEDC_CHANNEL, 0);
digitalWrite(LED_USER, HIGH); // Turn LED on
delay(500); // Keep it on 0.5s
digitalWrite(LED_USER, LOW); // Turn LED off
@@ -429,6 +454,11 @@ void loop() {
if (digitalRead(KEY_6) == LOW) {
Serial.println("Button detected: 6");
button += 32;
ledcWriteTone(LEDC_CHANNEL, 3200);
delay(8);
ledcWriteTone(LEDC_CHANNEL, 0);
digitalWrite(LED_USER, HIGH); // Turn LED on
delay(500); // Keep it on 0.5s
digitalWrite(LED_USER, LOW); // Turn LED off