Corning Community College
ENGR1050 C for Engineers
We continue our explorations of the electronics kit, this time by encountering our first interactions with input devices, in the form of the button.
Do note, the productive way to go about this project involves taking the following steps:
If you start too late, and do not ask questions, and do not have enough time and don't know what is going on, you are not doing the project correctly.
After exploring, assembling, and testing the intended circuit (1 button, 1 LED- each independently connected to the pi via separate GPIO pins), adapt the provided C code to provide software control to coordinate button presses with LED.
To assist with consistency across all implementations, data files for use with this project are available on lab46 via the grabit tool. Be sure to obtain it and ensure your implementation properly works with the provided data.
lab46:~/src/SEMESTER/DESIG$ grabit DESIG PROJECT
You will want to go here to edit and fill in the various sections of the document:
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.
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.
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.
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.
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.”
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.
The general core idea of the process (one way of going about it, anyway) can be described as follows:
REPEAT: SHOULD THE BUTTON BE PRESSED: ACTIVATE THE LED -> SENSORY ORGANS SENSE PERTINENT ELECTROMAGNETIC RADIATION OTHERWISE: DEACTIVATE THE LED -> SENSORY ORGANS NO LONGER SENSE ELECTROMAGNETIC RADIATION DELAY AT LEAST FIFTY MILLISECONDS
To be successful in this project, the following criteria (or their equivalent) must be met:
Let's say you have completed work on the project, and are ready to submit, you would do the following (assuming you have a program called uom0.c):
lab46:~/src/SEMESTER/DESIG/PROJECT$ make submit
You should get some sort of confirmation indicating successful submission if all went according to plan. If not, check for typos and or locational mismatches.
I'll be evaluating the project based on the following criteria:
104:ptb0:final tally of results (104/104) *:ptb0:used grabit to obtain project by the Sunday prior to duedate [13/13] *:ptb0:clean compile, no compiler messages [13/13] *:ptb0:LED and button each hooked to unique GPIOs [13/13] *:ptb0:LED only lights up on activation [26/26] *:ptb0:button state is read, on button press code activates LED [26/26] *:ptb0:code tracked in lab46 semester repo [13/13]