Home‎ > ‎CS 11M‎ > ‎Decisions and Digital I/O‎ > ‎

Project 2: Decisions and Input

In this project you'll use variables, serial input and output to customize the blink circuit. 

Introduction

In this project you will make a program that accepts input from both buttons and the serial monitor. Your program will produce output in the form of a blinking LED and it will report its status using output to the serial monitor. In order to accomplish this you will need to have a good understanding of if statements, cin, cout and variables. Before you start be sure to review the class exercises from this week. 

Reference Program

If you completed the lab for this week you should be able to download a compiled binary to your Arduino. Use the reference program below as a guide for how your program should work. 


The HEX file is what you should see with part 2 complete. 

Variable Blink

Begin with the class exercise if-else-if.ino. Modify the code to do the following:
  1. Allow the user to input the delay time in milliseconds directly. 
  2. Validate the user's input to be sure it's within proper bounds:
    1. If the number is less than 100 set the delay to 100. 
    2. If the number is greater than 1000 set the delay to 1000.
  3. If the user gives an invalid input print a message telling them so. 
  4. After the user changes the delay print the new delay to the serial monitor.  
Name your sketch proj2_part1.ino and submit it. 

Button-Based Updates 

Review the code from the button_counter.ino class exercise. In this part you will use similar code to track when both the right and the left button are pressed. Update the program from part 1 of the lab to respond to the buttons in the following ways:
  1. When the left button is pressed decrease the delay by 20 milliseconds. 
  2. When the right button is pressed increase the delay by 20 milliseconds. 
  3. Ignore the button press if the delay would exceed the bounds from part 1. 
  4. Print changes to the delay to the serial monitor.
Name your sketch proj2_part2.ino and submit it.  

Formatting

It's important to format your code! For full credit your code must adhere to the following rules:
  1. You must use and fill out the comment header as specified in my template. 
  2. You must properly indent your code before you submit it (Ctrl-T in Arduino IDE)
  3. You can create variables with either CamelCase or under_score styles but you must be consistent.

Turn In

  1. Exercises from last week:
    1. bin4counter.ino
    2. bin4io.ino
    3. if-else-if.ino
      1. Answers to the questions in this exercise
    4. button_counter.ino (optional)
  2. proj2_part1.ino
  3. proj2_part2.ino
Submit your homework on Canvas.

Grading

  • 5 points for class exercises 
  • 20 points for the project (10 points each part)
ċ
project2.ino.standard.hex
(30k)
Michael Matera,
Sep 12, 2016, 10:29 AM
Comments