Studio 5: Review
- Information representation
- C language
- Digital outputs
- Digital inputs
- Finish up
This studio is review material for the exam on Thursday afternoon.
The exam starts right at 2:40pm in Simon 1. You can bring a crib sheet (1 piece of normal, letter size paper) on which you can write (but not print) anything you wish (both sides).
By the end of this studio, you should know:
- what to expect on the midterm exam
As a review, this studio is organized around the set of subjects we have covered so far this semester. Each section will have some review questions, some pencil and paper style, some expecting you to author some code.
Do not feel obligated in any way to do these in order. Jump around and focus on the ones that will give you the most benefit in terms of preparation for the first exam.
Now we’re getting into the heart of the matter. This is stuff you should definitely expect to be asked about.
In general, don’t be surprised when we ask about how some data type is different in Arduino C vs. Java.
Also review Chapter 8 in the course text.
Know about conversion back and forth between any of decimal, binary, and hexadecimal.
Convert from binary to hex:
Convert from hex to binary:
Convert from hex to decimal:
Convert from decimal to hex:
Be able to do these conversions without a calculator. Yes, this means you have to do a little multiplication and/or division for some of them. You can do it!
Integer and fixed-point representations
Know about two’s complement representation, as well as excess notation and sign-magnitude notation. You also want to know the basics of fractional numbers.
How do you represent
-1in the following forms: 8-bit two’s complement, 8-bit sign-magnitude, 8-bit excess-127.
How do you represent
-2in these forms?
What is the weight of the most significant bit in 8-bit two’s complement?
What is the weight of the least significant bit in 8-bit two’s complement?
How many fractional bits are in a Q1.15 number?
Floating point representation
We’ll keep the floating point questions relatively simple (that’s code for “I won’t give you a 32-bit binary number and ask what it means as an IEEE floating point number.”). There are some questions, though, that are fair game, such as:
How many bits are in the exponent of a
floatin Java, or in C?
How many bytes in a
doublein C, in Java?
What form is used to represent negative numbers for the number as a whole? For the exponent?
We have discussed strings in two different formats this semester:
null-terminated arrays of single-byte characters in Arduino C and
String class in Java (under the hood using two-byte UTF-16 characters).
We will soon cover
UTF-8 strings, which have a two-byte size followed by a sequence of
flexible width (single-byte in our case) characters.
Use an ASCII table to look up the hex encoding for “ASCII table” and author an Arduino sketch using
Serial.write()to send the string
ASCII tableto the Serial Monitor on the PC. Use hex values as arguments to
Serial.write('A'); Serial.write('S'); ...).
What else do you need to send (e.g., via
Serial.write()) so that further (i.e., subsequent) versions of your string are printed on the next line in Serial Monitor? Try it.
There are a number of things we have investigated where C is somewhat different than Java. Can you name a few? Maybe more important, will you recognize them when you come across them in code? (e.g., differences in the sizes of data types, etc.)
There are many things where Arduino C and Java are quite alike. (e.g., indexing into arrays.)
- In C, suppose
yare declared as
charand have values
0xab, respectively. What are the values of the following C expressions:
x & y,
x | y,
~x | ~y,
~x & !y,
x && y,
x || y,
!x || !y, and
~x && ~y.
The focus of our timing investigations have moved to delta-timing techniques. We’ll keep the delta-timing questions reasonably straightforward since you haven’t yet turned in the assignment that uses delta timing. Delta timing is, however, fair game for the exam.
delay()based timing, what are the things that can cause the iteration time to be inaccurate?
When using delta-time techniques, what can still cause the iteration time to be inaccurate (i.e., delta-time techniques don’t handle everything, what do they still leave for the programmer to ensure is correct)?
Also review Chapter 6 in the course text.
We’ve not only generated software that controls digital outputs, we’ve also built the circuits that those digital outputs control.
With an LED, to get it to light, should the anode have a higher voltage than the cathode, or the other way around?
What is a reasonable resistor value to put in series with an LED to both physically protect the circuitry and also have a reasonable brightness?
Does it matter what is the orientation (i.e., direction) of the resistor?
Does it matter whether the LED is first and the resistor is second, or if the resistor is first and the LED is second?
What resistor value corresponds to the color code red-red-brown-gold? yellow-orange-red-gold? (The gold indicates tolerance, you can ignore that part. I just included it for completeness.)
Also review Chapter 2 in the course text.
We’ve used a digital input to determine if a button is pressed or not.
- How does a button need to be wired.
- What pin mode did we use with the button and why?
- How was the value from the button read?
Author a sketch that will:
- Detect when a button is pressed
- Print the amount of time the button is held down (in milliseconds)
- When a button is pressed, print the amount of time since it was last pressed. (It can print the amount of time since the Arduino was powered on the first press).
Also review Chapter 3 in the course text.
We’ve used FSMs for one thing, with a second one to come later:
- Modeling simple machines (which can be converted to a program)
- Handling the process of communication (recognizing a specific input)
Assume that you have a FSM that will have as input individual letter characters and space characters. Can you design a FSM that will output a 1 when a word begins with with the letters
t? The output can be on for exactly one “letter” or for the duration of the word. I.e., it would recognize the “st” in sequences like: “stuff”, “a story”, “ st “, “a st”, but not in sequences like “most “ or “less ts” or “ss t”. Moreover, it would correctly recognize the number of “st” words in sequences like: “most stories” and “ an st study “. Draw the bubble diagram of this FSM.
This next one is a stretch (i.e., don’t worry if you are not yet comfortable doing it).
Can you write and test code that implements this state machine (either in Java or on the Arduino)?
Also review Chapter 7 (Section 7.1) in the course text.
- No need to commit your code this week.
- No need to check out this week either.