Lab #8 Solution

$30.00

Description

Learning Goal:

  • Learn how to program with interrupts.

Write a program for the Arduino that utilizes interrupts. Interrupts allow a section of Arduino code to be called without writing code in the loop( ) function to explicitly check that code.

The lab is to have you use 2 buttons and the 16×2 LCD display. Each button is to trigger an interrupt. The interrupts are to toggle between two states/messages displayed on the 16×2 LCD.

  • When no button has been pressed your 16×2 display should say something like “We have been waiting for X seconds”, where X starts at the value 0 and is updated as time goes on. This is State 0.

  • When the first button is pressed, the display should display “Interrupt received! Press button 2 to continue”. This is State 1.

  • When the user presses the second button, the display goes back to displaying “We have been waiting for X seconds”, and restarts the time at 0 seconds. (I.E. go back to State 0.)

Information about how to tell the system to call your Interrupt Service Routine (ISR) can be found at:

http://arduino.cc/en/Reference/attachInterrupt

Information about timer:

https://www.arduino.cc/en/Reference/Millis

Important note: You must use pin 2 and pin 3 for this lab. Those two pins are specifically set up to work with interrupts.

To be considered completed “on time”, this Lab needs to be demonstrated by end of Lab on Wednesday . Your code must be submitted to Gradescope BEFORE you demo your lab!

Late Policy

  • Late Submission – Submitted and/or demonstrated later that week (before Friday 25% Penalty

  • Late submission – Submitted and/or demonstrated during the following week (before 50% Penalty

What should I include with my .ino Code File?

As with any code file, it should be written in Good Coding Style: in a manner that will help other people read and understand the intent, purpose, operation of the code. So your code must include:

  • Name the .ino file with your NetId and Lab Number o I.E. something like: ptroy4Lab2.ino

  • Header Comments (including the following)

  1. // FirstName LastName, UIN and NetID

  1. // Lab x – Title

  1. // Description – what is this code supposed to do?

  1. // Include any assumptions you may have made, what do you expect from the hardware, pinouts, particular arduino versions, etc.

    1. // References – where did you find code snippets, ideas, inspirations? if no references used say: “no references used”

  • Code is well documented/formatted with comments, indentations, and descriptive variable names

  • Actual code – the functions in the cpp/ino file

Academic Integrity Guidelines:

You may use any resources linked from this lab, or posted by the professor or TAs on piazza/class web page/etc. You should not look at any other internet resources for this. This is an individual assignment, and should be completed on your own. You should not show anyone your code, or look at anyone else’s code.