Arduino的 搞的MX7219的课堂作业
希望有大佬帮忙优化下这屎山代码 我看着是真脑袋大 毫无优化
但能跑 真的是能跑就行
主要流程就是 设置库 写好预设 显示预设 没了
我萌新 别骂 会哭 嘤嘤嘤
代码如下:
#include <SPI.h>
#include <Adafruit_GFX.h>
#include <Max72xxPanel.h>
Max72xxPanel myMatrix = Max72xxPanel(9,1,1);
uint8_t LEDArray[8];
const uint8_t LedArray00[8] PROGMEM ={0x18,0x3c,0x7e,0xff,0xff,0xff,0xe7,0x42};
const uint8_t LedArray01[8] PROGMEM ={0x00,0x00,0x00,0x00,0x00,0x00,0x00,0xff};
const uint8_t LedArray02[8] PROGMEM ={0x00,0x00,0x00,0x00,0x00,0x00,0xff,0x00};
const uint8_t LedArray03[8] PROGMEM ={0x00,0x00,0x00,0x00,0x00,0xff,0x00,0x00};
const uint8_t LedArray04[8] PROGMEM ={0x00,0x00,0x00,0x00,0xff,0x00,0x00,0x00};
const uint8_t LedArray05[8] PROGMEM ={0x00,0x00,0x00,0xff,0x00,0x00,0x00,0x00};
const uint8_t LedArray06[8] PROGMEM ={0x00,0x00,0xff,0x00,0x00,0x00,0x00,0x00};
const uint8_t LedArray07[8] PROGMEM ={0x00,0xff,0x00,0x00,0x00,0x00,0x00,0x00};
const uint8_t LedArray08[8] PROGMEM ={0xff,0x00,0x00,0x00,0x00,0x00,0x00,0x00};
const uint8_t LedArray09[8] PROGMEM ={0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01};
const uint8_t LedArray10[8] PROGMEM ={0x02,0x02,0x02,0x02,0x02,0x02,0x02,0x02};
const uint8_t LedArray11[8] PROGMEM ={0x04,0x04,0x04,0x04,0x04,0x04,0x04,0x04};
const uint8_t LedArray12[8] PROGMEM ={0x08,0x08,0x08,0x08,0x08,0x08,0x08,0x08};
const uint8_t LedArray13[8] PROGMEM ={0x10,0x10,0x10,0x10,0x10,0x10,0x10,0x10};
const uint8_t LedArray14[8] PROGMEM ={0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20};
const uint8_t LedArray15[8] PROGMEM ={0x40,0x40,0x40,0x40,0x40,0x40,0x40,0x40};
const uint8_t LedArray16[8] PROGMEM ={0x80,0x80,0x80,0x80,0x80,0x80,0x80,0x80};
void setup(){
}
void loop(){
myMatrix.setIntensity(1);
memcpy_P(&LEDArray, &LedArray01, 8);
for(int index_i=0; index_i<8; index_i++)
{
for(int index_j=0*8; index_j<0*8+8; index_j++)
{
if((LEDArray[index_i]&0x01)>0)
myMatrix.drawPixel(index_j, 7-index_i,1);
else
myMatrix.drawPixel(index_j, 7-index_i,0);
LEDArray[index_i] = LEDArray[index_i]>>1;
}
}
myMatrix.write();
delay(100);
myMatrix.fillScreen(0);
myMatrix.write();
memcpy_P(&LEDArray, &LedArray02, 8);
for(int index_i=0; index_i<8; index_i++)
{
for(int index_j=0*8; index_j<0*8+8; index_j++)
{
if((LEDArray[index_i]&0x01)>0)
myMatrix.drawPixel(index_j, 7-index_i,1);
else
myMatrix.drawPixel(index_j, 7-index_i,0);
LEDArray[index_i] = LEDArray[index_i]>>1;
}
}
myMatrix.write();
delay(100);
memcpy_P(&LEDArray, &LedArray03, 8);
for(int index_i=0; index_i<8; index_i++)
{
for(int index_j=0*8; index_j<0*8+8; index_j++)
{
if((LEDArray[index_i]&0x01)>0)
myMatrix.drawPixel(index_j, 7-index_i,1);
else
myMatrix.drawPixel(index_j, 7-index_i,0);
LEDArray[index_i] = LEDArray[index_i]>>1;
}
}
myMatrix.write();
delay(100);
myMatrix.fillScreen(0);
myMatrix.write();
memcpy_P(&LEDArray, &LedArray04, 8);
for(int index_i=0; index_i<8; index_i++)
{
for(int index_j=0*8; index_j<0*8+8; index_j++)
{
if((LEDArray[index_i]&0x01)>0)
myMatrix.drawPixel(index_j, 7-index_i,1);
else
myMatrix.drawPixel(index_j, 7-index_i,0);
LEDArray[index_i] = LEDArray[index_i]>>1;
}
}
myMatrix.write();
delay(100);
myMatrix.fillScreen(0);
myMatrix.write();
memcpy_P(&LEDArray, &LedArray05, 8);
for(int index_i=0; index_i<8; index_i++)
{
for(int index_j=0*8; index_j<0*8+8; index_j++)
{
if((LEDArray[index_i]&0x01)>0)
myMatrix.drawPixel(index_j, 7-index_i,1);
else
myMatrix.drawPixel(index_j, 7-index_i,0);
LEDArray[index_i] = LEDArray[index_i]>>1;
}
}
myMatrix.write();
delay(100);
memcpy_P(&LEDArray, &LedArray05, 8);
for(int index_i=0; index_i<8; index_i++)
{
for(int index_j=0*8; index_j<0*8+8; index_j++)
{
if((LEDArray[index_i]&0x01)>0)
myMatrix.drawPixel(index_j, 7-index_i,1);
else
myMatrix.drawPixel(index_j, 7-index_i,0);
LEDArray[index_i] = LEDArray[index_i]>>1;
}
}
myMatrix.write();
delay(100);
myMatrix.fillScreen(0);
myMatrix.write();
memcpy_P(&LEDArray, &LedArray06, 8);
for(int index_i=0; index_i<8; index_i++)
{
for(int index_j=0*8; index_j<0*8+8; index_j++)
{
if((LEDArray[index_i]&0x01)>0)
myMatrix.drawPixel(index_j, 7-index_i,1);
else
myMatrix.drawPixel(index_j, 7-index_i,0);
LEDArray[index_i] = LEDArray[index_i]>>1;
}
}
myMatrix.write();
delay(100);
myMatrix.fillScreen(0);
myMatrix.write();
memcpy_P(&LEDArray, &LedArray07, 8);
for(int index_i=0; index_i<8; index_i++)
{
for(int index_j=0*8; index_j<0*8+8; index_j++)
{
if((LEDArray[index_i]&0x01)>0)
myMatrix.drawPixel(index_j, 7-index_i,1);
else
myMatrix.drawPixel(index_j, 7-index_i,0);
LEDArray[index_i] = LEDArray[index_i]>>1;
}
}
myMatrix.write();
delay(100);
memcpy_P(&LEDArray, &LedArray08, 8);
for(int index_i=0; index_i<8; index_i++)
{
for(int index_j=0*8; index_j<0*8+8; index_j++)
{
if((LEDArray[index_i]&0x01)>0)
myMatrix.drawPixel(index_j, 7-index_i,1);
else
myMatrix.drawPixel(index_j, 7-index_i,0);
LEDArray[index_i] = LEDArray[index_i]>>1;
}
}
myMatrix.write();
delay(100);
myMatrix.fillScreen(0);
myMatrix.write();
memcpy_P(&LEDArray, &LedArray09, 8);
for(int index_i=0; index_i<8; index_i++)
{
for(int index_j=0*8; index_j<0*8+8; index_j++)
{
if((LEDArray[index_i]&0x01)>0)
myMatrix.drawPixel(index_j, 7-index_i,1);
else
myMatrix.drawPixel(index_j, 7-index_i,0);
LEDArray[index_i] = LEDArray[index_i]>>1;
}
}
myMatrix.write();
delay(100);
myMatrix.fillScreen(0);
myMatrix.write();
memcpy_P(&LEDArray, &LedArray10, 8);
for(int index_i=0; index_i<8; index_i++)
{
for(int index_j=0*8; index_j<0*8+8; index_j++)
{
if((LEDArray[index_i]&0x01)>0)
myMatrix.drawPixel(index_j, 7-index_i,1);
else
myMatrix.drawPixel(index_j, 7-index_i,0);
LEDArray[index_i] = LEDArray[index_i]>>1;
}
}
myMatrix.write();
delay(100);
memcpy_P(&LEDArray, &LedArray11, 8);
for(int index_i=0; index_i<8; index_i++)
{
for(int index_j=0*8; index_j<0*8+8; index_j++)
{
if((LEDArray[index_i]&0x01)>0)
myMatrix.drawPixel(index_j, 7-index_i,1);
else
myMatrix.drawPixel(index_j, 7-index_i,0);
LEDArray[index_i] = LEDArray[index_i]>>1;
}
}
myMatrix.write();
delay(100);
myMatrix.fillScreen(0);
myMatrix.write();
memcpy_P(&LEDArray, &LedArray12, 8);
for(int index_i=0; index_i<8; index_i++)
{
for(int index_j=0*8; index_j<0*8+8; index_j++)
{
if((LEDArray[index_i]&0x01)>0)
myMatrix.drawPixel(index_j, 7-index_i,1);
else
myMatrix.drawPixel(index_j, 7-index_i,0);
LEDArray[index_i] = LEDArray[index_i]>>1;
}
}
myMatrix.write();
delay(100);
myMatrix.fillScreen(0);
myMatrix.write();
memcpy_P(&LEDArray, &LedArray13, 8);
for(int index_i=0; index_i<8; index_i++)
{
for(int index_j=0*8; index_j<0*8+8; index_j++)
{
if((LEDArray[index_i]&0x01)>0)
myMatrix.drawPixel(index_j, 7-index_i,1);
else
myMatrix.drawPixel(index_j, 7-index_i,0);
LEDArray[index_i] = LEDArray[index_i]>>1;
}
}
myMatrix.write();
delay(100);
myMatrix.fillScreen(0);
myMatrix.write();
memcpy_P(&LEDArray, &LedArray14, 8);
for(int index_i=0; index_i<8; index_i++)
{
for(int index_j=0*8; index_j<0*8+8; index_j++)
{
if((LEDArray[index_i]&0x01)>0)
myMatrix.drawPixel(index_j, 7-index_i,1);
else
myMatrix.drawPixel(index_j, 7-index_i,0);
LEDArray[index_i] = LEDArray[index_i]>>1;
}
}
myMatrix.write();
delay(100);
myMatrix.fillScreen(0);
myMatrix.write();
memcpy_P(&LEDArray, &LedArray15, 8);
for(int index_i=0; index_i<8; index_i++)
{
for(int index_j=0*8; index_j<0*8+8; index_j++)
{
if((LEDArray[index_i]&0x01)>0)
myMatrix.drawPixel(index_j, 7-index_i,1);
else
myMatrix.drawPixel(index_j, 7-index_i,0);
LEDArray[index_i] = LEDArray[index_i]>>1;
}
}
myMatrix.write();
delay(1000);
myMatrix.fillScreen(0);
myMatrix.write();
memcpy_P(&LEDArray, &LedArray00, 8);
for(int index_i=0; index_i<8; index_i++)
{
for(int index_j=0*8; index_j<0*8+8; index_j++)
{
if((LEDArray[index_i]&0x01)>0)
myMatrix.drawPixel(index_j, 7-index_i,1);
else
myMatrix.drawPixel(index_j, 7-index_i,0);
LEDArray[index_i] = LEDArray[index_i]>>1;
}
}
myMatrix.write();
}