User Tools

Site Tools


notes:c4eng:fall2024:projects:ptb0

PTB0

LED

GPIO MODE SETTING

In order to allow for the LED that is connected to the circuit to be turned on and off through the code of the program we need to change the mode of the pin that the LED is connected through, to output. We do this through the line of code “pinMode (LED, OUTPUT);”. The “LED” factor in the parentheses is simply whatever variable name you assigned to the LED pin when you initialized it.

GPIO COMMAND-LINE TESTING

wiringPi: digitalWrite()

The digitalWrite() command is used to run power to a desired gpio pin. If the pin is in OUTPUT mode and you have a desired gpio pin set to some name (in this example, LED_PIN), then typing the command

digitalWrite(LED_PIN, HIGH);

will send voltage to that pin to power whatever is hooked up to it. If there is an LED light, then the command will cause the LED to illuminate. The command can also be used to shot off a pin in output mode. By typing

digitalWrite(LED_PIN, LOW);

The voltage to the pin will be interrupted, and the LED light will shut off.

pico: gpio_put()

The gpio_put() function is a command given to the computer relating to the input of a statement. The “gpio” corresponds to the gp-pin of the pico designated for the code to run through, with “put” being the command that tells the computer that a code is to be “put” into the command. An example is the wiring of an LED; the LED will only be lit up with the gpio_put () function if its “power” wiring is correctly placed in the denoted gp-pin.

BUTTON

GPIO MODE SETTING

In order to allow for the button that is connected to the circuit to be used as an actual input for the code and to power the light through the code of the program for ptb0 we need to ensure that the mode of the pin the button is connected to is set to input. We do this through the line of code “pinMode (button, OUTPUT);”. The “button” factor in the parentheses is simply whatever variable name you assigned to the button pin when you initialized it.

VERIFYING CORRECT CIRCUIT CONNECTION

wiringPi: digitalRead()

While digitalWrite() will send voltage to a gpio pin in “output” mode in order to power a component such as an LED light, the digitalRead() function will read the digital state of a gpio pin in “input” mode. The function will return “HIGH,” “True,” or “1” if there is an input. If there is no iutput, the function will return “LOW,” “False,” or “0.”

pico: gpio_get()

The gpio_get() function is a command given to the computer relating to the output of a statement and is the opposite of the gpio_put() function. The “gpio” corresponds to the gp-pin of the pico designated for the code to run through, with “get” being the command that tells the computer that a code is to be “pulled” from the command. The code the computer needs to “get” must be the same code given to the computer in the corresponding gpio_put () function written in the same command box. An example is the use of a button to light up an LED; the LED is given a designated gp-pin to be wired to, but the gpio_get () function can tell the computer that the LED should only be lit it if the wired button is pushed down, and turned off when the button is released.

notes/c4eng/fall2024/projects/ptb0.txt · Last modified: 2024/10/12 19:43 by skephart