2 Purpose: find the minimum and maximum values of an array of
5 Dr. Purdum, August 13, 2012
8 #define READINGSPERDAY 24
9 #define VERYHIGHTEMPERATURE 200
10 #define VERYLOWTEMPERATURE -200
12 int todaysReadings[] = {62, 64, 65, 68, 70, 70, 71, 72, 74, 75, 76, 78,
13 79, 79, 78, 73, 70, 70, 69, 68, 64, 63, 61, 59};
15 // So we can communicate with the PC
24 Serial.println("=== Before function call:");
25 Serial.print("The lvalue for lowTemp is: ");
26 Serial.print((long) &lowTemp, DEC);
27 Serial.print(" and the rvalue is ");
28 Serial.println((long) lowTemp, DEC);
29 Serial.print("The lvalue for hiTemp is: ");
30 Serial.print((long) &hiTemp, DEC);
31 Serial.print(" and the rvalue is ");
32 Serial.println((long) hiTemp, DEC);
34 retVal = CalculateMinMax(todaysReadings, &lowTemp, &hiTemp);
35 Serial.println("=== After the function call:");
36 Serial.print("The lvalue for lowTemp is: ");
37 Serial.print((long) &lowTemp, DEC);
38 Serial.print(" and the rvalue is ");
39 Serial.println((long) lowTemp, DEC);
40 Serial.print("The lvalue for hiTemp is: ");
41 Serial.print((long) &hiTemp, DEC);
42 Serial.print(" and the rvalue is ");
43 Serial.println((long) hiTemp, DEC);
46 Serial.flush(); // Make sure all the data is sent...
50 Purpose: Get the daily temperature reading (READINGSPERDAY) and
51 set the minimum and maximum temperatures for the day.
53 int temps[] the array of temperatures
54 int *minTemp pointer to the minimum temperature value
55 int *maxTemp pointer to the maximum temperature value
58 int the number of readings processed
60 int CalculateMinMax(int temps[], int *minTemp, int *maxTemp)
63 *minTemp = VERYHIGHTEMPERATURE; // Make the minimum temperature ridiculously high
64 *maxTemp = VERYLOWTEMPERATURE; // Make the maximum temperature ridiculously low
65 for (j = 0; j < READINGSPERDAY; j++) {
66 if (temps[j] >= *maxTemp) {
69 if (temps[j] <= *minTemp) {