Skip to main content

Subsection 1.4.4 Part 4: Lab 1, Three-LED Experiments

In Lab 1 you extend the single-LED Blinky to a three-LED circuit (Figure 1.4.10). Wire three LEDs through 220 Ω resistors to three separate GPIO output pins. In each sub-task you are asked to write a separate C file implementing a different blinking pattern.
Figure 1.4.10. Three-LED circuit for Lab 1. Each LED has its own 220 Ω resistor and connects to a separate GPIO output pin. Build incrementally: get the first LED blinking before adding the second, and the second before adding the third.
Start in a new project: copy your TemplateProject (Section D.5) and name the copy Lab1. We have put template.c on Canvas and in the book’s starter files (Appendix E): download it, place it in the project’s Src folder, and rename it to your first target filename. The template includes a header comment block. Fill in your name, assignment, a table of I/O pins and what they connect to, and a revision history for every file you submit.
Build and test incrementally: get one LED working before adding the second and third. Use descriptive #define names for every pin and timing constant, and keep track of your changes in comments.

Activity Activity

1. blinkySIM.c: Simultaneous Blink.

Write blinkySIM.c: all three LEDs blink on and off simultaneously at the same rate. All three should turn on together, pause, turn off together, pause, and repeat.
Hint: if two LEDs are on the same GPIO port, you can set (or clear) both bits with a single OR (or AND) operation rather than two separate register writes.

2. blinkySEQ.c: Sequential Blink.

Once blinkySIM.c is working, copy it to blinkySEQ.c. Modify the on/off logic so the three LEDs blink in sequence: only one lit at a time, cycling LED 1 → LED 2 → LED 3 → LED 1 → … continuously.

3. blinkyCNT.c: Binary Counter.

Write blinkyCNT.c: the three LEDs display a 3-bit binary count, cycling through 000, 001, 010, 011, 100, 101, 110, 111, 000, … with a short pause between each step. Designate which LED represents the least significant bit and which the most.
Hint: a loop variable incrementing from 0 to 7 can be used to drive the three LEDs. Use bit-twiddling expressions to extract each bit of the counter and map it to the appropriate GPIO pin.

Aside: AI Policy for ENGS 28.