EasyManua.ls Logo

SunFounder 3in1 Kit - Page 209

Default Icon
351 pages
Print Icon
To Next Page IconTo Next Page
To Next Page IconTo Next Page
To Previous Page IconTo Previous Page
To Previous Page IconTo Previous Page
Loading...
SunFounder 3in1 Kit
temperature threshold value, which can be adjusted using a potentiometer. The threshold value is stored on EEPROM
at the same time, so if the current temperature exceeds the threshold value, the buzzer will sound.
Note: If the code and wiring are fine, but the LCD still does not display content, you can turn the potentiometer on
the back.
How it works?
1. Initialize the button, buzzer and I2C LCD1602, and read the EEPROM values. An interrupt is also used here to
read the button status.
void setup()
{
pinMode(buzzerPin, OUTPUT);
pinMode(buttonPin, INPUT);
lcd.init();
lcd.backlight();
upperTem = EEPROM.read(0);
delay(1000);
attachInterrupt(digitalPinToInterrupt(buttonPin), buttonState, FALLING);
}
The interrupt is used here to read the button’s state. When the button is pressed, buttonPin
changes from low to high.
The function buttonState is called when the interrupt triggers, and it toggles the value of the
variable state.
FALLING means the interrupt occurs when buttonPin goes from low to high.
2. To set the high temperature threshold, the function upperTemSetting() is called when state is 1 (state switches
between 0 and 1 with button press) in the main program, otherwise monitoringTemp() is called to display the
current temperature and the set threshold.
void loop()
{
if (state == 1)
{
upperTemSetting();
}
else {
monitoringTemp();
}
}
3. About upperTemSetting() function.
void upperTemSetting()
{
int setTem = 0;
lcd.clear();
lcd.setCursor(0, 0);
lcd.print("Adjusting...");
lcd.setCursor(0, 1);
(continues on next page)
4.6. 6. Funny Project 205

Related product manuals