-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbutton.c
More file actions
36 lines (33 loc) · 712 Bytes
/
button.c
File metadata and controls
36 lines (33 loc) · 712 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
/*
* File: button.c
* Project: Klik
* -----
* This source code is released under BSD-3 license.
* Check LICENSE file for full list of conditions and disclaimer.
* -----
* Copyright 2022 - 2023 M.Kusiak (timax)
*/
#include <stdio.h>
#include "pico/stdlib.h"
#include "hardware/gpio.h"
/**
* @brief Configure a button pin.
*
* @param buttonPin button pin.
*/
void buttonSet(uint8_t buttonPin)
{
gpio_init(buttonPin);
gpio_set_dir(buttonPin, GPIO_IN);
gpio_pull_down(buttonPin);
}
/**
* @brief check if button is pressed.
*
* @param buttonPin button pin.
* @return true - when button pressed, else false.
*/
bool buttonReadState(uint8_t buttonPin)
{
return gpio_get(buttonPin);
}