【雕爷学编程】Arduino动手做(209)--- P6 室内全彩8扫电子屏之尝试运行空气动力学的康威(Conways)生存游戏v1版本

在这里插入图片描述

37款传感器与模块的提法,在网络上广泛流传,其实Arduino能够兼容的传感器模块肯定是不止37种的。鉴于本人手头积累了一些传感器和模块,依照实践(动手试试)出真知的理念,以学习和交流为目的,这里准备逐一做做实验,不管能否成功,都会记录下来—小小的进步或是搞不掂的问题,希望能够抛砖引玉。

【Arduino】168种传感器模块系列实验(资料代码+仿真编程+图形编程)
实验二百零九:P6全彩LED模组 16X32显示屏单元板 P6-RGB-16X32-8S室内全彩8扫电子屏(HX-P6-16X32-A)

在这里插入图片描述
在这里插入图片描述

HUB75接口,是个兼容大部分市面LED单元板的通用型接口,具体接线定义有些不同,比如HUB75B\HUB75E等。

这次自制的扩展板,只是专门匹配Arduino UNO开发板的专用板,由于性能限制,最多只能使用32x16,或者32x32的简单控制。

下一张扩展板,准备尝试搭配ESP32开发板,以适应大部分P5\P4\P3的单元板模组,主要规格可能有32x32\64x32\64x64,还有128x64等。

在这里插入图片描述

在这里插入图片描述

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

Arduino实验开源代码

/*
  【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[16][32]; // 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 OE  9
#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[i][j] = 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[i][j] = 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[i - 1][j - 1] + WORLD[i - 1][j] + WORLD[i - 1][j + 1] + WORLD[i][j - 1] + WORLD[i][j + 1] + WORLD[i + 1][j - 1] + WORLD[i + 1][j] + WORLD[i + 1][j + 1];
        bool state = WORLD[i][j];

        //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[i][j] = 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[i][j] == 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[i][j] == 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[k] != '!') {
    if (pattern_init[k] == ',') {
      row++;
      k++;
      column = 0;
    }
    else if (pattern_init[k] == '.') {
      WORLD[row + 2][column + 4] = 0;
      k++;
      column ++;
    }
    else  {
      WORLD[row + 2][column + 4] = 1;
      k++;
      column ++;
    }
  }
}

实验场景图 动态图

在这里插入图片描述

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

在这里插入图片描述

实验场景图

在这里插入图片描述
在这里插入图片描述

在这里插入图片描述

  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论
编程Arduino动手寻迹的实验可以使用TCRT5000红外反射光电开关寻迹传感器模块。这个传感器模块可以通过检测周围的光反射来进行寻迹操作。你可以将这个模块连接到mBot的主控板mCore V1.5的RJ25接口上,因为mBot的主控板兼容Arduino系统,所以你可以使用Arduino编程语言来控制mBot进行寻迹操作。请参考【Arduino】168种传感器模块系列实验中的实验六十六,该实验详细介绍了如何使用TCRT5000红外反射光电开关寻迹传感器模块进行寻迹。祝你成功完成实验!<span class="em">1</span><span class="em">2</span><span class="em">3</span> #### 引用[.reference_title] - *1* *2* [【编程Arduino动手(194)---makeblock mbot 主控板2](https://blog.csdn.net/weixin_41659040/article/details/132141677)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v92^chatsearchT0_1"}}] [.reference_item style="max-width: 50%"] - *3* [【编程Arduino动手(65)---红外寻迹传感器](https://blog.csdn.net/weixin_41659040/article/details/106604080)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v92^chatsearchT0_1"}}] [.reference_item style="max-width: 50%"] [ .reference_list ]

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

驴友花雕

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值