Homework 5

Instructions

Part 1: Group Work

Throughout this assignment, you may find some Raspberry Pi Pico tutorials such as https://electrocredible.com/raspberry-pi-pico-external-interrupts-button-micropython/ and https://www.hackster.io/Ramji_Patel/raspberry-pi-pico-and-button-321059 useful in configuring your supplies to complete these deliverables. Note that many of these tutorials use MicroPython, while you will be asked to code in C for this assignment.

You will be asked to DEMONSTRATE the coding portion of this in class or office hours. Demos can happen after the deadline as long as they use the code that was submitted.

Deliverable A

  1. Wire a button to a GPIO pin on your Pico.
  2. Create C code that constantly polls the button to see if it is pressed. Turn an LED (can be the onboard LED or another, as you wish) on when the button is pressed and off when it is not pressed.

Deliverable B

Modify your code from A to use an interrupt service routine. HINT: you may need to look into button debouncing. Buttons are noisy devices and often report multiple contacts for one press. Adding a short delay before checking again can fix that.

Deliverable C

Use the same circuit setup as in B. Write C code that counts the number of times the button is pressed and repeatedly blinks the LED the number of times counted. Specifically:

  • Count the number of times a button is pressed. A pause between presses of 1 second or more indicates the end of a sequence.
  • Blink the LED 100ms on, 100ms off the number of times counted.
  • Pause for approximately one second and repeat the blink sequence.
  • If the button is pressed at any time, a new count should be started.

Part 2: Individual Work

    1. What are the tradeoffs to consider when deciding to poll or use interrupts to accept input? (6 points)
    2. Describe the four ways an external interrupt can be triggered using the Pico libraries. (4 points)

Turn in to Blackboard

  • A zip file with the following code named after the deliverable it corresponds to:
    • Deliverable A
    • Deliverable B
    • Deliverable C
  • A PDF with the answers to Part 2

Rubric

Part 1 Demo

  • Deliverable A
    • 5 points
  • Deliverable B
    • 5 points
  • Deliverable C
    • 5 points: Repeatedly blinks the sequence
    • 5 points: Sequence can be interrupted at any time

Part 2: 10 points