Advertisement
pleasedontcode

Project02 rev_21

Oct 14th, 2023
104
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 20:53:36
  15.     - Source Code generated by: AlexWind
  16.  
  17. ********* Pleasedontcode.com **********/
  18.  
  19. /********* User code review feedback **********
  20. #### Feedback 1 ####
  21. - complete coding of system requirements
  22. ********* User code review feedback **********/
  23.  
  24. /****** DEFINITION OF LIBRARIES *****/
  25. #include <Arduino.h>
  26. #include <Wire.h>
  27. #include <EasyButton.h>
  28. #include <LiquidCrystal_I2C.h>
  29.  
  30. /****** SYSTEM REQUIREMENT 1 *****/
  31. // Count display on lcd with push button press
  32.  
  33. /****** SYSTEM REQUIREMENT 2 *****/
  34. // Counter up to 100000
  35.  
  36. /****** FUNCTION PROTOTYPES *****/
  37. void setup(void);
  38. void loop(void);
  39.  
  40. /***** DEFINITION OF DIGITAL INPUT PINS *****/
  41. const uint8_t pb2_PushButton_PIN_D2 = 2;
  42. const uint8_t myButton_PushButton_PIN_D3 = 3;
  43.  
  44. /***** DEFINITION OF DIGITAL OUTPUT PINS *****/
  45. const uint8_t l1_LED_PIN_D4 = 4;
  46.  
  47. /***** DEFINITION OF I2C PINS *****/
  48. const uint8_t Lcd_LCD1602I2C_I2C_PIN_SDA_A4 = A4;
  49. const uint8_t Lcd_LCD1602I2C_I2C_PIN_SCL_A5 = A5;
  50. const uint8_t Lcd_LCD1602I2C_I2C_SLAVE_ADDRESS = 39;
  51.  
  52. // Counter variable
  53. unsigned int counter = 0;
  54.  
  55. // LCD object
  56. LiquidCrystal_I2C lcd(Lcd_LCD1602I2C_I2C_SLAVE_ADDRESS, Lcd_LCD1602I2C_I2C_PIN_SDA_A4, Lcd_LCD1602I2C_I2C_PIN_SCL_A5);
  57.  
  58. void setup(void)
  59. {
  60.     // put your setup code here, to run once:
  61.  
  62.     pinMode(pb2_PushButton_PIN_D2, INPUT_PULLUP);
  63.     pinMode(myButton_PushButton_PIN_D3, INPUT_PULLUP);
  64.  
  65.     pinMode(l1_LED_PIN_D4, OUTPUT);
  66.  
  67.     lcd.begin(16, 2); // Initialize the LCD with 16 columns and 2 rows
  68.     lcd.backlight(); // Turn on the LCD backlight
  69.     lcd.setCursor(0, 0); // Set the cursor to the first column of the first row
  70.     lcd.print("Counter:"); // Print the initial text on the LCD
  71.  
  72. }
  73.  
  74.  
  75. void loop(void)
  76. {
  77.     // put your main code here, to run repeatedly:
  78.    
  79.     // Check if the push button is pressed
  80.     if (digitalRead(pb2_PushButton_PIN_D2) == LOW)
  81.     {
  82.         // Increment the counter
  83.         counter++;
  84.  
  85.         // Check if the counter exceeds 100000
  86.         if (counter > 100000)
  87.         {
  88.             counter = 0; // Reset the counter if it exceeds 100000
  89.         }
  90.  
  91.         // Update the LCD display with the new counter value
  92.         lcd.setCursor(8, 1); // Set the cursor to the ninth column of the second row
  93.         lcd.print("     "); // Clear the previous counter value
  94.         lcd.setCursor(8, 1); // Set the cursor to the ninth column of the second row
  95.         lcd.print(counter); // Print the new counter value
  96.  
  97.         // Blink the LED to indicate button press
  98.         digitalWrite(l1_LED_PIN_D4, HIGH);
  99.         delay(100);
  100.         digitalWrite(l1_LED_PIN_D4, LOW);
  101.         delay(100);
  102.     }
  103. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement