User Tools

Site Tools


haas:fall2023:c4eng:projects:ptb1

Corning Community College

ENGR1050 C for Engineers

PROJECT: Press The Button (PTB1)

OBJECTIVE

Revisiting our LED binary counter (with expanded capacity), this time with buttons to control the count (up/down by one), and optimizing our LED lighting logic with a loop to cut down on the individual position if statements needed.

PROCESS

Do note, the productive way to go about this project involves taking the following steps:

  • starting early
  • reading the project page
  • asking questions regarding things you do not know, are not clear on, or are confused about
  • as information, concepts, processes become clear, that is something you can contribute to the project documentation (so you can better remember)

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.

TASK

Taking our knowledge of LEDs and buttons:

  • wire up the 10 element LED bar to individual wiringPi GPIOs
  • wire up 2 buttons to individual wiringPi GPIOs
    • one button will be the increment button, increasing the value of the count by 1
    • one button will be the decrement button, decreasing the value of the count by 1
  • enhance your counting/LED logic from stl1 to incorporate 10 LEDs (up from 4)
  • optimize your counting/LED logic to utilize a loop to cut down the needed if statements from N to 1 (where N is the number of bits/LEDs)

GRABIT

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

EDIT

You will want to go here to edit and fill in the various sections of the document:

PTB1

GRABIT

After you've made a directory for ptb1 on lab46, you can use the grabit command to acquire the source code that we'll be modifying in this project, like so:

grabit c4eng ptb1

This will populate the ptb1 directory with all source files that you'll need for this project.

It's important to note, that while you'll be grabbing the source files via lab46, the required dependencies will not be available there and you will have to retrieve these files from your pi.

You can push these source files from your repository using the following set of commands:

hg add * 
hg commit -m "YOUR COMMIT MESSAGE HERE" 
hg push 

Assuming you've encountered no errors, you should now be able to retrieve these files on your pi:

hg pull 
hg update

PARTS

LED bar

The LED bar is a rather simplified version of putting 10 LEDs on your breadboard. The LED bar contains 10 different LEDs that require their own GPIO pins and resistors. Each gpio pin needs to be set to output mode. You can connect your resistors from one leg of the LED directly to the “-” column on the side of the bread-board to save some space. If your LED bar is not working, you can try flipping it around because the direction of the flow matters, just like regular LEDs.

button

each button should be wired the same way, just to different pins. each button needs a 3.3v ran through a 10Kohm resistor and a ground wire, with a final wire with a 10kohm resistor to a gpio pin. Within wiringpi, the pin must be set to input mode. The gpio wire should also be on the opposite side of the 3.3v wire and the ground wire. You made need to switch which pin your wires are connected to if your button is not working properly. You can also check if the button is working by looking at the gpio readall table before and after the button is being pressed, and you should see a change in voltage for that gpio pin (reminder to change voltage first gpio mode “pin” out, then gpio write “pin” 1).

LOGIC

Synopsis: To achieve our desired outcome with only one if statement, we'll need to implement bit shifting and a for loop. It would also be helpful, first, to create an array if our pins are not connected sequentially.

ARRAYS IN C

To declare an array in C is similar to declaring any variable: we declare the data type (in arrays, the data type of all the elements), name the variable, and assign a value (or a matrix of values for arrays).

 
int myArray[10] = {5,2,22,6,...}; 

In our sample, 10 is the number of elements we have (not shown).

 

STRATEGY

The general flow of the process (one way of going about it, anyway) can be described as follows:

SET COUNT TO ZERO
REPEAT INFINITELY:
    SHOULD THE INCREMENT BUTTON BE PRESSED:
        INCREMENT COUNT BY ONE
    
    SHOULD THE DECREMENT BUTTON BE PRESSED:
        DECREMENT COUNT BY ONE

    BIT POSITION IS ONE
    LED OFFSET IS ZERO
    REPEAT AS LONG AS LED OFFSET IS LESS THAN TEN:
        SHOULD THE CURRENT BIT POSITION HAVE A ONE:
            ACTIVATE THE LED AT CURRENT OFFSET
        OTHERWISE:
            DEACTIVATE THE LED AT CURRENT OFFSET

        LEFT SHIFT BIT POSITION BY ONE
        LED OFFSET IS INCREMENTED BY ONE
    COMMENT: INNER REPEAT CONCLUDES
    
    DELAY AT LEAST FIFTY MILLISECONDS

COMMENT: INFINITE REPEAT BLOCK CONCLUDES

SUBMISSION

To be successful in this project, the following criteria (or their equivalent) must be met:

  • Project must be submit on time, by the deadline.
    • Late submissions will lose 33% credit per day, with the submission window closing on the 3rd day following the deadline.
  • All code must compile cleanly (no warnings or errors)
    • Compile with the -Wall and –std=gnu18 compiler flags
    • all requested functionality must conform to stated requirements (either on this document or in a comment banner in source code files themselves).
  • Executed programs must display in a manner similar to provided output
    • output formatted, where applicable, must match that of project requirements
  • Processing must be correct based on input given and output requested
  • Output, if applicable, must be correct based on values input
  • Code must be nicely and consistently indented
  • Code must be consistently written, to strive for readability from having a consistent style throughout
  • Code must be commented
    • Any “to be implemented” comments MUST be removed
      • these “to be implemented” comments, if still present at evaluation time, will result in points being deducted.
      • Sufficient comments explaining the point of provided logic MUST be present
  • No global variables (without instructor approval), no goto statements, no calling of main()!
  • Track/version the source code in your lab46 semester repository
  • Submit a copy of your source code to me using the submit tool (make submit on lab46 will do this) by the deadline.

Submit Tool Usage

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.

RUBRIC

I'll be evaluating the project based on the following criteria:

52:ptb1:final tally of results (52/52)
*:ptb1:used grabit to obtain project by the Sunday prior to duedate [5/5]
*:ptb1:clean compile, no compiler messages [5/5]
*:ptb1:each button hooked to unique GPIOs [5/5]
*:ptb1:button state is read, on press code adjusts count [6/6]
*:ptb1:binary value of the count correctly displayed on LED bar [6/6]
*:ptb1:LED display logic optimized with a loop containing one if [20/20]
*:ptb1:code tracked in lab46 semester repo [5/5]

Pertaining to the collaborative authoring of project documentation

  • each class member is to participate in the contribution of relevant information and formatting of the documentation
    • minimal member contributions consist of:
      • near the class average edits (a value of at least four productive edits)
      • near the average class content change average (a value of at least 256 bytes (absolute value of data content change))
      • near the class content contribution average (a value of at least 1kiB)
      • no adding in one commit then later removing in its entirety for the sake of satisfying edit requirements
    • adding and formatting data in an organized fashion, aiming to create an informative and readable document that anyone in the class can reference
    • content contributions will be factored into a documentation coefficient, a value multiplied against your actual project submission to influence the end result:
      • no contributions, co-efficient is 0.50
      • less than minimum contributions is 0.75
      • met minimum contribution threshold is 1.00

Additionally

  • Solutions not abiding by spirit of project will be subject to a 50% overall deduction
  • Solutions not utilizing descriptive why and how comments will be subject to a 25% overall deduction
  • 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
  • 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
haas/fall2023/c4eng/projects/ptb1.txt · Last modified: 2023/09/26 10:03 by wedge