CCCPaste

LED Matrix rev_02

/********* Pleasedontcode.com **********

	Pleasedontcode thanks you for automatic code generation! Enjoy your code!

	- Terms and Conditions:
	You have a non-exclusive, revocable, worldwide, royalty-free license
	for personal and commercial use. Attribution is optional; modifications
	are allowed, but you're responsible for code maintenance. We're not
	liable for any loss or damage. For full terms,
	please visit pleasedontcode.com/termsandconditions.

	- Project: LED Matrix
	- Source Code compiled for: ESP32 DevKit V1
	- Source Code created on: 2024-04-03 04:54:42

********* Pleasedontcode.com **********/

/****** SYSTEM REQUIREMENTS *****/
/****** SYSTEM REQUIREMENT 1 *****/
	/* Generate a code which will blink 1 led in 3×3 led */
	/* matrix */
/****** SYSTEM REQUIREMENT 2 *****/
	/* Write a code for LED matrix which is connected */
	/* with ESP8266 pin D1,D2,D3 are connected with */
	/* negative terminal and D4,D5,D6 are connected with */
	/* positive write a code to blink led 1 to 9 in */
	/* sequence */
/****** END SYSTEM REQUIREMENTS *****/

/****** DEFINITION OF LIBRARIES *****/
#include 

/****** FUNCTION PROTOTYPES ******/
void setup(void);
void loop(void);
void updateOutputs(void);

/***** DEFINITION OF DIGITAL OUTPUT PINS *****/
const uint8_t Matrix_LED_PIN_D1 = 16; // Pin connected to negative terminal of LED 1
const uint8_t Matrix_LED_PIN_D2 = 17; // Pin connected to negative terminal of LED 2
const uint8_t Matrix_LED_PIN_D3 = 18; // Pin connected to negative terminal of LED 3
const uint8_t Matrix_LED_PIN_D4 = 19; // Pin connected to positive terminal of LED 1
const uint8_t Matrix_LED_PIN_D5 = 21; // Pin connected to positive terminal of LED 2
const uint8_t Matrix_LED_PIN_D6 = 22; // Pin connected to positive terminal of LED 3

/***** DEFINITION OF OUTPUT RAW VARIABLES *****/
bool Matrix_LED_PIN_D1_rawData = LOW;
bool Matrix_LED_PIN_D2_rawData = LOW;
bool Matrix_LED_PIN_D3_rawData = LOW;
bool Matrix_LED_PIN_D4_rawData = LOW;
bool Matrix_LED_PIN_D5_rawData = LOW;
bool Matrix_LED_PIN_D6_rawData = LOW;

/***** DEFINITION OF OUTPUT PHYSICAL VARIABLES *****/
float Matrix_LED_PIN_D1_phyData = 0.0;
float Matrix_LED_PIN_D2_phyData = 0.0;
float Matrix_LED_PIN_D3_phyData = 0.0;
float Matrix_LED_PIN_D4_phyData = 0.0;
float Matrix_LED_PIN_D5_phyData = 0.0;
float Matrix_LED_PIN_D6_phyData = 0.0;

/****** SYSTEM REQUIREMENTS *****/

/****** SYSTEM REQUIREMENT 1 *****/
/* Generate a code which will blink 1 led in 3x3 led matrix */
const uint8_t ledToBlink = 1; // LED number to blink
const uint32_t blinkDuration = 1000; // Blink duration in milliseconds

/****** SYSTEM REQUIREMENT 2 *****/
/* Write a code for LED matrix which is connected with ESP8266 pin D1,D2,D3 are connected with
   negative terminal and D4,D5,D6 are connected with positive write a code to blink led 1 to 9 in sequence */
const uint8_t startLed = 1; // Starting LED number
const uint8_t endLed = 9; // Ending LED number
const uint32_t sequenceDuration = 1000; // Duration to blink each LED in milliseconds

/****** END SYSTEM REQUIREMENTS *****/

void setup(void)
{
  // put your setup code here, to run once:
  pinMode(Matrix_LED_PIN_D1, OUTPUT);
  pinMode(Matrix_LED_PIN_D2, OUTPUT);
  pinMode(Matrix_LED_PIN_D3, OUTPUT);
  pinMode(Matrix_LED_PIN_D4, OUTPUT);
  pinMode(Matrix_LED_PIN_D5, OUTPUT);
  pinMode(Matrix_LED_PIN_D6, OUTPUT);
}

void loop(void)
{
  // put your main code here, to run repeatedly:
  
  /****** SYSTEM REQUIREMENT 1 *****/
  static uint32_t previousBlinkTime = 0;
  static bool ledBlinkState = LOW;
  
  if (millis() - previousBlinkTime >= blinkDuration)
  {
    previousBlinkTime = millis();
    ledBlinkState = !ledBlinkState;
    
    if (ledToBlink == 1)
      Matrix_LED_PIN_D1_rawData = ledBlinkState;
    else if (ledToBlink == 2)
      Matrix_LED_PIN_D2_rawData = ledBlinkState;
    else if (ledToBlink == 3)
      Matrix_LED_PIN_D3_rawData = ledBlinkState;
    
    updateOutputs();
  }
  
  /****** SYSTEM REQUIREMENT 2 *****/
  static uint8_t currentLed = startLed;
  static uint32_t previousSequenceTime = 0;
  static bool ledOnState = LOW;
  
  if (millis() - previousSequenceTime >= sequenceDuration)
  {
    previousSequenceTime = millis();
    ledOnState = !ledOnState;
    
    if (currentLed >= startLed && currentLed <= endLed)
    {
      if (currentLed == 1)
        Matrix_LED_PIN_D1_rawData = ledOnState;
      else if (currentLed == 2)
        Matrix_LED_PIN_D2_rawData = ledOnState;
      else if (currentLed == 3)
        Matrix_LED_PIN_D3_rawData = ledOnState;
      else if (currentLed == 4)
        Matrix_LED_PIN_D4_rawData = ledOnState;
      else if (currentLed == 5)
        Matrix_LED_PIN_D5_rawData = ledOnState;
      else if (currentLed == 6)
        Matrix_LED_PIN_D6_rawData = ledOnState;
      
      updateOutputs();
      
      currentLed++;
      
      if (currentLed > endLed)
        currentLed = startLed;
    }
  }
}

void updateOutputs(void)
{
  digitalWrite(Matrix_LED_PIN_D1, Matrix_LED_PIN_D1_rawData);
  digitalWrite(Matrix_LED_PIN_D2, Matrix_LED_PIN_D2_rawData);
  digitalWrite(Matrix_LED_PIN_D3, Matrix_LED_PIN_D3_rawData);
  digitalWrite(Matrix_LED_PIN_D4, Matrix_LED_PIN_D4_rawData);
  digitalWrite(Matrix_LED_PIN_D5, Matrix_LED_PIN_D5_rawData);
  digitalWrite(Matrix_LED_PIN_D6, Matrix_LED_PIN_D6_rawData);
}