looking for arduino code for homework , i have been trying much but can\'t make
ID: 2248631 • Letter: L
Question
looking for arduino code for homework , i have been trying much but can't make it work and needs some helop.
/*Use the I2C backpack with the LCD, the thermistor,
and two buttons to create a monitoring station that will track and display the temperature.
One button should be used to switch between Fahrenheit and Celsius on the display.
The current temperature should always be displayed on line 1 of the LCD “Now: ###.#°F” (or °C depending on the current mode).
The second line of the LCD display should cycle between the highest temperature recorded since reset,
the lowest temperature recorded since reset, and the average temperature since reset.
These 3 numbers should be displayed in the following format “Label: ###.#°F” (or °C depending on the current mode),
the label should be either “High”, “Low”, or “Avg.”. A second button should be used to allow the user to reset the stored historical values.
Do not pad any of the numbers with leading zeros to make them fit the proposed format, just display the number as it is, and round to the nearest tenth.
*/
Explanation / Answer
#include <LiquidCrystal.h>
//Used digital interrupt pin 2 for switching from ^C to ^F
//Used digital interrupt pin 3 for reset
const int convertPin = 2;
const int resetPin = 3;
//Assumed initiallly LCD will display in ^C you can change it by negating the following variable
boolean tempMode = true; //tempMode is true for ^C and false for ^F.
boolean reset;
float max_temp,min_temp,avg_temp,temp;
void setup() {
pinMode(convertPin,INPUT_PULLUP);
pinMode(resetPin,INPUT_PULLUP);
attachInterrupt(digitalPinToInterrupt(convertPin),convertTemp,CHANGE);
attachInterrupt(digitalPinToInterrupt(resetPin),resetMode,CHANGE);
}
void resetMode(){
//resetting all the values
max_temp=0;
min_temp=0;
avg_temp=0;
}
void convertTemp(){
//change from ^C to ^F and vice-versa on each-press
tempMode = !tempMode;
}
void loop() {
// put your main code here, to run repeatedly:
//Here you add the code for read the temperature dht.readTemp() assume that as variable temp and assuming that sensor gives temp in ^C;
if(temp>max_temp){
max_temp=temp; //to capture the max temp
}
if(temp<min_temp){
min_temp=temp; //to capture the min temp
}
avg_temp = 0.5*(min_temp+max_temp);
if(tempMode==true){
setCursor(0,0);
lcd.print("Temp:");
lcd.print(temp,1);
lcd.print("^C");
setCursor(0,1);
lcd.print("H");
lcd.print(max_temp,1);
lcd.print("L");
lcd.print(min_temp,1);
lcd.print("A");
lcd.print(avg_temp,1);
}
else(tempMode==false){
float favg,fmax,fmin,ftemp;
//converting temp in ^F.
ftemp = (temp*1.8)+32;
fmax = (max_temp*1.8)+32;
fmin = (min_temp*1.8)+32;
favg = 0.5*(fmax+fmin);
setCursor(0,0);
lcd.print("Temp:");
lcd.print(ftemp,1);
lcd.print("^F");
setCursor(0,1);
lcd.print("H");
lcd.print(fmax,1);
lcd.print("L");
lcd.print(fmin,1);
lcd.print("A");
lcd.print(favg,1);
}
}
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.