Advertisement
pleasedontcode

"Counter Display" rev_01

Jun 9th, 2024
486
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: "Counter Display"
  13.     - Source Code NOT compiled for: Arduino Uno
  14.     - Source Code created on: 2024-06-10 03:13:01
  15.  
  16. ********* Pleasedontcode.com **********/
  17.  
  18. /****** SYSTEM REQUIREMENTS *****/
  19. /****** SYSTEM REQUIREMENT 1 *****/
  20.     /* Make a counter */
  21. /****** END SYSTEM REQUIREMENTS *****/
  22.  
  23. /****** DEFINITION OF LIBRARIES *****/
  24. #include <SevenSegmentDisplay.h>  // https://github.com/alikabeel/Letters-and-Numbers-Seven-Segment-Display-Library
  25. #include <EasyButton.h>  // https://github.com/evert-arias/EasyButton
  26.  
  27. /****** FUNCTION PROTOTYPES *****/
  28. void setup(void);
  29. void loop(void);
  30. void updateOutputs(void);
  31. void onPressed(void);
  32.  
  33. /***** DEFINITION OF DIGITAL INPUT PINS *****/
  34. const uint8_t myPushButton_PushButton_PIN_D10 = 10;
  35.  
  36. /***** DEFINITION OF DIGITAL OUTPUT PINS *****/
  37. const uint8_t Display_SevenSegmentDisplayWithCommonCathode_A_PIN_D2 = 2;
  38. const uint8_t Display_SevenSegmentDisplayWithCommonCathode_B_PIN_D3 = 3;
  39. const uint8_t Display_SevenSegmentDisplayWithCommonCathode_C_PIN_D4 = 4;
  40. const uint8_t Display_SevenSegmentDisplayWithCommonCathode_D_PIN_D5 = 5;
  41.  
  42. /***** DEFINITION OF OUTPUT RAW VARIABLES *****/
  43. /***** used to store raw data *****/
  44. bool Display_SevenSegmentDisplayWithCommonCathode_A_PIN_D2_rawData = 0;
  45. bool Display_SevenSegmentDisplayWithCommonCathode_B_PIN_D3_rawData = 0;
  46. bool Display_SevenSegmentDisplayWithCommonCathode_C_PIN_D4_rawData = 0;
  47. bool Display_SevenSegmentDisplayWithCommonCathode_D_PIN_D5_rawData = 0;
  48.  
  49. /***** DEFINITION OF OUTPUT PHYSICAL VARIABLES *****/
  50. /***** used to store data after characteristic curve transformation *****/
  51. float Display_SevenSegmentDisplayWithCommonCathode_A_PIN_D2_phyData = 0.0;
  52. float Display_SevenSegmentDisplayWithCommonCathode_B_PIN_D3_phyData = 0.0;
  53. float Display_SevenSegmentDisplayWithCommonCathode_C_PIN_D4_phyData = 0.0;
  54. float Display_SevenSegmentDisplayWithCommonCathode_D_PIN_D5_phyData = 0.0;
  55.  
  56. /****** DEFINITION OF LIBRARIES CLASS INSTANCES*****/
  57. EasyButton button(myPushButton_PushButton_PIN_D10);
  58. SevenSegmentDisplay display(Display_SevenSegmentDisplayWithCommonCathode_A_PIN_D2,
  59.                             Display_SevenSegmentDisplayWithCommonCathode_B_PIN_D3,
  60.                             Display_SevenSegmentDisplayWithCommonCathode_C_PIN_D4,
  61.                             Display_SevenSegmentDisplayWithCommonCathode_D5,
  62.                             6, 7, 8, 9, false);  // Assuming common cathode display
  63.  
  64. /****** COUNTER VARIABLE *****/
  65. int counter = 0;
  66.  
  67. void onPressed()
  68. {
  69.   Serial.println("Button pressed");
  70.   counter++;  // Increment the counter
  71.   if (counter > 9) counter = 0;  // Reset counter if it exceeds 9
  72.   display.displayCharacter('0' + counter);  // Display the counter value
  73. }
  74.  
  75. void setup(void)
  76. {
  77.   // put your setup code here, to run once:
  78.   Serial.begin(115200);
  79.   Serial.println();
  80.   Serial.println(">>> Seven Segment Display and Button Example <<<");
  81.  
  82.   pinMode(myPushButton_PushButton_PIN_D10, INPUT_PULLUP);
  83.  
  84.   pinMode(Display_SevenSegmentDisplayWithCommonCathode_A_PIN_D2, OUTPUT);
  85.   pinMode(Display_SevenSegmentDisplayWithCommonCathode_B_PIN_D3, OUTPUT);
  86.   pinMode(Display_SevenSegmentDisplayWithCommonCathode_C_PIN_D4, OUTPUT);
  87.   pinMode(Display_SevenSegmentDisplayWithCommonCathode_D_PIN_D5, OUTPUT);
  88.  
  89.   button.begin();
  90.   button.onPressed(onPressed);
  91. }
  92.  
  93. void loop(void)
  94. {
  95.   // put your main code here, to run repeatedly:
  96.   button.read();
  97.   updateOutputs(); // Refresh output data
  98. }
  99.  
  100. void updateOutputs()
  101. {
  102.   digitalWrite(Display_SevenSegmentDisplayWithCommonCathode_A_PIN_D2, Display_SevenSegmentDisplayWithCommonCathode_A_PIN_D2_rawData);
  103.   digitalWrite(Display_SevenSegmentDisplayWithCommonCathode_B_PIN_D3, Display_SevenSegmentDisplayWithCommonCathode_B_PIN_D3_rawData);
  104.   digitalWrite(Display_SevenSegmentDisplayWithCommonCathode_C_PIN_D4, Display_SevenSegmentDisplayWithCommonCathode_C_PIN_D4_rawData);
  105.   digitalWrite(Display_SevenSegmentDisplayWithCommonCathode_D_PIN_D5, Display_SevenSegmentDisplayWithCommonCathode_D_PIN_D5_rawData);
  106. }
  107.  
  108. /* END CODE */
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement