add digital in doc

This commit is contained in:
2024-11-28 18:41:21 +05:30
parent 61dcb7ac2c
commit 803d377608

26
1_Basic_GPIO/digitalIn.md Normal file
View File

@@ -0,0 +1,26 @@
## Read Button
This example uses `gpio_get` api call to read and return the logic level of a gpio pin. A button is used to control the logic level of the pin. The connections are made as below. An additional concept called pulling is used to properly switch between high and low.
```c
int buttonPin = 15;
int ledPin = 14;
gpio_init(buttonPin);
gpio_init(ledPin);
gpio_set_dir(buttonPin, GPIO_IN);
gpio_pull_down(buttonPin);
gpio_set_dir(ledPin, GPIO_OUT);
while (true){
gpio_put(ledPin, gpio_get(buttonPin));
sleep_ms(10);
}
```
The usual `gpio_init` and `gpio_set_dir` are used to initialize and set the direction of the pins. Here, the pin which connects to the button gets set as input using `GPIO_IN`. The button is also configured in pull down configuration. [This guide](https://eepower.com/resistor-guide/resistor-applications/pull-up-resistor-pull-down-resistor) explains the use of pull up and pull down resistors.
- insert gif of controlling led with button
The same code can be used for controlling the fan from earlier experiment. LED connected to the `ledPin` is replaced with connection to the gate pin of the mosfet.
- insert gif of controlling fan with button