Question: C program Please C program Please C program Please This assignment is to write two programs that will simulate a quality control system. The first
C program Please
C program Please
C program Please
This assignment is to write two programs that will simulate a quality control system. The first program will run on the pcDuino and will measure the translucency and size of an object, storing those values to a file. The second program will run on a Windows computer and will analyze the data produced by the first program.
The measuring program will use the light sensor to determine the translucency of a product, to be expressed as a percentage, where 100% would be perfectly clear and 0% would be completely opaque. The distance sensor will be used to determine size, given as distance from the sensor. The Hall Effect sensor will be used to simulate the object being near the two sensors and that a measurement is to be taken. A button will be used to start and stop the program. As each translucency/size measurement are read, they will be immediately appended to the readings file.
The analysis program will read in all the measurements, storing to arrays. The standard deviation for translucency and for size will be calculated, then every measurement compared to those values. The number of any item that has either a translucency or size value outside the standard deviation will be stored to a rejects file, all other item numbers will be stored to an accepted file.
Program Details
prog2a.c
Parts and slot assignments
button D13
green LED D11
Hall sensor D6 (assign as 7 in code)
light sensor A4
distance sensor A3
Program Steps
Initialize hardware
Determine and store button pressed value
Wait for button press to begin processing
wait for magnet to approach sensor, blink LED while waiting (50 msec pause)
take one light/distance reading pair, append to file
print error message and end program if any file error occurs
wait one second, go back to step a
Stop processing when button pressed.
Required Functions
get_button_type given button slot, determines the value that represents pressed state of the button
blink given LED slot, number of blinks, duration of cycles, blinks the LED
read_store given light sensor slot, distance sensor slot and a file name, takes readings, opens file in append mode, stores the readings to one line.
The translucency measurement will be the reading from the light sensor divided by 4095 (the maximum possible reading). Store the calculated value (dont convert up to percent).
The size measurement will be the measured distance, using the formula:
size = 1.5 * 6762.0 / ( reading / 4.0 - 9 ) - 4;
Note that the read_store function takes a file name as one parameter. This will be in the form of a character array that is assigned the value readings.txt in main and is passed to the function. The function is to open the file in append mode, write the current data, and then close the file. The file is not to remain open between calls to the function.
All values stored to the file are to be written with three digits following the decimal point, and exactly one space between values on a line. Each measurement pair is written to one line.
prog2b.c
Program Steps
Open input file readings.txt. If file fails, display message and end program
Read the data into arrays for translucency and for sizes. Keep count of number of records read
If no records, display message and end program
Calculate average and standard deviation for translucency array and for sizes array
Open output files accepted.txt and rejected.txt. If either fails, display message and end program
Compare each items two measurements to their respective average and standard deviation. If item is outside standard deviation for either measurement, write its number (index + 1) to the rejected file, otherwise write its number to the accepted file.
Close files.
Required Functions
calc_avg given an array and its size, determines the average value
calc_std_dev given an array and its size, determines the standard deviation
read_data given an opened input file, two arrays of type double and the maximum number of values to put into the arrays, reads the file, storing the translucency and size values to respective arrays, keeping count of the number of item pairs read
Example Output
Take your finger off the button!
Start testing products by briefly pressing button.
Move product to test station when LED is on
Press button again when all items are tested
Taking reading in 1 second
Taking reading in 1 second
Taking reading in 1 second
Taking reading in 1 second
Taking reading in 1 second
Taking reading in 1 second
Taking reading in 1 second
Taking reading in 1 second
Taking reading in 1 second
Taking reading in 1 second
Taking reading in 1 second
All done
readings.txt
0.849 9.307
0.774 9.656
0.885 10.107
0.804 10.068
0.805 10.705
0.775 9.633
0.832 9.730
0.828 9.899
0.830 9.656
0.826 9.638
0.808 9.493
Sample outputs from prog2b
accepted.txt
2
3
4
6
7
8
9
10
11
rejected.txt
1
5
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
