#include <stdio.h>
#include "freertos/FreeRTOS.h"
#include "freertos/task.h"
#include "driver/gpio.h"
#include "driver/adc.h"
#define JOYSTICK_X ADC1_CHANNEL_3 // 1. Add ADC1 channel for GPIO4 (hor)
#define JOYSTICK_Y ADC1_CHANNEL_4 // 2. Add ADC1 channel for GPIO5 (ver)
#define PUSH_BUTTON 6 // 3. Add GPIO6
void app_main() {
// 4. Configure ADC width to 12 bits
adc1_config_width(ADC_WIDTH_BIT_12);
// 5. Configure ADC channels to correct attenuation for 3.3 V
adc1_config_channel_atten(JOYSTICK_X, ADC_ATTEN_DB_11);
adc1_config_channel_atten(JOYSTICK_Y, ADC_ATTEN_DB_11);
// 6. Configure push button pin as input with pull-up
gpio_set_direction(PUSH_BUTTON, GPIO_MODE_INPUT);
gpio_set_pull_mode(PUSH_BUTTON, GPIO_PULLUP_ONLY);
// Variables to store ADC value
int analogDataX = 0;
int analogDataY = 0;
int pushButtonState = 1;
while (1) {
// 7. Read raw 12-bit value from the X-axis and Y-axis of the joystick
analogDataX = adc1_get_raw(JOYSTICK_X);
analogDataY = adc1_get_raw(JOYSTICK_Y);
// 8. Read the push button pin
pushButtonState = gpio_get_level(PUSH_BUTTON);
// 9. Print the Joystick X-axis and Y-axis readings
printf("X-axis: %d and Y-axis: %d \n", analogDataX, analogDataY);
// 10. Print the push button reading
printf("Button: %d\n", pushButtonState);
vTaskDelay(pdMS_TO_TICKS(500));
}
}