驴友花雕 发表于 2022-11-13 19:18:14

实验场景图动态图



驴友花雕 发表于 2022-11-13 19:22:17

实验场景图



驴友花雕 发表于 2022-11-14 08:31:34

【Arduino】168种传感器模块系列实验(资料代码+仿真编程+图形编程)
实验二百二十:P6全彩LED模组 16X32显示屏单元板 P6-RGB-16X32-8S
室内全彩8扫电子屏(HX-P6-16X32-A)
项目程序之十:3个弹力球与流动文本“Arduino 16x32 RGB LED矩阵”

/*
【Arduino】168种传感器模块系列实验(资料代码+仿真编程+图形编程)
实验二百二十:P6全彩LED模组 16X32显示屏单元板 P6-RGB-16X32-8S
室内全彩8扫电子屏(HX-P6-16X32-A)
项目程序之十:3个弹力球与流动文本“Arduino 16x32 RGB LED矩阵”
*/

#include <Adafruit_GFX.h>   //核心图形库
#include <RGBmatrixPanel.h> //硬件特定库

#define CLK 8 //必须在这个端口上! (在Mega上使用PIN 11)
#define LAT A3
#define OE9
#define A   A0
#define B   A1
#define C   A2

//最后一个参数='false'禁用双缓冲
RGBmatrixPanel matrix(A, B, C, CLK, LAT, OE, false);
static const unsigned char PROGMEM bitmap = {0x02, 0x00, 0x01, 0x00, 0x02, 0x00, 0x01, 0x00, 0x02, 0x00, 0x01, 0x00, 0x7F, 0xFC, 0x01, 0x00, 0x04, 0x00, 0x21, 0x08, 0x09, 0x00, 0x21, 0x08, 0x11, 0x00, 0x21, 0x08, 0x21, 0x00, 0x21, 0x08, 0x3F, 0xF8, 0x21, 0x08, 0x01, 0x00, 0x21, 0x08, 0x09, 0x20, 0x21, 0x08, 0x11, 0x10, 0x21, 0x08, 0x21, 0x08, 0x21, 0x08, 0x41, 0x04, 0x3F, 0xF8, 0x05, 0x00, 0x00, 0x08, 0x02, 0x00, 0x00, 0x00};

#define F2(progmem_ptr) (const __FlashStringHelper *)progmem_ptr

const char str[] PROGMEM = "       Arduino 16x32 RGB LED Matrix";
int16_t    textX         = matrix.width(),
         textMin       = sizeof(str) * -12,
         hue         = 0;

int8_t ball = {
{3,0,1,1 }, //初始x速度3个弹力球
{ 17, 15,1, -1 },
{ 27,4, -1,1 }
};


static const uint16_t PROGMEM ballcolor = {
0x0080, // 绿色=1
0x0002, // 蓝色=1
0x1000// 红色=1
};

void setup() {
matrix.begin();
matrix.setTextWrap(false);
matrix.setTextSize(2);
}

void loop(){
byte i;

matrix.fillScreen(0);

for(i=0; i<3; i++) {
    matrix.fillCircle(ball, ball, 5, pgm_read_word(&ballcolor));
    ball += ball;
    ball += ball;
    if((ball == 0) || (ball == (matrix.width() - 1)))
      ball *= -1;
    if((ball == 0) || (ball == (matrix.height() - 1)))
      ball *= -1;
}

matrix.setTextColor(matrix.ColorHSV(hue, 255, 255, true));
matrix.setCursor(textX, 1);
matrix.print(F2(str));

if((--textX) < textMin) textX = matrix.width();
hue += 7;
if(hue >= 1536) hue -= 1536;

#if !defined(__AVR__)
delay(20);
#endif

matrix.swapBuffers(false);
}

驴友花雕 发表于 2022-11-14 08:34:37

实验场景图



驴友花雕 发表于 2022-11-14 08:57:10

实验场景图动态图



驴友花雕 发表于 2022-11-14 08:59:31


驴友花雕 发表于 2022-11-14 09:03:24

实验的视频记录
优酷:https://v.youku.com/v_show/id_XNTkxODE4ODg3Mg==.html?spm=a2hcb.playlsit.page.1
B站:https://www.bilibili.com/video/BV1Gd4y1k7Na/?vd_source=98c6b1fc23b2787403d97f8d3cc0b7e5

https://v.youku.com/v_show/id_XNTkxODE4ODg3Mg==.html?spm=a2hcb.playlsit.page.1

驴友花雕 发表于 2022-11-14 09:06:16

【Arduino】168种传感器模块系列实验(资料代码+仿真编程+图形编程)
实验二百二十:P6全彩LED模组 16X32显示屏单元板 P6-RGB-16X32-8S
室内全彩8扫电子屏(HX-P6-16X32-A)
项目程序之十一:尝试运行空气动力学的康威(Conways)生存游戏v1版本

/*
【Arduino】168种传感器模块系列实验(资料代码+仿真编程+图形编程)
实验二百二十:P6全彩LED模组 16X32显示屏单元板 P6-RGB-16X32-8S
室内全彩8扫电子屏(HX-P6-16X32-A)
项目程序之十一:尝试运行空气动力学的康威(Conways)生存游戏v1版本
*/

#include <Adafruit_GFX.h>   // Core graphics library
#include <RGBmatrixPanel.h> // Hardware-specific library
#include <EEPROM.h> // To store on EEPROM Memory

//Definition of the pattern if you use the pattern initialization
int pattern_size[] = {7, 22}; // row x Column
char pattern_init[] =
".........*,\
.......*.*,\
......*.*,\
**...*..*...........**,\
**....*.*...........**,\
.......*.*,\
.........*!";

bool WORLD; // Creation of the wordl
int step_GOL; //used to know the generation

//Definition of the LED Matrix Object
#define CLK 8// MUST be on PORTB! (Use pin 11 on Mega)
#define LAT A3
#define OE9
#define A   A0
#define B   A1
#define C   A2
// Last parameter = 'true' enables double-BUFFER_WORLDing, for flicker-free,
// buttery smooth animatrixion.Note that NOTHING WILL SHOW ON THE DISPLAY
// until the first call to swapBuffers().This is normal.

RGBmatrixPanel matrix(A, B, C, CLK, LAT, OE, false); //I couldn't use double buffering because it uses
//too much memory

void setup() {
//Serial.begin(115200); //use to print the game on the serial monitor (to debug)

//Randomly initialazing the world for the first step
randomSeed(analogRead(5));
for (byte i = 0; i < 16; i++) {
    for (byte j = 0; j < 32; j++) {
      WORLD = random(0, 2);
    }
}

//init_WORLD(); // Uncomment if you want to init with a specific pattern

step_GOL = 0;
matrix.begin();
print_WORLD(); //Display the first generation

}

void loop() {
if (step_GOL == 60) { // This if reboot the world after 60 generation to avoid static world
    step_GOL = 0;
    matrix.fillScreen(0);
    delay(500);
    randomSeed(analogRead(5));
    for (byte i = 0; i < 16; i++) {
      for (byte j = 0; j < 32; j++) {
      WORLD = random(0, 2);
      }
    }
}
//This double "for" is used to update the world to the next generation
//The buffer state is written on the EEPROM Memory

for (byte i = 0; i < 16; i++) {
    for (byte j = 0; j < 32; j++) {

      if (i == 0 || i == 15 || j == 0 || j == 31) // I choose to keep the border at 0
      {
      EEPROM.write(i * 31 + j , 0);
      }
      else {
      byte num_alive = WORLD + WORLD + WORLD + WORLD + WORLD + WORLD + WORLD + WORLD;
      bool state = WORLD;

      //RULE#1 if you are surrounded by 3 cells --> you live
      if (num_alive == 3) {
          EEPROM.write(i * 31 + j , 1);
      }
      //RULE#2 if you are surrounded by 2 cells --> you stay in your state
      else if (num_alive == 2) {
          EEPROM.write(i * 31 + j , state);
      }
      //RULE#3 otherwise you die from overpopulation or subpopulation
      else {
          EEPROM.write(i * 31 + j , 0);
      }
      }
    }
}

//Updating the World
for (byte i = 0; i < 16; i++) {
    for (byte j = 0; j < 32; j++) {
      WORLD = EEPROM.read(i * 31 + j);
    }
}

//Displaying the world
print_WORLD();

//Increasing the generation
step_GOL++;

}

// PRINT THE WORLD
void print_WORLD()
{
for (byte j = 0; j < 32; j++) {
    for (byte i = 0; i < 16; i++) {
      if (WORLD == 0) {
      matrix.drawPixel(j, i, matrix.Color333(0, 0, 0));
      }
      else
      {
      matrix.drawPixel(j, i, matrix.Color333(0, 1, 2));
      }
    }
}
}

//Those two function are used to display the world on the serial monitor
//Not beautiful but useful to debug

void print_WORLD_SERIAL()
{
clearscreen();
Serial.print("Step = "); Serial.println(step_GOL);
for (int i = 0; i < 16; i++) {
    for (int j = 0; j < 32; j++) {
      if (WORLD == 0) {
      Serial.print(".");
      Serial.print(" ");
      }
      else
      {
      Serial.print("*");
      Serial.print(" ");
      }
    }
    Serial.println("");
}
Serial.println("");

}

void clearscreen() {
for (int i = 0; i < 10; i++) {
    Serial.println("\n\n\n\n");
}
}

//This function is used to init the world with a know pattern
//It read . and * to convert them to 0 and 1.
//Inspired from life 1.05 format
// NB : this function needs improvment to center the pattern

void init_WORLD() {
int k = 0;
int row = 0;
int column = 0;
while (pattern_init != '!') {
    if (pattern_init == ',') {
      row++;
      k++;
      column = 0;
    }
    else if (pattern_init == '.') {
      WORLD = 0;
      k++;
      column ++;
    }
    else{
      WORLD = 1;
      k++;
      column ++;
    }
}
}

驴友花雕 发表于 2022-11-14 09:07:50

实验场景图动态图



驴友花雕 发表于 2022-11-14 09:11:22

实验的视频记录
优酷:https://v.youku.com/v_show/id_XNTkxODE5MDQ4NA==.html?spm=a2hcb.playlsit.page.3
B站:https://www.bilibili.com/video/BV1xW4y1s7bX/?vd_source=98c6b1fc23b2787403d97f8d3cc0b7e5

https://v.youku.com/v_show/id_XNTkxODE5MDQ4NA==.html?spm=a2hcb.playlsit.page.3

驴友花雕 发表于 2022-11-14 09:13:13

实验场景图



页: 1 2 3 [4]
查看完整版本: 【Arduino】168种传感器模块系列实验(220)---P6全彩16X32单元板