8289浏览
楼主: 驴友花雕

[项目] 【Arduino】168种传感器模块系列实验(220)---P6全彩16X32单元板

[复制链接]

驴友花雕  中级技神
 楼主|

发表于 2022-11-13 19:18:14

实验场景图  动态图

【Arduino】168种传感器模块系列实验(220)---P6全彩16X32单元板图1

回复

使用道具 举报

驴友花雕  中级技神
 楼主|

发表于 2022-11-13 19:22:17

实验场景图

【Arduino】168种传感器模块系列实验(220)---P6全彩16X32单元板图1

回复

使用道具 举报

驴友花雕  中级技神
 楼主|

发表于 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矩阵”

  1. /*
  2.   【Arduino】168种传感器模块系列实验(资料代码+仿真编程+图形编程)
  3.   实验二百二十:P6全彩LED模组 16X32显示屏单元板 P6-RGB-16X32-8S
  4.   室内全彩8扫电子屏(HX-P6-16X32-A)
  5.   项目程序之十:3个弹力球与流动文本“Arduino 16x32 RGB LED矩阵”
  6. */
  7. #include <Adafruit_GFX.h>   //核心图形库
  8. #include <RGBmatrixPanel.h> //硬件特定库
  9. #define CLK 8 //必须在这个端口上! (在Mega上使用PIN 11)
  10. #define LAT A3
  11. #define OE  9
  12. #define A   A0
  13. #define B   A1
  14. #define C   A2
  15. //最后一个参数='false'禁用双缓冲
  16. RGBmatrixPanel matrix(A, B, C, CLK, LAT, OE, false);
  17. static const unsigned char PROGMEM bitmap[64] = {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};
  18. #define F2(progmem_ptr) (const __FlashStringHelper *)progmem_ptr
  19. const char str[] PROGMEM = "       Arduino 16x32 RGB LED Matrix";
  20. int16_t    textX         = matrix.width(),
  21.            textMin       = sizeof(str) * -12,
  22.            hue           = 0;
  23. int8_t ball[3][4] = {
  24.   {  3,  0,  1,  1 }, //初始x速度3个弹力球
  25.   { 17, 15,  1, -1 },
  26.   { 27,  4, -1,  1 }
  27. };
  28. static const uint16_t PROGMEM ballcolor[3] = {
  29.   0x0080, // 绿色=1
  30.   0x0002, // 蓝色=1
  31.   0x1000  // 红色=1
  32. };
  33. void setup() {
  34.   matrix.begin();
  35.   matrix.setTextWrap(false);
  36.   matrix.setTextSize(2);
  37. }
  38. void loop(){
  39.   byte i;
  40.   matrix.fillScreen(0);
  41.   for(i=0; i<3; i++) {
  42.     matrix.fillCircle(ball[i][0], ball[i][1], 5, pgm_read_word(&ballcolor[i]));
  43.     ball[i][0] += ball[i][2];
  44.     ball[i][1] += ball[i][3];
  45.     if((ball[i][0] == 0) || (ball[i][0] == (matrix.width() - 1)))
  46.       ball[i][2] *= -1;
  47.     if((ball[i][1] == 0) || (ball[i][1] == (matrix.height() - 1)))
  48.       ball[i][3] *= -1;
  49.   }
  50.   matrix.setTextColor(matrix.ColorHSV(hue, 255, 255, true));
  51.   matrix.setCursor(textX, 1);
  52.   matrix.print(F2(str));
  53.   if((--textX) < textMin) textX = matrix.width();
  54.   hue += 7;
  55.   if(hue >= 1536) hue -= 1536;
  56. #if !defined(__AVR__)
  57.   delay(20);
  58. #endif
  59.   matrix.swapBuffers(false);
  60. }
复制代码


回复

使用道具 举报

驴友花雕  中级技神
 楼主|

发表于 2022-11-14 08:34:37

实验场景图

【Arduino】168种传感器模块系列实验(220)---P6全彩16X32单元板图1

回复

使用道具 举报

驴友花雕  中级技神
 楼主|

发表于 2022-11-14 08:57:10

实验场景图  动态图

【Arduino】168种传感器模块系列实验(220)---P6全彩16X32单元板图1

回复

使用道具 举报

驴友花雕  中级技神
 楼主|

发表于 2022-11-14 08:59:31

【Arduino】168种传感器模块系列实验(220)---P6全彩16X32单元板图1
回复

使用道具 举报

驴友花雕  中级技神
 楼主|

发表于 2022-11-14 09:03:24

回复

使用道具 举报

驴友花雕  中级技神
 楼主|

发表于 2022-11-14 09:06:16

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

  1. /*
  2.   【Arduino】168种传感器模块系列实验(资料代码+仿真编程+图形编程)
  3.   实验二百二十:P6全彩LED模组 16X32显示屏单元板 P6-RGB-16X32-8S
  4.   室内全彩8扫电子屏(HX-P6-16X32-A)
  5.   项目程序之十一:尝试运行空气动力学的康威(Conways)生存游戏v1版本
  6. */
  7. #include <Adafruit_GFX.h>   // Core graphics library
  8. #include <RGBmatrixPanel.h> // Hardware-specific library
  9. #include <EEPROM.h> // To store on EEPROM Memory
  10. //Definition of the pattern if you use the pattern initialization
  11. int pattern_size[] = {7, 22}; // row x Column
  12. char pattern_init[] =
  13.   ".........*,\
  14. .......*.*,\
  15. ......*.*,\
  16. **...*..*...........**,\
  17. **....*.*...........**,\
  18. .......*.*,\
  19. .........*!";
  20. bool WORLD[16][32]; // Creation of the wordl
  21. int step_GOL; //used to know the generation
  22. //Definition of the LED Matrix Object
  23. #define CLK 8  // MUST be on PORTB! (Use pin 11 on Mega)
  24. #define LAT A3
  25. #define OE  9
  26. #define A   A0
  27. #define B   A1
  28. #define C   A2
  29. // Last parameter = 'true' enables double-BUFFER_WORLDing, for flicker-free,
  30. // buttery smooth animatrixion.  Note that NOTHING WILL SHOW ON THE DISPLAY
  31. // until the first call to swapBuffers().  This is normal.
  32. RGBmatrixPanel matrix(A, B, C, CLK, LAT, OE, false); //I couldn't use double buffering because it uses
  33. //too much memory
  34. void setup() {
  35.   //Serial.begin(115200); //use to print the game on the serial monitor (to debug)
  36.   //Randomly initialazing the world for the first step
  37.   randomSeed(analogRead(5));
  38.   for (byte i = 0; i < 16; i++) {
  39.     for (byte j = 0; j < 32; j++) {
  40.       WORLD[i][j] = random(0, 2);
  41.     }
  42.   }
  43.   //init_WORLD(); // Uncomment if you want to init with a specific pattern
  44.   step_GOL = 0;
  45.   matrix.begin();
  46.   print_WORLD(); //Display the first generation
  47. }
  48. void loop() {
  49.   if (step_GOL == 60) { // This if reboot the world after 60 generation to avoid static world
  50.     step_GOL = 0;
  51.     matrix.fillScreen(0);
  52.     delay(500);
  53.     randomSeed(analogRead(5));
  54.     for (byte i = 0; i < 16; i++) {
  55.       for (byte j = 0; j < 32; j++) {
  56.         WORLD[i][j] = random(0, 2);
  57.       }
  58.     }
  59.   }
  60.   //This double "for" is used to update the world to the next generation
  61.   //The buffer state is written on the EEPROM Memory
  62.   for (byte i = 0; i < 16; i++) {
  63.     for (byte j = 0; j < 32; j++) {
  64.       if (i == 0 || i == 15 || j == 0 || j == 31) // I choose to keep the border at 0
  65.       {
  66.         EEPROM.write(i * 31 + j , 0);
  67.       }
  68.       else {
  69.         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];
  70.         bool state = WORLD[i][j];
  71.         //RULE#1 if you are surrounded by 3 cells --> you live
  72.         if (num_alive == 3) {
  73.           EEPROM.write(i * 31 + j , 1);
  74.         }
  75.         //RULE#2 if you are surrounded by 2 cells --> you stay in your state
  76.         else if (num_alive == 2) {
  77.           EEPROM.write(i * 31 + j , state);
  78.         }
  79.         //RULE#3 otherwise you die from overpopulation or subpopulation
  80.         else {
  81.           EEPROM.write(i * 31 + j , 0);
  82.         }
  83.       }
  84.     }
  85.   }
  86.   //Updating the World
  87.   for (byte i = 0; i < 16; i++) {
  88.     for (byte j = 0; j < 32; j++) {
  89.       WORLD[i][j] = EEPROM.read(i * 31 + j);
  90.     }
  91.   }
  92.   //Displaying the world
  93.   print_WORLD();
  94.   //Increasing the generation
  95.   step_GOL++;
  96. }
  97. // PRINT THE WORLD
  98. void print_WORLD()
  99. {
  100.   for (byte j = 0; j < 32; j++) {
  101.     for (byte i = 0; i < 16; i++) {
  102.       if (WORLD[i][j] == 0) {
  103.         matrix.drawPixel(j, i, matrix.Color333(0, 0, 0));
  104.       }
  105.       else
  106.       {
  107.         matrix.drawPixel(j, i, matrix.Color333(0, 1, 2));
  108.       }
  109.     }
  110.   }
  111. }
  112. //Those two function are used to display the world on the serial monitor
  113. //Not beautiful but useful to debug
  114. void print_WORLD_SERIAL()
  115. {
  116.   clearscreen();
  117.   Serial.print("Step = "); Serial.println(step_GOL);
  118.   for (int i = 0; i < 16; i++) {
  119.     for (int j = 0; j < 32; j++) {
  120.       if (WORLD[i][j] == 0) {
  121.         Serial.print(".");
  122.         Serial.print(" ");
  123.       }
  124.       else
  125.       {
  126.         Serial.print("*");
  127.         Serial.print(" ");
  128.       }
  129.     }
  130.     Serial.println("");
  131.   }
  132.   Serial.println("");
  133. }
  134. void clearscreen() {
  135.   for (int i = 0; i < 10; i++) {
  136.     Serial.println("\n\n\n\n");
  137.   }
  138. }
  139. //This function is used to init the world with a know pattern
  140. //It read . and * to convert them to 0 and 1.
  141. //Inspired from life 1.05 format
  142. // NB : this function needs improvment to center the pattern
  143. void init_WORLD() {
  144.   int k = 0;
  145.   int row = 0;
  146.   int column = 0;
  147.   while (pattern_init[k] != '!') {
  148.     if (pattern_init[k] == ',') {
  149.       row++;
  150.       k++;
  151.       column = 0;
  152.     }
  153.     else if (pattern_init[k] == '.') {
  154.       WORLD[row + 2][column + 4] = 0;
  155.       k++;
  156.       column ++;
  157.     }
  158.     else  {
  159.       WORLD[row + 2][column + 4] = 1;
  160.       k++;
  161.       column ++;
  162.     }
  163.   }
  164. }
复制代码


回复

使用道具 举报

驴友花雕  中级技神
 楼主|

发表于 2022-11-14 09:07:50

实验场景图  动态图

【Arduino】168种传感器模块系列实验(220)---P6全彩16X32单元板图1

回复

使用道具 举报

驴友花雕  中级技神
 楼主|

发表于 2022-11-14 09:11:22

回复

使用道具 举报

驴友花雕  中级技神
 楼主|

发表于 2022-11-14 09:13:13

实验场景图

【Arduino】168种传感器模块系列实验(220)---P6全彩16X32单元板图1

回复

使用道具 举报

1234
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

为本项目制作心愿单
购买心愿单
心愿单 编辑
[[wsData.name]]

硬件清单

  • [[d.name]]
btnicon
我也要做!
点击进入购买页面
上海智位机器人股份有限公司 沪ICP备09038501号-4

© 2013-2024 Comsenz Inc. Powered by Discuz! X3.4 Licensed

mail