Simplest way to get readings from a button ?
Posted: Fri May 14, 2021 7:23 pm
by DutchOrange
Good day, This is a very basic question but...
I need to get either a 1 or 0 from 3 buttons but I haven't found an easy / simple way to do it. Most clash with the wifi / bl. Any ideas of what should be used for this ?
Thanks
Re: Simplest way to get readings from a button ?
Posted: Sat May 15, 2021 12:28 am
by tommeyers
(1)Please post the pin numbers and (2) the circuit.
(3) How will you handle bounce?
(4)Maybe a code snip too
Tom
Re: Simplest way to get readings from a button ?
Posted: Sat May 15, 2021 1:22 pm
by DutchOrange
Here is my code:
Code: Select all
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include "freertos/FreeRTOS.h"
#include "freertos/task.h"
#include "freertos/queue.h"
#include "driver/gpio.h"
#include <driver/adc.h>
#include "esp_adc_cal.h"
void app_main(){
while(1){
uint32_t reading = adc1_get_raw(ADC1_CHANNEL_5);
printf("\n reading = %d ",reading);
vTaskDelay(250 / portTICK_PERIOD_MS);
}}
And here is how I got it conected:
https://cdn-learn.adafruit.com/assets/a ... 1472798079
Re: Simplest way to get readings from a button ?
Posted: Sat May 15, 2021 2:57 pm
by tommeyers
https://learn.adafruit.com/micropython- ... tal-inputs
1) i recommend a pull-up on that pin or enable internal pullup: that way it is high or low
2) you will experience bounce and i think you will need to debounce the value
Take a look at what adafruit has written for more.
That pin is not involved with wifi but others are see:
https://docs.espressif.com/projects/esp ... s/adc.html
Tom