/********* Pleasedontcode.com **********
Pleasedontcode thanks you for automatic code generation! Enjoy your code!
- Terms and Conditions:
You have a non-exclusive, revocable, worldwide, royalty-free license
for personal and commercial use. Attribution is optional; modifications
are allowed, but you're responsible for code maintenance. We're not
liable for any loss or damage. For full terms,
please visit pleasedontcode.com/termsandconditions.
- Project: Temperature Monitor
- Source Code compiled for: Arduino Uno
- Source Code created on: 2023-12-29 03:33:28
********* Pleasedontcode.com **********/
/****** SYSTEM REQUIREMENTS *****/
/****** SYSTEM REQUIREMENT 1 *****/
/* Si la temperatura supera los 35° entonces enciende */
/* L1 y A=1, si no apaga L1 y A=0. Si la temperatura */
/* supera los 30 entonces enciende L2 y B=1, si no */
/* apaga L1 y B=0. Si A=1 o B=1 entonces encienda */
/* Buzzer. Si A=0 y B=0 entonces apague Buzzer. */
/****** SYSTEM REQUIREMENT 2 *****/
/* Si se pulsa el pulsador apague el buzzer y no haga */
/* nada durante 5s. */
/****** END SYSTEM REQUIREMENTS *****/
/****** DEFINITION OF LIBRARIES *****/
#include
#include
#include
/****** FUNCTION PROTOTYPES *****/
void setup(void);
void loop(void);
/***** DEFINITION OF DIGITAL INPUT PINS *****/
const uint8_t D_DHT11_DOUT_PIN_D2 = 2;
const uint8_t P_PushButton_PIN_D3 = 3;
/***** DEFINITION OF DIGITAL OUTPUT PINS *****/
const uint8_t B_ActiveBuzzer_output_PIN_D5 = 5;
const uint8_t L1_LED_PIN_D4 = 4;
const uint8_t L2_LED_PIN_D6 = 6;
/****** DEFINITION OF LIBRARIES CLASS INSTANCES*****/
EasyButton pushButton(P_PushButton_PIN_D3);
DHT dht(D_DHT11_DOUT_PIN_D2, DHT11);
/****** SYSTEM REQUIREMENTS *****/
bool A = false; // Variable to track requirement 1 condition A
bool B = false; // Variable to track requirement 1 condition B
bool buzzerEnabled = false; // Variable to track buzzer state
unsigned long buttonPressTime = 0; // Variable to track button press time
void setup(void)
{
// put your setup code here, to run once:
pinMode(D_DHT11_DOUT_PIN_D2, INPUT_PULLUP);
pinMode(P_PushButton_PIN_D3, INPUT_PULLUP);
pinMode(B_ActiveBuzzer_output_PIN_D5, OUTPUT);
pinMode(L1_LED_PIN_D4, OUTPUT);
pinMode(L2_LED_PIN_D6, OUTPUT);
dht.begin();
}
void loop(void)
{
// put your main code here, to run repeatedly:
float temperature = dht.readTemperature();
/****** SYSTEM REQUIREMENT 1 *****/
if (temperature > 35) {
digitalWrite(L1_LED_PIN_D4, HIGH);
A = true;
} else {
digitalWrite(L1_LED_PIN_D4, LOW);
A = false;
}
if (temperature > 30) {
digitalWrite(L2_LED_PIN_D6, HIGH);
B = true;
} else {
digitalWrite(L2_LED_PIN_D6, LOW);
B = false;
}
if (A || B) {
digitalWrite(B_ActiveBuzzer_output_PIN_D5, HIGH);
buzzerEnabled = true;
} else {
digitalWrite(B_ActiveBuzzer_output_PIN_D5, LOW);
buzzerEnabled = false;
}
/****** SYSTEM REQUIREMENT 2 *****/
if (pushButton.isPressed()) {
digitalWrite(B_ActiveBuzzer_output_PIN_D5, LOW);
buzzerEnabled = false;
buttonPressTime = millis();
while (millis() - buttonPressTime < 5000) {
// Do nothing for 5 seconds
}
}
}