ENGR1050 C for Engineers

PROJECT: Press The Button (PTB1)

OBJECTIVE

Buttons and multi-colored LEDs, oh my!

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.

OBTAIN THE PROJECT FILES

To assist with consistency across all implementations, data files for use with this project are available on lab46 as a grabit. Please copy the data to your private semester repository under an appropriate project directory to begin work, and ensure your implementation properly works with the provided data.

The project should be obtained by the Sunday prior to the due date.

lab46:~/SEMESTER/c4eng$ grabit c4eng ptb1

Please study any provided code or supporting documents, and look up, experiment, and ask questions on aspects that you do not understand.

OPERATING THE PROJECT

These projects will have two paths to them, depending on which device you are using:

  • Raspberry Pi single board computer (4/5) using the wiringPi library
  • Raspberry Pi Pico microcontroller
lab46:~/SEMESTER/c4eng/ptb1$ make
Please select which development environment:

  make wiringpi - using the Raspberry Pi with wiringpi library
  make pico     - using the Raspberry Pi pico

after which, you can use 'make' to build
lab46:~/SEMESTER/c4eng/ptb1$ 

Run the make command with the category representing the path you will be working with for this project.

After which, if you do an ls, you will see a cyan-colored file called ptb1.c. This is the C file you will be editing for this project.

Go ahead and view it, study the code, eventually make any changes, save and return to the command-line.

To build it, you simply run: make

If there are no errors, it will build, and you proceed from there.

MAINTAINING YOUR REPOSITORY

Be sure to keep your repository up-to-date, regularly committing changes to files.

As a reminder, here are the suggested steps:

-1. make clean <– remove all unnecessary files

  1. git status <– see the current state of things
  2. git pull <– pull down any changes from elsewhere
  3. git add <– add each new or modified file 2a. git add ./ <– try this the first time
  4. git commit -m "your message" <– make a snapshot
  5. git push

TASK

Taking our knowledge of LEDs and buttons:

  • wire up the multicolored LED (3 separate GPIO pins)
    • we are going to use PWM to control this, which will give us 100 levels of adjustment
  • wire up 3 buttons to additional, individual GPIOs (one for red, one for green, one for blue)
  • wire up the rocker switch to its own unique GPIO
    • one direction will indicate positive
    • the other direction will indicate negative
  • implement logic so that, with the rocker switch in a given position, when pressing one of the color buttons, it adjusts that component of the multicolor LED in the appropriate direction (by a step of 10).
    • if a color value exceeds or dips below the allowed range, cycle it to the opposite end

Each LED color channel is powered from a unique GPIO pin, allowing for independent control of the red, green, and blue components. Likewise, each button and the rocker switch will be connected to its own unique GPIO pin, which your program will read to determine whether that button is currently being pressed, and which direction the switch is set to.

EXECUTION

If on the pico, follow the process for downloading the binary file and programming your pico.

If on the full Raspberry Pi, you have a green executable you can run just as we've done in our other projects.

STRATEGY

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

SET REDVAL, GRNVAL, BLUVAL TO ZERO
REPEAT INFINITELY:
    SHOULD THE INCREMENT POSITION ON THE SWITCH BE SET:
        SET DIRECTION TO POSITIVE ONE
    OTHERWISE:
        SET DIRECTION TO NEGATIVE ONE

    SHOULD THE RED BUTTON BE PRESSED:
        ADJUST REDVAL BY (TEN TIMES DIRECTION)

    SHOULD THE GREEN BUTTON BE PRESSED:
        ADJUST GRNVAL BY (TEN TIMES DIRECTION)

    SHOULD THE BLUE BUTTON BE PRESSED:
        ADJUST BLUVAL BY (TEN TIMES DIRECTION)

    ACTIVATE MULTICOLOR LED TO RGB VALUES CURRENTLY SET

    DELAY AT LEAST FIFTY MILLISECONDS

REPEAT BLOCK

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 in this document or in a comment banner in the 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:

lab46:~/SEMESTER/c4eng/ptb1$ 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.

What I'll be looking for:

RUBRIC

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

234:ptb1:final tally of results (234/234)
*:ptb1:used grabit to obtain project by the Sunday prior to duedate [13/13]
*:ptb1:post a screenshot or short video to the class DISCORD [13/13]
*:ptb1:each color of the multicolor LED hooked to a unique GPIO [26/26]
*:ptb1:each button and the rocker switch hooked to unique GPIOs [26/26]
*:ptb1:switch is read and adjusts color level direction [39/39]
*:ptb1:each button adjusts its pertinent color level [39/39]
*:ptb1:multicolor LED displays current set RGB levels [39/39]
*:ptb1:bounds enforcement keeping color value within range [26/26]
*:ptb1:code tracked in lab46 semester repo [13/13]

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