From 803d377608ca0920271e4c286cfc2ba36611ec5e Mon Sep 17 00:00:00 2001 From: "Phani Pavan K: iDellToast" Date: Thu, 28 Nov 2024 18:41:21 +0530 Subject: [PATCH] add digital in doc --- 1_Basic_GPIO/digitalIn.md | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) create mode 100644 1_Basic_GPIO/digitalIn.md diff --git a/1_Basic_GPIO/digitalIn.md b/1_Basic_GPIO/digitalIn.md new file mode 100644 index 0000000..d5c6492 --- /dev/null +++ b/1_Basic_GPIO/digitalIn.md @@ -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