#include <stdio.h>
#include "freertos/FreeRTOS.h"
#include "freertos/task.h"
#include "driver/gpio.h"
const int buttonPin = 2; // Change this to the pin you are using for the button
const int dacChannel = 0; // DAC channel to use
const int toneFrequency = 1000; // Frequency of the tone (Hz)
TaskHandle_t buttonTaskHandle = NULL;
void buttonTask(void* parameter) {
while (1) {
if (digitalRead(buttonPin) == LOW) {
// Button is pressed, generate a tone
dacWrite(dacChannel, 2047); // Set DAC to a value for the desired tone
delay(100); // Adjust the duration of the tone as needed
dacWrite(dacChannel, 0); // Turn off the tone
}
vTaskDelay(10 / portTICK_PERIOD_MS); // Adjust the delay as needed
}
}
void setup() {
pinMode(buttonPin, INPUT_PULLUP); // Use INPUT_PULLUP to enable the internal pull-up resistor
// Initialize the DAC
dacWrite(dacChannel, 0); // Start with 0 output
xTaskCreate(buttonTask, "ButtonTask", 1000, NULL, 1, &buttonTaskHandle);
vTaskStartScheduler(); // Start FreeRTOS
}
void loop(){}