ENGR1050 C for Engineers

PROJECT: Seeing The Light (STL2)

OBJECTIVE

Time to explore optimizing our logic further, through the use of a loop and demonstrating the effectiveness of our logic by scaling up the number of LEDs in our counter (using the 10 segment LED bar).

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, or within the class repository under the projects/ directory. Please copy the data to your project directory in your private semester repository to begin work.

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/stl2$ make
Please select which development environment:

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

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

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 stl2.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

After exploring, assembling, and testing the intended circuit (10 LEDs), adapt the provided C code to use the bank of connected LEDs to count in binary from 0000000000 to at least 1111111111 (0 to 1023).

Using the current value of count, your task is to make use of ONE if statement and copious use of bitwise logic to determine from an ongoing count the state of the individual bits.

It is your task to write a C program that interfaces successfully with the eight or more independently connected LED circuits, arranged in some orientation to ascertain an order or positioning, where your program will (in endless fashion, or until being manually interrupted) display a count (in binary) of values from 0 to 1023 (then rollover, or reset).

If "1" means the LED in that position is ON, and "0" means the LED in that position is OFF, then you want to write a program that performs the following progression (over and over again):

0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 1
0 0 0 0 0 0 0 0 1 0
0 0 0 0 0 0 0 0 1 1
0 0 0 0 0 0 0 1 0 0
0 0 0 0 0 0 0 1 0 1
0 0 0 0 0 0 0 1 1 0
0 0 0 0 0 0 0 1 1 1
0 0 0 0 0 0 1 0 0 0
. . .
1 1 1 1 1 1 1 0 0 1
1 1 1 1 1 1 1 0 1 0
1 1 1 1 1 1 1 0 1 1
1 1 1 1 1 1 1 1 0 0
1 1 1 1 1 1 1 1 0 1
1 1 1 1 1 1 1 1 1 0
1 1 1 1 1 1 1 1 1 1   <-- 1023, the maximum value to display when there are 10 bits/LEDs
0 0 0 0 0 0 0 0 0 0   <-- 0, we "roll over" and start again
0 0 0 0 0 0 0 0 0 1
0 0 0 0 0 0 0 0 1 0
. . .

The circuits you will be constructing will be the same ones we previously built in class- an LED circuit receiving power (from a GPIO pin), having a 220 Ohm resistor, an LED, and then connecting to ground. Only this time we will make use of the 10 segment LED bar. It is basically a packaging of ten individual LEDs into one component (10 pairs of legs, one pair for each LED). Remember you still need to hook uip resistors to each LED.

We will be powering each LED circuit from a unique GPIO pin, allowing for conditional supply of power, based on our code.

Unlike in stl1, where you used individual if statements to manage each value of the count, here you will only use ONE if statement to manage the state of the current LED.

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 COUNTER TO ZERO
REPEAT INFINITELY:
    SET PLACE TO ONE
    REPEAT UNTIL PLACE IS GREATER THAN TEN:
        SHOULD THE PLACE POSITION HAVE A ONE:
            ACTIVATE THE PLACE’S LED
        OTHERWISE:
            DEACTIVATE THE PLACE’S LED

        LET PLACE BECOME THE NEXT PLACE POSITION
    KEEP GOING

    PAUSE FOR HUMAN PERCEPTION
    LET THE COUNTER BE INCREMENTED BY ONE
KEEP GOING
</code>

SUBMISSION

To successfully complete this project, the following criteria must be met:

  • Code must compile/execute cleanly (no notes, warnings, nor errors)
  • Code must be nicely and consistently indented
  • Code must be well commented
  • Do NOT double space your code. Group like statements together.
  • Track/version the source code in your private semester repository

To submit this project to me, make sure the Makefile and your completed stl2.c file are placed in your private semester repository under c4eng/stl2/

What I'll be looking for:

RUBRIC

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

182:stl2:final tally of results (182/182)
*:stl2:post a picture or short video to the DISCORD [26/26]
*:stl2:code makes use of ONE if statement [26/26]
*:stl2:code makes use of a for loop [26/26]
*:stl2:code makes use of bitwise logic [26/26]
*:stl2:code structure is different than stl1 [26/26]
*:stl2:program conforms to project specifications [26/26]
*:stl2:code tracked in private semester repo [26/26]

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