8X8的 LED燈顯示 各種形狀

接線圖:

17902870-05987e0ced135858.png
image


形狀圖:
17902870-f71154afc821d172.png
image

代碼:

int R[] = {2,3,4,5,A3,A2,A1,A0};      //行  數組,記錄接口int C[] = {6,7,8,9,10,11,12,13};      //列  數組,記錄接口int led[8][8] = {//實心心形,1處是亮燈的led
  {0, 0, 0, 0, 0, 0, 0, 0},
  {0, 1, 1, 0, 0, 1, 1, 0},
  {1, 1, 1, 1, 1, 1, 1, 1},
  {1, 1, 1, 1, 1, 1, 1, 1},
  {1, 1, 1, 1, 1, 1, 1, 1},
  {0, 1, 1, 1, 1, 1, 1, 0},
  {0, 0, 1, 1, 1, 1, 0, 0},
  {0, 0, 0, 1, 1, 0, 0, 0}
};
int led3[8][8] = {//字母I,1處是亮燈的led
  {0, 0, 0, 0, 0, 0, 0, 0},
  {0, 0, 0, 1, 1, 0, 0, 0},
  {0, 0, 0, 1, 1, 0, 0, 0},
  {0, 0, 0, 1, 1, 0, 0, 0},
  {0, 0, 0, 1, 1, 0, 0, 0},
  {0, 0, 0, 1, 1, 0, 0, 0},
  {0, 0, 0, 1, 1, 0, 0, 0},
  {0, 0, 0, 0, 0, 0, 0, 0}
};

int led4[8][8] = {//字母U,1處是亮燈的led
  {0, 0, 0, 0, 0, 0, 0, 0},
  {0, 1, 1, 0, 0, 1, 1, 0},
  {0, 1, 1, 0, 0, 1, 1, 0},
  {0, 1, 1, 0, 0, 1, 1, 0},
  {0, 1, 1, 0, 0, 1, 1, 0},
  {0, 1, 1, 1, 1, 1, 1, 0},
  {0, 0, 1, 1, 1, 1, 0, 0},
  {0, 0, 0, 0, 0, 0, 0, 0}
};

void setup() {  // put your setup code here, to run once:for(int i = 0;i< 8;i++)
    {
        pinMode(R[i],OUTPUT);
        pinMode(C[i],OUTPUT);
      }  // Serial.begin(9600);}


void loop() {  // put your main code here, to run repeatedly://    myDisplay(led);
     for(int i = 0 ; i < 100 ; i++)        //循環顯示100次  
      {  
        myDisplay(led3);                   //顯示字母“I”  
      }  
      for(int i = 0 ; i < 100 ; i++)         //循環顯示100次  
      {     
        myDisplay(led);                 //顯示心形
      } 
      for(int i = 0 ; i < 100 ; i++)         //循環顯示100次  
      {     
        myDisplay(led4);                 //顯示字母“U”
      }  
}//自定義函數//顯示函數  void myDisplay(int Led[8][8])   
{  
  for(int c = 0; c<8;c++)  
  {  
    digitalWrite(C[c],LOW);//選通第c列  
  
    //循環  
    for(int r = 0;r<8;r++)  
    {  
      digitalWrite(R[r],Led[r][c]);  
    }  
    delay(1);  
    Clear();  //清空顯示
  }  
}  

//清空顯示  void Clear()                          
{  
  for(int i = 0;i<8;i++)  
  {  
    digitalWrite(R[i],LOW);
    digitalWrite(C[i],HIGH);  
  }  
}

完成!

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章