Advertisement
pleasedontcode

LED Matrix rev_02

Apr 2nd, 2024
115
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: LED Matrix
  13.     - Source Code compiled for: ESP32 DevKit V1
  14.     - Source Code created on: 2024-04-03 04:54:42
  15.  
  16. ********* Pleasedontcode.com **********/
  17.  
  18. /****** SYSTEM REQUIREMENTS *****/
  19. /****** SYSTEM REQUIREMENT 1 *****/
  20.     /* Generate a code which will blink 1 led in 3×3 led */
  21.     /* matrix */
  22. /****** SYSTEM REQUIREMENT 2 *****/
  23.     /* Write a code for LED matrix which is connected */
  24.     /* with ESP8266 pin D1,D2,D3 are connected with */
  25.     /* negative terminal and D4,D5,D6 are connected with */
  26.     /* positive write a code to blink led 1 to 9 in */
  27.     /* sequence */
  28. /****** END SYSTEM REQUIREMENTS *****/
  29.  
  30. /****** DEFINITION OF LIBRARIES *****/
  31. #include <Arduino.h>
  32.  
  33. /****** FUNCTION PROTOTYPES ******/
  34. void setup(void);
  35. void loop(void);
  36. void updateOutputs(void);
  37.  
  38. /***** DEFINITION OF DIGITAL OUTPUT PINS *****/
  39. const uint8_t Matrix_LED_PIN_D1 = 16; // Pin connected to negative terminal of LED 1
  40. const uint8_t Matrix_LED_PIN_D2 = 17; // Pin connected to negative terminal of LED 2
  41. const uint8_t Matrix_LED_PIN_D3 = 18; // Pin connected to negative terminal of LED 3
  42. const uint8_t Matrix_LED_PIN_D4 = 19; // Pin connected to positive terminal of LED 1
  43. const uint8_t Matrix_LED_PIN_D5 = 21; // Pin connected to positive terminal of LED 2
  44. const uint8_t Matrix_LED_PIN_D6 = 22; // Pin connected to positive terminal of LED 3
  45.  
  46. /***** DEFINITION OF OUTPUT RAW VARIABLES *****/
  47. bool Matrix_LED_PIN_D1_rawData = LOW;
  48. bool Matrix_LED_PIN_D2_rawData = LOW;
  49. bool Matrix_LED_PIN_D3_rawData = LOW;
  50. bool Matrix_LED_PIN_D4_rawData = LOW;
  51. bool Matrix_LED_PIN_D5_rawData = LOW;
  52. bool Matrix_LED_PIN_D6_rawData = LOW;
  53.  
  54. /***** DEFINITION OF OUTPUT PHYSICAL VARIABLES *****/
  55. float Matrix_LED_PIN_D1_phyData = 0.0;
  56. float Matrix_LED_PIN_D2_phyData = 0.0;
  57. float Matrix_LED_PIN_D3_phyData = 0.0;
  58. float Matrix_LED_PIN_D4_phyData = 0.0;
  59. float Matrix_LED_PIN_D5_phyData = 0.0;
  60. float Matrix_LED_PIN_D6_phyData = 0.0;
  61.  
  62. /****** SYSTEM REQUIREMENTS *****/
  63.  
  64. /****** SYSTEM REQUIREMENT 1 *****/
  65. /* Generate a code which will blink 1 led in 3x3 led matrix */
  66. const uint8_t ledToBlink = 1; // LED number to blink
  67. const uint32_t blinkDuration = 1000; // Blink duration in milliseconds
  68.  
  69. /****** SYSTEM REQUIREMENT 2 *****/
  70. /* Write a code for LED matrix which is connected with ESP8266 pin D1,D2,D3 are connected with
  71.    negative terminal and D4,D5,D6 are connected with positive write a code to blink led 1 to 9 in sequence */
  72. const uint8_t startLed = 1; // Starting LED number
  73. const uint8_t endLed = 9; // Ending LED number
  74. const uint32_t sequenceDuration = 1000; // Duration to blink each LED in milliseconds
  75.  
  76. /****** END SYSTEM REQUIREMENTS *****/
  77.  
  78. void setup(void)
  79. {
  80.   // put your setup code here, to run once:
  81.   pinMode(Matrix_LED_PIN_D1, OUTPUT);
  82.   pinMode(Matrix_LED_PIN_D2, OUTPUT);
  83.   pinMode(Matrix_LED_PIN_D3, OUTPUT);
  84.   pinMode(Matrix_LED_PIN_D4, OUTPUT);
  85.   pinMode(Matrix_LED_PIN_D5, OUTPUT);
  86.   pinMode(Matrix_LED_PIN_D6, OUTPUT);
  87. }
  88.  
  89. void loop(void)
  90. {
  91.   // put your main code here, to run repeatedly:
  92.  
  93.   /****** SYSTEM REQUIREMENT 1 *****/
  94.   static uint32_t previousBlinkTime = 0;
  95.   static bool ledBlinkState = LOW;
  96.  
  97.   if (millis() - previousBlinkTime >= blinkDuration)
  98.   {
  99.     previousBlinkTime = millis();
  100.     ledBlinkState = !ledBlinkState;
  101.    
  102.     if (ledToBlink == 1)
  103.       Matrix_LED_PIN_D1_rawData = ledBlinkState;
  104.     else if (ledToBlink == 2)
  105.       Matrix_LED_PIN_D2_rawData = ledBlinkState;
  106.     else if (ledToBlink == 3)
  107.       Matrix_LED_PIN_D3_rawData = ledBlinkState;
  108.    
  109.     updateOutputs();
  110.   }
  111.  
  112.   /****** SYSTEM REQUIREMENT 2 *****/
  113.   static uint8_t currentLed = startLed;
  114.   static uint32_t previousSequenceTime = 0;
  115.   static bool ledOnState = LOW;
  116.  
  117.   if (millis() - previousSequenceTime >= sequenceDuration)
  118.   {
  119.     previousSequenceTime = millis();
  120.     ledOnState = !ledOnState;
  121.    
  122.     if (currentLed >= startLed && currentLed <= endLed)
  123.     {
  124.       if (currentLed == 1)
  125.         Matrix_LED_PIN_D1_rawData = ledOnState;
  126.       else if (currentLed == 2)
  127.         Matrix_LED_PIN_D2_rawData = ledOnState;
  128.       else if (currentLed == 3)
  129.         Matrix_LED_PIN_D3_rawData = ledOnState;
  130.       else if (currentLed == 4)
  131.         Matrix_LED_PIN_D4_rawData = ledOnState;
  132.       else if (currentLed == 5)
  133.         Matrix_LED_PIN_D5_rawData = ledOnState;
  134.       else if (currentLed == 6)
  135.         Matrix_LED_PIN_D6_rawData = ledOnState;
  136.      
  137.       updateOutputs();
  138.      
  139.       currentLed++;
  140.      
  141.       if (currentLed > endLed)
  142.         currentLed = startLed;
  143.     }
  144.   }
  145. }
  146.  
  147. void updateOutputs(void)
  148. {
  149.   digitalWrite(Matrix_LED_PIN_D1, Matrix_LED_PIN_D1_rawData);
  150.   digitalWrite(Matrix_LED_PIN_D2, Matrix_LED_PIN_D2_rawData);
  151.   digitalWrite(Matrix_LED_PIN_D3, Matrix_LED_PIN_D3_rawData);
  152.   digitalWrite(Matrix_LED_PIN_D4, Matrix_LED_PIN_D4_rawData);
  153.   digitalWrite(Matrix_LED_PIN_D5, Matrix_LED_PIN_D5_rawData);
  154.   digitalWrite(Matrix_LED_PIN_D6, Matrix_LED_PIN_D6_rawData);
  155. }
  156.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement