Flashing Heart on Uno R4 WiFi

Flashing Heart on Nologo Uno R4 WiFi:


UnoR4_Heart.ino
/*
  Display Heart on Uno R4 using Matrix Frame Buffer
*/

// Include the LED_Matrix library
#include "Arduino_LED_Matrix.h"  

// Create an instance of the ArduinoLEDMatrix class
ArduinoLEDMatrix matrix;        


const int num_of_row = 8;
const int num_of_col = 12;
const int max_random = 1000;

// Define the frame array for the LED matrix with pixel values
uint8_t mask_matrix[8][12];
uint8_t heart[8][12] = {
  { 0, 0, 1, 1, 0, 0, 0, 1, 1, 0, 0, 0 }, 
  { 0, 1, 1, 1, 1, 0, 1, 1, 1, 1, 0, 0 },
  { 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0 },
  { 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0 },
  { 0, 0, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0 },
  { 0, 0, 0, 1, 1, 1, 1, 1, 0, 0, 0, 0 },
  { 0, 0, 0, 0, 1, 1, 1, 0, 0, 0, 0, 0 },
  { 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0 }
};

uint8_t result_matrix[8][12];

#define ROWS 8
#define COLUMNS 12

void reRandomMask(int margin){
  for (int r=0; r<num_of_row; r++){
    for (int c=0; c<num_of_col; c++){
      long randomNum = random(max_random);
      if (randomNum <= margin)
        mask_matrix[r][c] = 1;
      else
        mask_matrix[r][c] = 0;
    }
  }
}

void mask_AND_heart(){
  for (int r=0; r<num_of_row; r++){
    for (int c=0; c<num_of_col; c++){
      if (mask_matrix[r][c])
        result_matrix[r][c] = heart[r][c];
      else
        result_matrix[r][c] = 0;
    }
  }
}

void flashingHeart(){
  for(int m=1; m<=max_random; m++){
    reRandomMask(m);
    mask_AND_heart();
    matrix.renderBitmap(result_matrix, 8, 12);
    delay(10);
  }
  
}

void setup() {
  // Initialize serial communication and delaying for setup
  Serial.begin(115200);
  delay(1500);

  // Initialize the LED matrix
  matrix.begin();
  
}

void loop() {
  flashingHeart();
  delay(5000);
}

Comments

Popular posts from this blog

MicroPython/ESP32-C3 + 1.8" 128x160 TFT ST7735 SPI, using boochow/MicroPython-ST7735 library.

CameraWebServe: ESP32-S3 (arduino-esp32) + OV5640 camera module