Back to what I know best about this event. The code...
Below is a snippet of code from the loop function an arduino c++ detector program. In this case, the red LED is on digital output pin 1, the green LED on pin 2, and the blue LED on pin 3. The GetTemperature function will output the measured temperature of the water in degrees C.
I haven't actually tested this code, and my C++ is a little rusty, so the syntax might be a little off, and the code might be a little broken... just a warning.
Code: Select all
float temperature = GetTemperature(thermistor);
float tBot[] = {22, 46, 12};
float tTop[] = {39, 57, 70};
for (int i = 0; i < 3; i++) {
if (temperature > tBot[i] && temperature < tTop[i]){
digitalWrite(i+1, HIGH);
}
else{
digitalWrite(i+1, LOW);
}
}
- What are the current temperature ranges entered for the detector?
- Describe what the the purpose of the for loop in this program is.
- Now, let's say at a competition, the red pin was moved to pin 4 because pin 1 was malfunctioning. Additionally, let the temperature ranges for this competition be red = 20*C to 56*C, green = 0*C to 25*C, and blue = 68*C to 75*C. Modify the code as little as possible so that the detector shows the proper LED ranges. You only need show the edited lines.
Edit: Just noticed that I messed up array initialization...