I have tried all the available values for the attenuation, nothing worked out. The Joystick takes 5V. However, I have tested it, and it also gives 5V from the analog output pin. About the resolution of the ADC, even if I did not use the appropriate value, at least it will give some value, not '-1'. This is the code:
Code: Select all
#include <esp_event.h>
#include <driver/gpio.h>
#include <driver/adc.h>
#include <stdio.h>
#define JS1_X 34
#define JS1_Y 35
#define JS1_BT 32
#define JS2_X 27
#define JS2_Y 26
#define JS2_BT 25
typedef struct {
short x : 10;
short y : 10;
} Point2D;
void app_main() {
if (adc1_config_width(ADC_WIDTH_10Bit) != 0) printf("An error has occured!");
if (adc1_config_channel_atten(ADC1_GPIO34_CHANNEL, 4) != 0) printf("An error has occured!");
if (adc1_config_channel_atten(ADC1_GPIO35_CHANNEL, 4) != 0) printf("An error has occured!");
gpio_set_direction(JS1_BT, GPIO_MODE_INPUT);
gpio_set_pull_mode(JS1_BT, GPIO_PULLDOWN_ENABLE);
Point2D lastPoint;
while (true) {
if (gpio_get_level(JS1_BT) == 1) printf("The button is pressed!\n");
lastPoint.x = adc1_get_raw(ADC1_GPIO34_CHANNEL);
lastPoint.y = adc1_get_raw(ADC1_GPIO35_CHANNEL);
printf("(%d, %d)\n", lastPoint.x, lastPoint.y);
vTaskDelay(50 / portTICK_PERIOD_MS);
}
}