Advertisement
pleasedontcode

Project02 rev_23

Oct 14th, 2023
107
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: Project02
  13.     - Source Code compiled for: Arduino Uno
  14.     - Source Code created on: 2023-10-14 21:05:12
  15.     - Source Code generated by: AlexWind
  16.  
  17. ********* Pleasedontcode.com **********/
  18. /****** DEFINITION OF LIBRARIES *****/
  19. #include <Arduino.h>
  20. #include <Wire.h>
  21. #include <EasyButton.h>
  22. #include <LiquidCrystal_I2C.h>
  23.  
  24. /****** SYSTEM REQUIREMENT 1 *****/
  25. /* Count display on lcd with push button press */
  26. /****** SYSTEM REQUIREMENT 2 *****/
  27. /* Counter up to 100000 */
  28.  
  29. /****** FUNCTION PROTOTYPES *****/
  30. void setup(void);
  31. void loop(void);
  32. void updateCounter(int count);
  33.  
  34. /***** DEFINITION OF DIGITAL INPUT PINS *****/
  35. const uint8_t pb2_PushButton_PIN_D2 = 2;
  36. const uint8_t myButton_PushButton_PIN_D3 = 3;
  37.  
  38. /***** DEFINITION OF DIGITAL OUTPUT PINS *****/
  39. const uint8_t l1_LED_PIN_D4 = 4;
  40.  
  41. /***** DEFINITION OF I2C PINS *****/
  42. const uint8_t Lcd_LCD1602I2C_I2C_PIN_SDA_A4 = A4;
  43. const uint8_t Lcd_LCD1602I2C_I2C_PIN_SCL_A5 = A5;
  44. const uint8_t Lcd_LCD1602I2C_I2C_SLAVE_ADDRESS = 0x27; // Change the address if necessary
  45.  
  46. // Global variables
  47. int counter = 0;
  48. LiquidCrystal_I2C lcd(Lcd_LCD1602I2C_I2C_SLAVE_ADDRESS, 16, 2); // Initialize LCD object
  49.  
  50. EasyButton pb2(pb2_PushButton_PIN_D2); // Initialize EasyButton object for pb2
  51. EasyButton myButton(myButton_PushButton_PIN_D3); // Initialize EasyButton object for myButton
  52.  
  53. void setup(void)
  54. {
  55.   // Initialize LCD
  56.   lcd.begin(16, 2);
  57.   lcd.print("Counter: ");
  58.   lcd.setCursor(0, 1);
  59.   lcd.print(counter);
  60.  
  61.   // Initialize buttons
  62.   pb2.begin();
  63.   myButton.begin();
  64.  
  65.   // Set LED pin as output
  66.   pinMode(l1_LED_PIN_D4, OUTPUT);
  67. }
  68.  
  69. void loop(void)
  70. {
  71.   // Update buttons
  72.   pb2.read();
  73.   myButton.read();
  74.  
  75.   // Check if pb2 button is pressed
  76.   if (pb2.wasPressed())
  77.   {
  78.     counter++;
  79.     updateCounter(counter);
  80.   }
  81.  
  82.   // Check if myButton button is pressed
  83.   if (myButton.wasPressed())
  84.   {
  85.     counter = 0;
  86.     updateCounter(counter);
  87.   }
  88. }
  89.  
  90. void updateCounter(int count)
  91. {
  92.   lcd.setCursor(9, 1);
  93.   lcd.print("     "); // Clear previous counter value
  94.   lcd.setCursor(9, 1);
  95.   lcd.print(count);
  96. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement