Question: #8530

COSC130 Fall Lab 3 Complete Solution

COSC130 Fall 2015 Lab 3 (100 pts)
MGT JA Rev2F2015


This lab continues your work with sketches for the Due board. You will use code downloaded from
Blackboard, including a function to drive the Shield's 7-segment displays. The downloaded code is the skeleton you start with, but you will modify this code to create an up-down counter. You'll also implement a simple calculator.
There is no new reference handout for this lab. The previous Part I and Part II are relevant material. This lab has two parts. The point distribution is described at the end.

1 Creating an Up-Down Counter
You must create a simple sketch that counts up/down in the decimal range 0-9 (binary integer range 0000- 1001) and displays the current decimal count on a 7-segment display. The Serial Monitor is not required on this part, but it may help your debugging.

1. Download the skeleton sketch UDCounter.ino from Blackboard. This sketch handles the 7-segment display for you by the function Drive7(). When you input an integer in the range 0-9, it'll display on
a 7-segment display. Do not modify this code except in the locations where it asks you to do so.
2. Open UDCounter in IDE and modify the sketch for these requirements:
(a) The current count is an integer in the range 0-9 and is shown on a 7-segment display. The initial
count is 0.
(b) When Shield button A1 is brie
y pressed, the counter increments by 1.
(c) When Shield button A2 is brie
y pressed, the counter decrements by 1.
(d) When Shield button A3 is brie
y pressed, the counter resets to 0.
(e) The count is circular. When the count is 9 and button A1 is pressed, the count \goes up" to 0.
When the count is 0 and button A2 is pressed, the count \goes down" to 9.
(f) The count should change only once when a button is pressed. For instance, if button A1 is held
down, the count does not keep increasing.
(g) You may assume that only one button is pressed at a time.
2 Creating a Simple Calculator
You will write a sketch using the Serial Monitor for I/O to implement a simple calculator in this second
part of the lab. The requirements are:
1. Name your sketch CalcYourName using a short version of your own name for YourName.
2. The user will type-and-Send a one-line input from the Serial Monitor. The form of a correct input
is
operand1 operator operand2
with a space between items, or a single operand
1
operand1
Three examples of correct input are 5.5 * 6 and -5.5 * -6 and -5.5.
3. Any other form of input is incorrect. The sketch must detect incorrectness and print an error message
on the Serial Monitor. It's a good idea to keep messages to the user polite.
Examples of incorrect input are -5.5 -6 * (operator is in wrong place) and (5) * 6 (the parens
aren't allowed).
4. Your calculator must handle the four operators + - * /.
5. Input operands are decimal (base-10).
An operand is an integer (a sign is allowed) or a real number written as integer-decimal-fraction,
for instance, 25.1; however, the calculator must retain the previously computed answer and if the user
uses ans for an operand, the calculator must use that previously computed value as an operand.
For example, 5 * 2 computes and retains answer 10, so ans * 3 next computes and retains new answer
30.
Initialize ans to 0.
6. Your calculator sketch prints the correct answer in the Monitor. Remember that the Monitor prints
floats rounded to two fractional digits, so that's how your calculator's answer will be displayed.
7. If the user types-and-Sends just one operand, that's OK. Your calculator will just make that operand
the answer and echo it back to the Serial Monitor. For example, the input -5.5 is allowed and the
value of ans becomes -5.5.
Points: Demo and Submit on Blackboard
1. Demo your modi ed UDCounter sketch to GTA in this lab session (anytime before the session is over)
and submit sketch on Blackboard by deadline below (50 pts).
2. Demo your CalcYourName sketch to GTA in this lab session and submit sketch on Blackboard by
deadline below (50 pts).
All items must be submitted on Blackboard by 11:59pm on R 17 Sept 2015.
 

Solution: #8540

COSC130 Fall Lab 3 Complete Solution

Function: drive7(int val) Description: drive7 takes a value fro...
Tutormaster
Rating: A+ Purchased: 11 x Posted By: Vikas
Comments
Posted by: Vikas

Online Users