Table of Contents

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:

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:

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

Log into your student account and proceed to the c4eng file: Enter your username and password

“cd” into c4eng with the command:

user@lab46:~$ cd src/fall2024/c4eng

type grabit, followed by c4eng ptb1 to pull the project from the server:

user@lab46:~/src/fall2024/c4eng$ grabit c4eng ptb1

Enter into the ptb1 file. If you're using a raspberry pi, enter into the wiring_pi file. If you're using a pico, enter into the pi_pico file. Access the ptb1.c file and alter accordingly.

REPO STEPS

PARTS

LED bar

The raspberry pi electronics kits came with small, lego-sized, rectangular prism-shaped bars containing 10 independent LED lights. These LED lights are not connected in series or parallel, and each light must be individually wired in order to properly function. The LEDs appear to be red, and the entire bar fits nicely right on the raspberry pi breadboard and occupies 10 adjacent rows. In stl2, we used these bars to create 8 or 10-bit binary counters. In this project, we are using these same bars to create another binary counter, but now we are adding buttons to reverse the order of the lights and begin counting down from the highest number possible.

button

similar to how we used the buttons in ptb0, we will need to find 2 buttons in our electronics kit which look like little squares with 4 small legs from each corner. To allow for the button to output and give a reading we need to physically hook the button up correctly. You do this by hooking one leg of the button to a direct line to ground. Then, another leg to 3.3v power through a 10 kΩ resistor and a final leg to a gpio pin through another 10 kΩ resistor. Once you have connected this button correctly you can then initialize it to a wpi pin value in the code before using the button. You will need to repeat these steps with another button as for ptb1 you will need 2 seperate buttons one for increasing count and on for decreasing count.

LOGIC

ARRAYS IN C

a data structure that allows you store multiple elements of the same data type in the same memory location. Arrays can contain many different date types and even other date structures. Once an array is initialized, it's size cannot be changed. However, you can change date elements at specific points in the array.

   int numbers[5] = {1, 2, 3, 4, 5};  //declares and creates an array that contains 5 integers 1,2,3,4,5
   int thirdNumber = numbers[3];  //access 3rd data element in the array, which would be 3 in this case.  
 

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:

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:

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

Pertaining to the collaborative authoring of project documentation

Additionally