Instructions

Deliverable A

  1. Wire a button up to an input on your Arduino. You may choose any digital pin that you like, but note that a pin capable of an interrupt will be required for later steps. You may find Lesson 5 in the Elegoo tutorials useful.
  2. Create 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: https://docs.arduino.cc/built-in-examples/digital/Debounce/

Deliverable C

Use the same circuit setup as in B. Write 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.

Turn in to Blackboard

  • A zip file with the following code named after the deliverable it corresponds to:
    • Deliverable A (4 points)
    • Deliverable B (4 points)
    • Deliverable C (4 points)
  • A PDF with answers to the following questions:
    1. What are the tradeoffs to consider when deciding to poll or use interrupts to accept input? (8 points)
    2. Which pins on the Arduino Mega are able to be used for interrupts? (3 points)
    3. Which port and pin number on the AVR ATMEGA2560 do each pin number on the Arduino Mega from Q2 correspond to? For example, the documentation (linked in slides), states that Digital Pin 0 on the Arduino corresponds to Port E Pin 0 (PE0) on the AVR. (3 points)
    4. Describe the four ways an external interrupt can be triggered using the Arduino libraries. (4 points)

Rubric

Demo

  • Deliverable A
    • 5 points
  • Deliverable B
    • 5 points
  • Deliverable C
    • 5 points: Blinks the number of times button was pressed at least once
    • 5 points: Repeatedly blinks the sequence
    • 5 points: Sequence can be interrupted and recounted at least once
    • 5 points: Sequence can be interrupted at any time