Studio 10: Review


This studio is review material for the exam on Thursday evening.

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 2nd midterm exam

Studio organization

As a review, this studio is organized around the set of subjects we have covered so far this semester, with a strong focus on the material since the first midterm exam. While not designed to be comprehensive, there will, by necessity, be some overlap with material covered in the first midterm.

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 your individual preparation for the exam (i.e., focus on the things that you need the most help with).

Analog inputs

Given a spec from some arbitrary input device, can you write code that reads from an analog input channel and converts the A/D counts into the appropriate engineering units?

  • Hook up the potentiometer using 5V and ground and an analog input on the “wiper”. Find a way to estimate the degree of rotation based on the measured value. Be sure to use the default analog reference.

  • Hook up the 3.3V pin on the Arduino to a free analog input pin. Author a sketch to read the analog value and print it to the Serial Monitor. Approximately what value do you expect to see? Why?

  • Hook up the 3.3V pin on the Arduino to the AREF analog input reference pin (they are right next to one another). Using an external reference (see analogReference()), alter your temperature conversion code to again properly read degrees C. Try it out. Is it reasonable? (Don’t worry if it’s a few degrees off, the reference voltages aren’t that precise.)

Streams and communication

  • What are the basic operations on a stream (receive/send a byte) for each platform, Arduino C and Java?

  • What is a magic number and what is it good for?

  • We wish to send a debug message using our protocol. The debug string should comprise the single character "?". (Yes, we know, that is really a poor debug message!) How many bytes will be in the message? What are those bytes, in order? Give the contents of each part of the message in hex and describe its meaning.

  • This is a thought exercise, don’t really write any of this code. Consider how you would design a protocol and write the corresponding code to transmit and receive Java objects (we are only interested in the instance variables appropriate for these Java objects): (1) a rectangle, (2) a pencil (first design the object, then design the protocol). What kind of FSMs would you use to handle communication? What would your Java objects look like in Arduino C?

The Arduino side

  • If you type in the string “hello” to the serial monitor, and then the Arduino executes a single invokation of, what value will be returned by Serial.available() if it is invoked immediately after the call to returns?

  • What is the value, in hex, returned by the above call to

  • You want to send a two-byte int to Java, but instead of doing it the way we’ve done it all semester, this time you want to send it least significant byte first. Author code for the Arduino that will send an int in this way.

The Java side

  • Author Java code that will receive a two-byte int sent from the Arduino least significant byte first and store the received integer in a Java int (which is comprised of four bytes).

Multiplexed display

In these questions, you will be designing a new character for a 5 by 7 pixel display (of the type we’re using in class).

  • The first task is to decide what the character looks like. On a 5 by 7 grid, design the look of a new character EURO (€). I.e., which of the LEDs will be lit and which will be dark for this new character?

  • Fill in the initializations below, so that the font_5x7[][] array data structure can be used to display the character you have just designed on the 5 by 7 pixel display.

font_5x7[EURO][0] = 0x _____ ;

font_5x7[EURO][1] = 0x _____ ;

font_5x7[EURO][2] = 0x _____ ;

font_5x7[EURO][3] = 0x _____ ;

font_5x7[EURO][4] = 0x _____ ;

  • If the display is to be refreshed at a rate of 30 frames per second, what is the maximum delta time allowed for each column?

Accelerometer and peak detection

  • In studio last week, you authored code to detect the peaks in the accelerometer signal, starting with a simple peak detection algorithm and expanding to make it more robust. Design an alternative approach to avoiding the false peaks than the one you used in studio (i.e., just solve the problem in an alternative way).

Game design

The answers to the following three questions will depend upon how you implemented the predator-prey game (Assignment 8), so don’t be surprised if your answers are different than another group’s answers.

  1. If you wished to alter the 4 Hz flashing frequency of the predator, how many lines of code would need to change, and which lines are they?

  2. If you wished to alter the display of the predator to be just a single (flashing) dot, how many lines of code would need to change, and which lines are they?

  3. Which of the above two changes would be more complicated to ensure it is done correctly (i.e., to test adequately)?

Finish up

  1. No need to commit your code this week.
  2. No need to check out this week either.