Advertisement
pleasedontcode

EasyButton Control rev_06

May 8th, 2024
756
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. /********* Pleasedontcode.com **********
  2.  
  3.     Pleasedontcode thanks you for automatic code generation! Enjoy your code!
  4.  
  5.     - Terms and Conditions:
  6.     You have a non-exclusive, revocable, worldwide, royalty-free license
  7.     for personal and commercial use. Attribution is optional; modifications
  8.     are allowed, but you're responsible for code maintenance. We're not
  9.     liable for any loss or damage. For full terms,
  10.     please visit pleasedontcode.com/termsandconditions.
  11.  
  12.     - Project: EasyButton Control
  13.     - Source Code NOT compiled for: Arduino Uno
  14.     - Source Code created on: 2024-05-08 17:46:39
  15.  
  16. ********* Pleasedontcode.com **********/
  17.  
  18. /****** SYSTEM REQUIREMENTS *****/
  19. /****** SYSTEM REQUIREMENT 1 *****/
  20.     /* The project must control a timer that starts when */
  21.     /* the infrared sensor is in a low active state and */
  22.     /* stops when the sensor returns to a low active */
  23.     /* state. The timer must be displayed on the LCD */
  24.     /* screen. */
  25. /****** SYSTEM REQUIREMENT 2 *****/
  26.     /* The timer state should be handled using a state */
  27.     /* machine. Furthermore, an explicit function called */
  28.     /* 'resetTimer' needs to be implemented to reset the */
  29.     /* counter and state of the state machine. */
  30. /****** END SYSTEM REQUIREMENTS *****/
  31.  
  32. /****** DEFINITION OF LIBRARIES *****/
  33. #include <Wire.h>
  34. #include <LiquidCrystal_I2C.h>    // https://github.com/marcoschwartz/LiquidCrystal_I2C
  35. #include <EasyButton.h>    // https://github.com/evert-arias/EasyButton
  36.  
  37. /****** FUNCTION PROTOTYPES *****/
  38. void setup(void);
  39. void loop(void);
  40. void resetTimer(void);
  41.  
  42. /***** DEFINITION OF DIGITAL INPUT PINS *****/
  43. const uint8_t sensorInfrared_PushButton_PIN_D2 = 2;
  44.  
  45. /***** DEFINITION OF I2C PINS *****/
  46. const uint8_t display_LCD1602I2C_I2C_PIN_SDA_A4 = A4;
  47. const uint8_t display_LCD1602I2C_I2C_PIN_SCL_A5 = A5;
  48. const uint8_t display_LCD1602I2C_I2C_SLAVE_ADDRESS = 39;
  49.  
  50. /****** DEFINITION OF LIBRARIES CLASS INSTANCES*****/
  51. LiquidCrystal_I2C lcd(display_LCD1602I2C_I2C_SLAVE_ADDRESS, 20, 4); // Initialize LiquidCrystal_I2C object
  52. EasyButton button(sensorInfrared_PushButton_PIN_D2); // Initialize EasyButton object
  53.  
  54. void onPressedForDuration()
  55. {
  56.   // Code to be executed when the button is pressed for the given duration.
  57. }
  58.  
  59. void setup(void)
  60. {
  61.     // put your setup code here, to run once:
  62.     pinMode(sensorInfrared_PushButton_PIN_D2, INPUT_PULLUP);
  63.  
  64.     lcd.init(); // Initialize the LCD
  65.     lcd.backlight(); // Turn on the backlight
  66.  
  67.     // Initialize the button
  68.     button.begin();
  69.     // Add the callback function to be called when the button is pressed for at least the given time
  70.     button.onPressedFor(2000, onPressedForDuration);
  71. }
  72.  
  73. void loop(void)
  74. {
  75.     // put your main code here, to run repeatedly:
  76.     button.read(); // Continuously read the status of the button
  77. }
  78.  
  79. void resetTimer(void)
  80. {
  81.     // Function to reset the timer and state machine
  82. }
  83.  
  84. /* END CODE */
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement