/********* 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: EasyButton Control
- Source Code NOT compiled for: Arduino Uno
- Source Code created on: 2024-05-08 17:46:39
********* Pleasedontcode.com **********/
/****** SYSTEM REQUIREMENTS *****/
/****** SYSTEM REQUIREMENT 1 *****/
/* The project must control a timer that starts when */
/* the infrared sensor is in a low active state and */
/* stops when the sensor returns to a low active */
/* state. The timer must be displayed on the LCD */
/* screen. */
/****** SYSTEM REQUIREMENT 2 *****/
/* The timer state should be handled using a state */
/* machine. Furthermore, an explicit function called */
/* 'resetTimer' needs to be implemented to reset the */
/* counter and state of the state machine. */
/****** END SYSTEM REQUIREMENTS *****/
/****** DEFINITION OF LIBRARIES *****/
#include
#include // https://github.com/marcoschwartz/LiquidCrystal_I2C
#include // https://github.com/evert-arias/EasyButton
/****** FUNCTION PROTOTYPES *****/
void setup(void);
void loop(void);
void resetTimer(void);
/***** DEFINITION OF DIGITAL INPUT PINS *****/
const uint8_t sensorInfrared_PushButton_PIN_D2 = 2;
/***** DEFINITION OF I2C PINS *****/
const uint8_t display_LCD1602I2C_I2C_PIN_SDA_A4 = A4;
const uint8_t display_LCD1602I2C_I2C_PIN_SCL_A5 = A5;
const uint8_t display_LCD1602I2C_I2C_SLAVE_ADDRESS = 39;
/****** DEFINITION OF LIBRARIES CLASS INSTANCES*****/
LiquidCrystal_I2C lcd(display_LCD1602I2C_I2C_SLAVE_ADDRESS, 20, 4); // Initialize LiquidCrystal_I2C object
EasyButton button(sensorInfrared_PushButton_PIN_D2); // Initialize EasyButton object
void onPressedForDuration()
{
// Code to be executed when the button is pressed for the given duration.
}
void setup(void)
{
// put your setup code here, to run once:
pinMode(sensorInfrared_PushButton_PIN_D2, INPUT_PULLUP);
lcd.init(); // Initialize the LCD
lcd.backlight(); // Turn on the backlight
// Initialize the button
button.begin();
// Add the callback function to be called when the button is pressed for at least the given time
button.onPressedFor(2000, onPressedForDuration);
}
void loop(void)
{
// put your main code here, to run repeatedly:
button.read(); // Continuously read the status of the button
}
void resetTimer(void)
{
// Function to reset the timer and state machine
}
/* END CODE */