Advertisement
pleasedontcode

Project02 rev_22

Oct 14th, 2023
96
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:03:17
  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 upto 100000 */
  28.  
  29. /****** FUNCTION PROTOTYPES *****/
  30. void setup(void);
  31. void loop(void);
  32.  
  33. /***** DEFINITION OF DIGITAL INPUT PINS *****/
  34. const uint8_t pb2_PushButton_PIN_D2 = 2;
  35. const uint8_t myButton_PushButton_PIN_D3 = 3;
  36.  
  37. /***** DEFINITION OF DIGITAL OUTPUT PINS *****/
  38. const uint8_t l1_LED_PIN_D4 = 4;
  39.  
  40. /***** DEFINITION OF I2C PINS *****/
  41. const uint8_t Lcd_LCD1602I2C_I2C_PIN_SDA_A4 = A4;
  42. const uint8_t Lcd_LCD1602I2C_I2C_PIN_SCL_A5 = A5;
  43. const uint8_t Lcd_LCD1602I2C_I2C_SLAVE_ADDRESS = 39;
  44.  
  45. // Counter variable
  46. int counter = 0;
  47.  
  48. // LCD object
  49. LiquidCrystal_I2C lcd(Lcd_LCD1602I2C_I2C_SLAVE_ADDRESS, 16, 2);
  50.  
  51. // Button objects
  52. EasyButton pb2_PushButton(pb2_PushButton_PIN_D2);
  53. EasyButton myButton_PushButton(myButton_PushButton_PIN_D3);
  54.  
  55. void setup(void)
  56. {
  57.   // Initialize LCD
  58.   lcd.begin(16, 2);
  59.   lcd.print("Counter: ");
  60.   lcd.setCursor(0, 1);
  61.   lcd.print(counter);
  62.  
  63.   // Initialize buttons
  64.   pb2_PushButton.begin();
  65.   myButton_PushButton.begin();
  66.  
  67.   // Set LED pin as output
  68.   pinMode(l1_LED_PIN_D4, OUTPUT);
  69. }
  70.  
  71. void loop(void)
  72. {
  73.   // Update button states
  74.   pb2_PushButton.read();
  75.   myButton_PushButton.read();
  76.  
  77.   // Check if pb2_PushButton is pressed
  78.   if (pb2_PushButton.wasPressed())
  79.   {
  80.     // Increment counter
  81.     counter++;
  82.     if (counter > 100000)
  83.     {
  84.       counter = 0;
  85.     }
  86.  
  87.     // Update LCD display
  88.     lcd.setCursor(8, 1);
  89.     lcd.print("     ");
  90.     lcd.setCursor(8, 1);
  91.     lcd.print(counter);
  92.   }
  93.  
  94.   // Check if myButton_PushButton is pressed
  95.   if (myButton_PushButton.wasPressed())
  96.   {
  97.     // Toggle LED
  98.     digitalWrite(l1_LED_PIN_D4, !digitalRead(l1_LED_PIN_D4));
  99.   }
  100. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement