Advertisement
pleasedontcode

**Display Control** rev_01

Dec 6th, 2024
59
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: **Display Control**
  13.     - Source Code NOT compiled for: Arduino Uno
  14.     - Source Code created on: 2024-12-06 14:36:34
  15.  
  16. ********* Pleasedontcode.com **********/
  17.  
  18. /****** SYSTEM REQUIREMENTS *****/
  19. /****** SYSTEM REQUIREMENT 1 *****/
  20.     /* make the 7-segment display show the numbers 0 to 9 */
  21.     /* with the for loop */
  22. /****** END SYSTEM REQUIREMENTS *****/
  23.  
  24. /* START CODE */
  25.  
  26. /****** DEFINITION OF LIBRARIES *****/
  27.  
  28. /****** FUNCTION PROTOTYPES *****/
  29. void setup(void);
  30. void loop(void);
  31.  
  32. // USER CODE START
  33. int segA = 1;
  34. int segB = 2;
  35. int segC = 3;
  36. int segD = 4;
  37. int segE = 5;
  38. int segF = 6;
  39. int segG = 7;
  40.  
  41. // Array to represent the segments for numbers 0 to 9
  42. const int segmentMapping[10][7] = {
  43.     {1, 1, 1, 1, 1, 1, 0}, // 0
  44.     {0, 1, 0, 0, 0, 0, 0}, // 1
  45.     {1, 1, 0, 1, 1, 0, 1}, // 2
  46.     {1, 1, 1, 1, 0, 0, 1}, // 3
  47.     {0, 1, 1, 0, 0, 1, 1}, // 4
  48.     {1, 0, 1, 1, 0, 1, 1}, // 5
  49.     {1, 0, 1, 1, 1, 1, 1}, // 6
  50.     {1, 1, 0, 0, 0, 0, 0}, // 7
  51.     {1, 1, 1, 1, 1, 1, 1}, // 8
  52.     {1, 1, 1, 1, 0, 1, 1}  // 9
  53. };
  54. // USER CODE END
  55.  
  56. void setup(void)
  57. {
  58.     // put your setup code here, to run once:
  59.     pinMode(segA, OUTPUT);
  60.     pinMode(segB, OUTPUT);
  61.     pinMode(segC, OUTPUT);
  62.     pinMode(segD, OUTPUT);
  63.     pinMode(segE, OUTPUT);
  64.     pinMode(segF, OUTPUT);
  65.     pinMode(segG, OUTPUT);
  66. }
  67.  
  68. void loop(void)
  69. {
  70.     // put your main code here, to run repeatedly:
  71.     for (int i = 0; i < 10; i++) { // Loop from 0 to 9
  72.         // Set the segments according to the current number
  73.         digitalWrite(segA, segmentMapping[i][0]);
  74.         digitalWrite(segB, segmentMapping[i][1]);
  75.         digitalWrite(segC, segmentMapping[i][2]);
  76.         digitalWrite(segD, segmentMapping[i][3]);
  77.         digitalWrite(segE, segmentMapping[i][4]);
  78.         digitalWrite(segF, segmentMapping[i][5]);
  79.         digitalWrite(segG, segmentMapping[i][6]);
  80.         delay(1000); // Wait for 1 second before showing the next number
  81.     }
  82. }
  83.  
  84. /* END CODE */
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement