【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 OE  9
 - #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[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};
 - 
 - #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][4] = {
 -   {  3,  0,  1,  1 }, //初始x速度3个弹力球
 -   { 17, 15,  1, -1 },
 -   { 27,  4, -1,  1 }
 - };
 - 
 - 
 - static const uint16_t PROGMEM ballcolor[3] = {
 -   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[i][0], ball[i][1], 5, pgm_read_word(&ballcolor[i]));
 -     ball[i][0] += ball[i][2];
 -     ball[i][1] += ball[i][3];
 -     if((ball[i][0] == 0) || (ball[i][0] == (matrix.width() - 1)))
 -       ball[i][2] *= -1;
 -     if((ball[i][1] == 0) || (ball[i][1] == (matrix.height() - 1)))
 -       ball[i][3] *= -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);
 - }
 
  复制代码
  
 
 |