View difference between Paste ID: GuzRbaM8 and CHfvjyT5
SHOW: | | - or go back to the newest paste.
1
#include "driver/gpio.h"
2
#include "button.h"
3
4
#define GPIO_BUTTON GPIO_NUM_1
5
6
void button_init(void)
7
{
8
	gpio_config_t io_config ={};
9
	io_config.pin_bit_mask= 1ULL << GPIO_BUTTON;
10
	io_config.mode = GPIO_MODE_INPUT;
11
	io_config.pull_up_en = GPIO_PULLUP_ENABLED;
12
	io_config.pulldown_en = GPIO_PULLDOWN_DISABLE;
13
	io_config.intr_type = GPIO_INTR_DISABLE;
14
	gpio_config(&io_conf);
15
}
16
17
button_state_t button_get(void)
18
{
19
	uint8_t pin_level;
20
	button_state_t state;
21-
	if(pin_level ==1)
21+
22
	pin_level = gpio_get_level(GPIO_BUTTON);
23-
		button_state_t state = BUTTON_PRESSED;
23+
	if (pin_level == 1)
24-
		return state;
24+
25
		state = BUTTON_PRESSED;
26-
		button_state_t state = BUTTON_RELEASED;
26+
27-
		return state;
27+
	else
28
	{
29
		state = BUTTON_RELEASED;
30
	}
31
	return state;
32
}