abcb1403f8436eba9f2541b459715489161d7c22
haas/fall2026/c4eng/projects/images/ptb0_circuit.jpg
| ... | ... | Binary files /dev/null and b/haas/fall2026/c4eng/projects/images/ptb0_circuit.jpg differ |
haas/fall2026/c4eng/projects/ptb0.md
| ... | ... | @@ -0,0 +1,223 @@ |
| 1 | +# ENGR1050 C for Engineers |
|
| 2 | + |
|
| 3 | +# PROJECT: Press The Button (PTB0) |
|
| 4 | + |
|
| 5 | +## OBJECTIVE |
|
| 6 | + |
|
| 7 | +Revisiting our LED binary counter (with expanded capacity) from stl2, |
|
| 8 | +this time with buttons to control the count (up/down by one). |
|
| 9 | + |
|
| 10 | +## PROCESS |
|
| 11 | + |
|
| 12 | +Do note, the productive way to go about this project involves taking the |
|
| 13 | +following steps: |
|
| 14 | + |
|
| 15 | + * starting early |
|
| 16 | + * reading the project page |
|
| 17 | + * asking questions regarding things you do not know, are not clear on, |
|
| 18 | + or are confused about |
|
| 19 | + * as information, concepts, processes become clear, that is something |
|
| 20 | + you can contribute to the project documentation (so you can better |
|
| 21 | + remember) |
|
| 22 | + |
|
| 23 | +If you start too late, and do not ask questions, and do not have enough |
|
| 24 | +time and don't know what is going on, you are not doing the project |
|
| 25 | +correctly. |
|
| 26 | + |
|
| 27 | +## OBTAIN THE PROJECT FILES |
|
| 28 | + |
|
| 29 | +To assist with consistency across all implementations, data files for use |
|
| 30 | +with this project are available on lab46 as a `grabit` Please copy the |
|
| 31 | +data to your private semester repository under an appropriate project |
|
| 32 | +directory to begin work. |
|
| 33 | + |
|
| 34 | +The project should be obtained by the **Sunday prior to the due date**. |
|
| 35 | + |
|
| 36 | +``` |
|
| 37 | +lab46:~/SEMESTER/c4eng$ grabit c4eng ptb0 |
|
| 38 | +``` |
|
| 39 | + |
|
| 40 | +Please study any provided code or supporting documents, and look up, |
|
| 41 | +experiment, and ask questions on aspects that you do not understand. |
|
| 42 | + |
|
| 43 | +## OPERATING THE PROJECT |
|
| 44 | + |
|
| 45 | +These projects will have two paths to them, depending on which device you |
|
| 46 | +are using: |
|
| 47 | + |
|
| 48 | + * Raspberry Pi single board computer (4/5) using the `wiringPi` library |
|
| 49 | + * Raspberry Pi Pico microcontroller |
|
| 50 | + |
|
| 51 | +``` |
|
| 52 | +lab46:~/SEMESTER/c4eng/ptb0$ make |
|
| 53 | +Please select which development environment: |
|
| 54 | + |
|
| 55 | + make wiringpi - using the Raspberry Pi with wiringpi library |
|
| 56 | + make pico - using the Raspberry Pi pico |
|
| 57 | + |
|
| 58 | +after which, you can use 'make' to build |
|
| 59 | +lab46:~/SEMESTER/c4eng/ptb0$ |
|
| 60 | +``` |
|
| 61 | + |
|
| 62 | +Run the `make` command with the category representing the path you will |
|
| 63 | +be working with for this project. |
|
| 64 | + |
|
| 65 | +After which, if you do an `ls`, you will see a cyan-colored file called |
|
| 66 | +`ptb0.c`. This is the C file you will be editing for this project. |
|
| 67 | + |
|
| 68 | +Go ahead and view it, study the code, eventually make any changes, save |
|
| 69 | +and return to the command-line. |
|
| 70 | + |
|
| 71 | +To build it, you simply run: `make` |
|
| 72 | + |
|
| 73 | +If there are no errors, it will build, and you proceed from there. |
|
| 74 | + |
|
| 75 | + |
|
| 76 | +## MAINTAINING YOUR REPOSITORY |
|
| 77 | + |
|
| 78 | +Be sure to keep your repository up-to-date, regularly committing changes |
|
| 79 | +to files. |
|
| 80 | + |
|
| 81 | +As a reminder, here are the suggested steps: |
|
| 82 | + |
|
| 83 | + -1. `make clean` <-- remove all unnecessary files |
|
| 84 | + 0. `git status` <-- see the current state of things |
|
| 85 | + 1. `git pull` <-- pull down any changes from elsewhere |
|
| 86 | + 2. `git add` <-- add each new or modified file |
|
| 87 | + 2a. `git add ./` <-- try this the first time |
|
| 88 | + 3. `git commit -m "your message"` <-- make a snapshot |
|
| 89 | + 4. `git push` |
|
| 90 | + |
|
| 91 | +## TASK |
|
| 92 | + |
|
| 93 | +Taking our knowledge of LEDs and buttons: |
|
| 94 | + |
|
| 95 | + * wire up the 10 element LED bar to individual wiringPi GPIOs (have |
|
| 96 | + 8-10 usable LEDs for the count) |
|
| 97 | + * wire up 2 buttons to individual wiringPi GPIOs |
|
| 98 | + * one button will be the **increment** button, increasing the value |
|
| 99 | + of the count by 1 |
|
| 100 | + * one button will be the **decrement** button, decreasing the value |
|
| 101 | + of the count by 1 |
|
| 102 | + * unless a button is pressed, the count remains on the current value |
|
| 103 | + * when the increment button is pressed, the count proceeds to count |
|
| 104 | + up by 1 |
|
| 105 | + * when the decrement button is pressed, the count proceeds to count |
|
| 106 | + down by 1 |
|
| 107 | + |
|
| 108 | + |
|
| 109 | + |
|
| 110 | +The value of the count is to be displayed in binary on the LED bar. If |
|
| 111 | +"1" means the LED in that position is ON, and "0" means the LED in that |
|
| 112 | +position is OFF, then a count of 5 would appear as: |
|
| 113 | + |
|
| 114 | +``` |
|
| 115 | +0 0 0 0 0 0 0 1 0 1 |
|
| 116 | +``` |
|
| 117 | + |
|
| 118 | +Pressing the increment button would advance the display to: |
|
| 119 | + |
|
| 120 | +``` |
|
| 121 | +0 0 0 0 0 0 0 1 1 0 |
|
| 122 | +``` |
|
| 123 | + |
|
| 124 | +while pressing the decrement button would instead bring it back to: |
|
| 125 | + |
|
| 126 | +``` |
|
| 127 | +0 0 0 0 0 0 0 1 0 0 |
|
| 128 | +``` |
|
| 129 | + |
|
| 130 | +The LED circuits you will be constructing are the same ones we built in |
|
| 131 | +stl2: an LED circuit receiving power (from a GPIO pin), having a 220 Ohm |
|
| 132 | +resistor, an LED, and then connecting to ground, using the 10 segment LED |
|
| 133 | +bar (ten individual LEDs packaged into one component). Remember you still |
|
| 134 | +need to hook up resistors to each LED. |
|
| 135 | + |
|
| 136 | +Each LED circuit will be powered from a unique GPIO pin, allowing for |
|
| 137 | +conditional supply of power, based on our code. Likewise, each button |
|
| 138 | +will be connected to its own unique GPIO pin, which your program will |
|
| 139 | +read to determine whether that button is currently being pressed. |
|
| 140 | + |
|
| 141 | +As in stl2, you will use a **loop** where your use of **if** statements |
|
| 142 | +has been optimized so you're not writing a case for each possible state, |
|
| 143 | +but instead bit positions / place values. Consider also what should |
|
| 144 | +happen at the edges of your count (such as decrementing below zero, or |
|
| 145 | +incrementing past the largest value your LEDs can show), and document |
|
| 146 | +your decision in your comments. |
|
| 147 | + |
|
| 148 | +## EXECUTION |
|
| 149 | + |
|
| 150 | +If on the pico, follow the process for downloading the binary file and |
|
| 151 | +programming your pico. |
|
| 152 | + |
|
| 153 | +If on the full Raspberry Pi, you have a green executable you can run just |
|
| 154 | +as we've done in our other projects. |
|
| 155 | + |
|
| 156 | +## STRATEGY |
|
| 157 | + |
|
| 158 | +The general flow of the process (one way of going about it, anyway) can |
|
| 159 | +be described as follows: |
|
| 160 | + |
|
| 161 | +``` |
|
| 162 | +SET COUNT TO ZERO |
|
| 163 | +REPEAT INFINITELY: |
|
| 164 | + SHOULD THE INCREMENT BUTTON BE PRESSED: |
|
| 165 | + INCREMENT COUNT BY ONE |
|
| 166 | + |
|
| 167 | + SHOULD THE DECREMENT BUTTON BE PRESSED: |
|
| 168 | + DECREMENT COUNT BY ONE |
|
| 169 | + |
|
| 170 | + BIT POSITION IS ONE |
|
| 171 | + LED OFFSET IS ZERO |
|
| 172 | + REPEAT AS LONG AS LED OFFSET IS LESS THAN TEN: |
|
| 173 | + SHOULD THE CURRENT BIT POSITION HAVE A ONE: |
|
| 174 | + ACTIVATE THE LED AT CURRENT OFFSET |
|
| 175 | + OTHERWISE: |
|
| 176 | + DEACTIVATE THE LED AT CURRENT OFFSET |
|
| 177 | + |
|
| 178 | + LEFT SHIFT BIT POSITION BY ONE |
|
| 179 | + LED OFFSET IS INCREMENTED BY ONE |
|
| 180 | + |
|
| 181 | + DELAY AT LEAST FIFTY MILLISECONDS |
|
| 182 | + |
|
| 183 | +REPEAT BLOCK |
|
| 184 | +``` |
|
| 185 | + |
|
| 186 | +## SUBMISSION |
|
| 187 | + |
|
| 188 | +To successfully complete this project, the following criteria must be |
|
| 189 | +met: |
|
| 190 | + |
|
| 191 | + * Code must compile/execute cleanly (no notes, warnings, nor errors) |
|
| 192 | + * Code must be nicely and consistently indented |
|
| 193 | + * Code must be well commented |
|
| 194 | + * Do NOT double space your code. Group like statements together. |
|
| 195 | + * Track/version the source code in your private semester repository |
|
| 196 | + |
|
| 197 | +To submit this project to me, make sure the `Makefile` and your completed |
|
| 198 | +`ptb0.c` file are placed in your private semester repository under |
|
| 199 | +`c4eng/ptb0/` |
|
| 200 | + |
|
| 201 | +What I'll be looking for: |
|
| 202 | + |
|
| 203 | +### RUBRIC |
|
| 204 | + |
|
| 205 | +I'll be evaluating the project based on the following criteria: |
|
| 206 | + |
|
| 207 | +``` |
|
| 208 | +208:ptb0:final tally of results (208/208) |
|
| 209 | +*:ptb0:used grabit to obtain project by the Sunday prior to duedate [13/13] |
|
| 210 | +*:ptb0:clean compile, no compiler messages [13/13] |
|
| 211 | +*:ptb0:post a picture or short video to the DISCORD [26/26] |
|
| 212 | +*:ptb0:each LED hooked to a unique GPIO [26/26] |
|
| 213 | +*:ptb0:each button hooked to unique GPIOs [52/52] |
|
| 214 | +*:ptb0:button state is read, on press code adjusts count [52/52] |
|
| 215 | +*:ptb0:binary value of the count correctly displayed on LED bar [13/13] |
|
| 216 | +*:ptb0:code tracked in lab46 semester repo [13/13] |
|
| 217 | +``` |
|
| 218 | + |
|
| 219 | +Additionally: |
|
| 220 | + * Solutions not abiding by spirit of project will be subject to a 50% overall deduction |
|
| 221 | + * Solutions not utilizing descriptive why and how comments will be subject to a 25% overall deduction |
|
| 222 | + * Solutions not utilizing indentation to promote scope and clarity or otherwise maintaining consistency in code style and presentation will be subject to a 25% overall deduction |
|
| 223 | + * Solutions not organized and easy to read (assume a terminal at least 90 characters wide, 40 characters tall) are subject to a 25% overall deduction |