0

XRAD'S MATRIX DIGITAL RAIN
Moderators: adafruit_support_bill, adafruit

Please be positive and constructive with your questions and comments.

XRAD'S MATRIX DIGITAL RAIN

by XRAD on Sun Aug 01, 2021 10:56 am

So i was working on another lidar scanner project, and I need a cool intro screen. What's cooler than The Matrix?! So on to coding and hacking the one fragmented digital rain C++ code I could find on the net. It took a few hours, but I got nearly EXACTLY what the open scene shows including the WHITE character color on the leading end of 'rain drop.' there are a FEW exceptions: characters not in Japanese, and no sushi recipes, and MY code changes every character every loop (127 of them)) so I think it's very cool! I will post the code later as it is mixed in with my new RP lidar scanner code.

I am using an adafruit RA8875 processor w/480x272 tft, teensy 3.6. I also have some sound and led stuff going on....like all my projects....this one is more interactive than just code....

enjoy!

short vid:
https://www.youtube.com/watch?v=HB5vvQOc3wE



Although the image captures several WHITE characters per rain drop, it's visually just the "drop tip" that's white....
IMG_0652.JPG
IMG_0652.JPG (169.92 KiB) Viewed 73 times

XRAD
 
Posts: 644
Joined: Sat Nov 19, 2016 3:28 pm

Re: XRAD'S MATRIX DIGITAL RAIN

by adafruit_support_mike on Tue Aug 03, 2021 1:40 am

Nice! Thank for posting the video link.

adafruit_support_mike
 
Posts: 63670
Joined: Thu Feb 11, 2010 2:51 pm

Re: XRAD'S MATRIX DIGITAL RAIN

by XRAD on Fri Aug 06, 2021 6:46 am

Thx ada Mike! I tweeked the code a bit more for better fading trails. Here it is.....

Code: Select all | TOGGLE FULL SIZE
/*
  XRAD'S Matrix Digital Rain. Use as you like
  or make it better! 8,5,2021

  Some of the base code comes from here:
  https://www.youtube.com/watch?v=rE2FvkHDzQU

  However, I updated it to include fading trails,
  and 'random' characters, and white raindrop tips.....
  This sketch is set for a 480x272 tft...
*/



#include "Adafruit_GFX.h"
#include "Adafruit_RA8875.h"
#include <FastLED.h>

#define RA8875_INT     3
#define RA8875_RESET   9
#define RA8875_CS      10

#define width 480 //tft width
#define height 272 //tft height

int brightness = 255;   // how bright the LED is initially
int fadeAmount = 20;    // how many increments to fade the LED by


Adafruit_RA8875 tft = Adafruit_RA8875(RA8875_CS, RA8875_RESET);//



// Digital Rain colors...
#define  LightGreen   0x2FC0
#define  MedDarkGreen 0x26A0
#define  DarkerGreen  0x1420


/////////digital rain variables///////
int yRain[272];
int xRain;
int temp;
char zRain;
int brightnessRain = 0;   // how bright the TFTLED is initially
int fadeAmountRain = 10;    // how many increments to fade the TFTLED by


void digitalRain() {//fade in digital rain, make it rain, fade out digital rain
  for (int t = 0; t <= 250; t++) {
    if (t > 220) {
      EVERY_N_MILLISECONDS( 50 ) {
        brightnessRain = brightnessRain - fadeAmountRain;
        if (brightnessRain <= 0) {
          brightnessRain = 0;
        }
        tft.PWM1out(brightnessRain);
      }
    }
    else {
      EVERY_N_MILLISECONDS( 50 ) {
        brightnessRain = brightnessRain + fadeAmountRain;
        if (brightnessRain >= 255) {
          brightnessRain = 255;
        }
        tft.PWM1out(brightnessRain);
      }
    }
 
     

    //this is a repetitve x,y distribution per loop...but the characters always change...
    for (xRain = 0; xRain < width; xRain = xRain + 12) { //480/12 gives nice spacing

      temp = random(0, 12);

      if (temp <= 8) {//create some 'random' characters
        zRain = ('0' + random(0, 127));//ASCII digits/symbols/characters depends on GFX lib
      }

      else {
        zRain = (' ' + random(1, 80)); // spacing blanks
      }

      tft.textColor(LightGreen, RA8875_BLACK);
      tft.textSetCursor(xRain, yRain[xRain]);
      tft.print(zRain);



      temp = yRain[xRain] - 112; //  fading more
      if (temp < 0) {
        temp = temp +  height ;
      }
      else if (temp >= height) {
        temp = 0;
      }
      tft.textColor(DarkerGreen, RA8875_BLACK);
      tft.textSetCursor(xRain, temp);
      tft.print(zRain);


      temp = yRain[xRain] - 96; //  fading more
      if (temp < 0) {
        temp = temp +  height ;
      }
      else if (temp >= height) {
        temp = 0;
      }
      tft.textColor(DarkerGreen, RA8875_BLACK);
      tft.textSetCursor(xRain, temp);
      tft.print(zRain);

      temp = yRain[xRain] - 80; //   fading more
      if (temp < 0) {
        temp = temp +  height ;
      }
      else if (temp >= height) {
        temp = 0;
      }
      tft.textColor(MedDarkGreen, RA8875_BLACK);
      tft.textSetCursor(xRain, temp);
      tft.print(zRain);

      temp = yRain[xRain] - 64; // begin fading a few characters after leader
      if (temp < 0) {
        temp = temp +  height ;
      }
      else if (temp >= height) {
        temp = 0;
      }
      tft.textColor(MedDarkGreen, RA8875_BLACK);
      tft.textSetCursor(xRain, temp);
      tft.print(zRain);


      temp = yRain[xRain] + 16; //color the drop 'tip' WHITE
      if (temp < 0) {
        temp = temp +  height ;
      }
      else if (temp >= height) {
        temp = 0;
      }
      tft.textColor(RA8875_WHITE, RA8875_BLACK);
      tft.textSetCursor(xRain, temp);
      tft.print(zRain);


      temp = yRain[xRain] - 128;
      if (temp < 0) {
        temp = temp +  height ;
      }
      else if (temp >= height) {
        temp = 0;
      }
      tft.textSetCursor(xRain, temp);
      tft.print(" ");
      temp = yRain[xRain] + 16;

      if (temp < 0) {
        temp = temp + height;
      }
      else if (temp >= height) {
        temp = 0;
      }
      yRain[xRain] = temp;
      delay(1);
    }
  }
}

 

void setup() {
  Serial.begin(115200);
  delay(2000);

  if (!tft.begin(RA8875_480x272)) {
    Serial.println("LCD not found!");// ohhhh nooooo.....
    while (1);
  }
  Serial.println(F("LCD Initialized"));

  tft.displayOn(true);
  tft.GPIOX(true);      // Enable TFT - display enable tied to GPIOX
  tft.PWM1config(true, RA8875_PWM_CLK_DIV1024); // PWM output for backlight, can change this
  tft.PWM1out(255);  //brightest PWM

  tft.textMode(); // note this!!!!
  tft.textEnlarge(0);//use the small Adafruit GFX font with Adafruit RA8875 for this sketch...
  tft.fillScreen(RA8875_BLACK);
  tft.PWM1out(brightnessRain);
  delay(2000);


//create a different x,y digital rain pattern each boot....
  randomSeed(analogRead(0));
  for (xRain = 0; xRain < width; xRain = xRain + 12) {
    temp = random(0, height / 12) * 12;
    do {
      yRain[xRain] = random(0, height / 12) * 12;
    }
    while (temp != yRain[xRain]);
  }
}


///////////////////////////// LOOP/////////////////////

void loop() {
  digitalRain();
}

XRAD
 
Posts: 644
Joined: Sat Nov 19, 2016 3:28 pm

Re: XRAD'S MATRIX DIGITAL RAIN

by adafruit_support_mike on Sat Aug 07, 2021 8:24 pm

Cool! Thanks for posting it!

adafruit_support_mike
 
Posts: 63670
Joined: Thu Feb 11, 2010 2:51 pm

Please be positive and constructive with your questions and comments.