PLAYSTATION PICO III

ESP32 + 16×16 RGB LED MATRIX


#include <FastLED.h>
 
#include <Adafruit_GFX.h>
#include <Adafruit_NeoMatrix.h>
#include <Adafruit_NeoPixel.h>
 
 
 
 
uint16_t speed = 8;
uint16_t noise[16][16];
uint16_t scale = 80;
 
static uint16_t x;
static uint16_t y;
static uint16_t z;
 
#define PIN 13
 
// MATRIX DECLARATION:
// Parameter 1 = width of NeoPixel matrix
// Parameter 2 = height of matrix
// Parameter 3 = pin number (most are valid)
// Parameter 4 = matrix layout flags, add together as needed:
//   NEO_MATRIX_TOP, NEO_MATRIX_BOTTOM, NEO_MATRIX_LEFT, NEO_MATRIX_RIGHT:
//     Position of the FIRST LED in the matrix; pick two, e.g.
//     NEO_MATRIX_TOP + NEO_MATRIX_LEFT for the top-left corner.
//   NEO_MATRIX_ROWS, NEO_MATRIX_COLUMNS: LEDs are arranged in horizontal
//     rows or in vertical columns, respectively; pick one or the other.
//   NEO_MATRIX_PROGRESSIVE, NEO_MATRIX_ZIGZAG: all rows/columns proceed
//     in the same order, or alternate lines reverse direction; pick one.
//   See example below for these values in action.
// Parameter 5 = pixel type flags, add together as needed:
//   NEO_KHZ800  800 KHz bitstream (most NeoPixel products w/WS2812 LEDs)
//   NEO_KHZ400  400 KHz (classic 'v1' (not v2) FLORA pixels, WS2811 drivers)
//   NEO_GRB     Pixels are wired for GRB bitstream (most NeoPixel products)
//   NEO_GRBW    Pixels are wired for GRBW bitstream (RGB+W NeoPixel products)
//   NEO_RGB     Pixels are wired for RGB bitstream (v1 FLORA pixels, not v2)
 
 
// Example for NeoPixel Shield.  In this application we'd like to use it
// as a 5x8 tall matrix, with the USB port positioned at the top of the
// Arduino.  When held that way, the first pixel is at the top right, and
// lines are arranged in columns, progressive order.  The shield uses
// 800 KHz (v2) pixels that expect GRB color data.
Adafruit_NeoMatrix matrix = Adafruit_NeoMatrix(16, 16, PIN,
  NEO_MATRIX_TOP     + NEO_MATRIX_RIGHT +
  NEO_MATRIX_COLUMNS + NEO_MATRIX_ZIGZAG,
  NEO_GRB            + NEO_KHZ800);
 
const uint16_t colors[] = {
  matrix.Color(255, 0, 0), matrix.Color(0, 255, 0), matrix.Color(0, 0, 255) };
 
 
const uint16_t palette_colors[] = {
  matrix.Color(255, 0, 222), // 0 red
  matrix.Color(0, 22, 0), // 1 green 
  matrix.Color(0, 0, 155) // 2 blue
  };
 
 
void setup() {
 
 // Initialize our coordinates to some random values
  x = random16();
  y = random16();
  z = random16();
 
   
  matrix.begin();
  //matrix.setTextWrap(false);
  matrix.setBrightness(90);
  matrix.setTextColor(colors[0]);
}
 
//int x = matrix.width();
//int pass = 0;
 
float tick = 0;
 
int id_buffer[256];
 
void getNewFrame(){
 
  int idtick = 0;
 
  for(int y=0;y<16;y++){
    for(int xi=0;xi<16;xi++){
 
    int cid = int(random(3));
 
      id_buffer[idtick] = cid;
      idtick++;
    }
  }
   
}
 
 
void drawFrame(){
   
  int idtick = 0;
  fillnoise8();
 
  for(int y=0;y<16;y++){
  for(int xi=0;xi<16;xi++){
 
   
    //int dcid = id_buffer[idtick];
 
    int dcid = round(noise[y][xi] * 3 );
 
    int n = round(noise[y][xi] * 255 );
    int n2 = round(noise[xi*2][y] * 255 );
 
    //n *= 2;
 
    //if( n>254 ){ n =2 54; }
     
    //matrix.drawPixel(xi, y, palette_colors[dcid]  );
     
    matrix.drawPixel(xi, y, matrix.Color(n,0,n2)  );
    idtick++;
   }
  }
   
}
 
void loop() {
 
  
 // matrix.fillScreen(0);
 
  //getNewFrame();
  drawFrame();
  
    
  matrix.show();
  delay(3);
}
 
// #######################################
 
 
// Fill the x/y array of 8-bit noise values using the inoise8 function.
void fillnoise8() {
  for(int i = 0; i < 16; i++) {
    int ioffset = scale * i;
    for(int j = 0; j < 16; j++) {
      int joffset = scale * j;
      noise[i][j] = inoise8(x + ioffset,y + joffset,z);
    }
  }
  z += speed;
}
 
// ----------------------------------------------
 
void draw_procedural(){
   
  tick +=.19;
  for(int y=0;y<16;y++){
  for(int xi=0;xi<8;xi++){
  
   
 
    float n = (sin( y*.81 + tick*.41 )+1)*95;
    float n2 = (sin( xi*.6 + y*.92  + tick*.2 )+1)*120;
 
    float n3 = (sin( xi*.81 + y*.942  + tick*.3 )+1)*120;
 
   // n = sin(n);
     
  
    matrix.drawPixel(xi, y, matrix.Color(n, n3, n2));
    matrix.drawPixel(15-xi, y, matrix.Color(n, n3, n2));
     
  }
   }
 
   
   
 }