Microprocessors
Lab 8 C Programming 4
The purpose of this lab is to become familiar with a
ays and data structures in C.
Instructions (IMPORTANT!):
1. Insert screenshots (which include your computer tray and clock) where indicated.
2. Provide comments on all lab sections as indicated. Highlight all comments.
3. Students who are found to have submitted another’s work will receive an academic misconduct.
4. Submit this lab file, and your complete Arduino file to the dropbox in Blackboard when completed.
In your Arduino file put your name and a title above each part, place each part within a comment block.
5. A complete lab will contain 4 screenshots, and a
ief comment for every lab part (5 total).
For each question below, write the code co
esponding to the given pseudo code, verify and upload the code to the Arduino simulator. Provide a sentence or two of comments for every part, and answer specific questions where they are noted.
Part 1: A
ays (3) (20 minutes)
1) Creating an A
ay
a) declare a global integer type a
ay with 5 elements, called myA
ay.
assign values to all 5 a
ay elements.
in the setup function, using 5 print statements, print the values of the a
ay.
b) modify the program, so instead of instead of using 5 print statements, use a single for loop.
INSERT SCREENSHOT
2) rectangle area problem
Store 5 random values for width and 5 random values for length in two a
ays, and use nested for loops (for loop within a for loop) with the a
ays to calculate and print the areas of 25 rectangles. Use each for loop to increment through a separate a
ay.
INSERT SCREENSHOT
Add the program from 2) to your Arduino file for submission.
Part 2: Data Structures (7) (60 minutes)
1) Creating a Data Structure
Connect a potentiometer between 5V, pin A0, and GND.
Connect a button between 5V and pin 2 (do not forget the pull-down resistor).
in the setup function create a data structure called sensorInfo containing 3 variables, which will store a time reading, an analog input reading, and digital input reading
remember this is only the format of the structure.
create an instance of the data structure called testData.
in the setup function take a reading of A0, pin 2, and millis() and store them in testData in the setup function, print all recorded values once the readings are finished
this will record and print 1 set of data.
INSERT SCREENSHOT
Add the program from 1) to your Arduino file for submission.
2) a
ays and loops with data structures
create a global data structure called sensorInfo containing 3 variables, which will store the time recorded from millis(), an analog input value (from A0), and digital input value (from pin 2).
Create an a
ay of 10 instances of the data structure, called dataA
ay.
In the loop function, use a for loop to take 10 readings of A0, pin 2, and millis(),
5 seconds apart, and store them in dataA
ay.
in the loop function, use another loop to print all recorded values once the readings are finished.
When executing the code, be sure to vary the analog and digital inputs.
INSERT SCREENSHOT
Add the program from 2) to your Arduino file for submission.