You are on page 1of 2

SAN JOS STATE UNIVERSITY

Department of Mechanical and Aerospace Engineering

ME 106 Fundamentals of Mechatronics Homework #3: Programming the Arduino Due 2/28/13 Hardcopy (in lecture) and Softcopy (in D2L)
Use the answer template to record your homework responses. Dont forget to include the summary of the assignment on the cover page of the answer template (what you did, how you did it, and what you learned). Where written responses are requested, please type them. Make sure that you show how you arrive at any answers involving numerical calculations. Answers that do not show intermediate steps will likely not get any points. Photocopy, photograph, or scan your work, so that you have a back up copy. ************************** 1. Get an Arduino board. Arduino Microcontroller (Duemilanove or UNO R3). Sources for these
boards include: NKC Electronics , Adafruit Industries, Sparkfun Electronics, Modern Device, Radio Shack, and many others..

2. Go to http://arduino.cc/en/Main/Software, download the Arduino software, and install it on a computer that you will use for your homework or project work. See the Getting Started web page for instructions on installing the Arduino software (http://arduino.cc/en/Guide/HomePage). 3. Review the handout on Bit Manipulation, http://www.engr.sjsu.edu/bjfurman/courses/ME106/lectures/handout_bit_manipulation.doc, and the addendum, http://www.engr.sjsu.edu/bjfurman/courses/ME106/lectures/handout_bit_manipulation_adde ndum.doc 4. Binary HEX Decimal conversions a. (2 pts) Convert the binary number 10100111 to HEX b. (2 pts) Convert the HEX number 7A to binary c. (2 pts) What would the following C statement evaluate to? 0x17 > 17; Explain your answer. d. (2 pts) Evaluate as a decimal number the statement, 0xD6 0b11000110; e. (2 pts) What is decimal 145 expressed in HEX? 5. (10 pts) Write two programs to run on the Arduino that will do the following: a. Make pins D2 and D3 be outputs, and pins D0, D1, D4 D7 to be inputs b. Turn on pullup resistors for D0 and D1 only c. Repeat forever alternating making D2 and D3 high and low with a one second delay between the change in state of the two pins. In other words, the pattern is: when one of D2 or D3 is high the other is low. Every second thereafter, the state of the pins flips (the one that was high goes low, and the one that was low goes high). Write one of the programs using Arduino style programming. Write the second program using the more general port-style approach (i.e., without using the built-in Arduino

BJ Furman | ME 106 Intro to Mechatronics | HW3_Arduino.doc | 14FEB2013

Page 1 of 2

SAN JOS STATE UNIVERSITY

Department of Mechanical and Aerospace Engineering

ME 106 Fundamentals of Mechatronics


functions that deal with setting the data direction for a pin or writing to a pin). You must comment your code to have any hope of getting full credit. 2. (10 pts) Assume that four active-low switches are connected to Arduino pins D0 D3 and four LEDs are connected to Arduino pins D4 D7 (each through a current limiting resistor as shown in lecture). Write two programs to run on the Arduino (one in Arduino style, the other in port-style) that will do the following: Read the state of the switches, and output their state to the LEDs. So, if a switch is activated (i.e., connecting it to ground), the corresponding LED will light up (i.e., the switch on D0 controls the state of the LED on D4, the switch on D1 controls state of the LED on D5, etc.) 3. (10 pts) Write two programs to run on the Arduino (one in Arduino style, the other in portstyle) in conjunction with the PortMaster shield that will do the following: Turn the LEDs associated with PORTD (D0-D7) on or off according to the pattern shown below, so that the LED light starts at the right and appears to travel to the left in a time that is detectable by the eye (say about 1 second to go from right to left). After the LED spends its one display cycle in the leftmost position, the behavior should begin again from the rightmost position. In the diagram below, the numbers in the column header are the bit position numbers for your reference. Time is increasing from top-to-bottom of the chart. The behavior should loop forever. [Note: to have any hope of getting credit for this problem, your code must be fully and well-commented]
7 6 5 4 3 2 1 0 X X X X X X X X X X X X

Extra Credit: Write a program that will allow you to execute the pattern from Problem 7, but using all ten of the LEDs on the PortMaster shield. [Again, to have any hope of getting credit for this problem, your code must be fully and wellcommented]

BJ Furman | ME 106 Intro to Mechatronics | HW3_Arduino.doc | 14FEB2013

Page 2 of 2