Simplest way to get readings from a button ?

DutchOrange
Posts: 74
Joined: Fri Dec 04, 2020 4:23 pm

Simplest way to get readings from a button ?

Postby DutchOrange » Fri May 14, 2021 7:23 pm

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

tommeyers
Posts: 184
Joined: Tue Apr 17, 2018 1:51 pm
Location: Santiago, Dominican Republic

Re: Simplest way to get readings from a button ?

Postby tommeyers » Sat May 15, 2021 12:28 am

(1)Please post the pin numbers and (2) the circuit.

(3) How will you handle bounce?

(4)Maybe a code snip too

Tom
IT Professional, Maker
Santiago, Dominican Republic

DutchOrange
Posts: 74
Joined: Fri Dec 04, 2020 4:23 pm

Re: Simplest way to get readings from a button ?

Postby DutchOrange » Sat May 15, 2021 1:22 pm

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

tommeyers
Posts: 184
Joined: Tue Apr 17, 2018 1:51 pm
Location: Santiago, Dominican Republic

Re: Simplest way to get readings from a button ?

Postby tommeyers » Sat May 15, 2021 2:57 pm

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
IT Professional, Maker
Santiago, Dominican Republic

Who is online

Users browsing this forum: No registered users and 243 guests