SOGO論壇
  登入   註冊   找回密碼
查看: 1326|回覆: 2
列印 上一主題 下一主題

[程式設計] 如何加入宣告 arduino 11和13腳位 讓矩陣LED亮 [複製連結]

Rank: 1

狀態︰ 離線
跳轉到指定樓層
1
發表於 2016-7-20 15:36:29 |只看該作者 |倒序瀏覽
最近在做Arduino 的程式應用,目的是先讓RED矩陣的數字會亮

原課本程式碼為  如下

#include <SPI.h>
const int slaveSelect=10;
const int decodeMode=9;
const int intensity=10;
const int scanLimit=11;
const int shutDown=12;
const int dispTest=15;
byte i;
const int col=8;
const byte character[10][8]=  //PABCDEFG               
  { {0x00,0x00,0x7f,0x41,0x41,0x7f,0x00,0x00},    //0
    {0x00,0x00,0x00,0x00,0x00,0x7f,0x00,0x00},    //1
    {0x00,0x00,0x79,0x49,0x49,0x4f,0x00,0x00},    //2
    {0x00,0x00,0x49,0x49,0x49,0x7f,0x00,0x00},    //3
    {0x00,0x00,0x0f,0x08,0x08,0x7f,0x00,0x00},    //4
    {0x00,0x00,0x4f,0x49,0x49,0x79,0x00,0x00},    //5
    {0x00,0x00,0x7f,0x49,0x49,0x79,0x00,0x00},    //6
    {0x00,0x00,0x01,0x01,0x01,0x7f,0x00,0x00},    //7
    {0x00,0x00,0x7f,0x49,0x49,0x7f,0x00,0x00},    //8
    {0x00,0x00,0x4f,0x49,0x49,0x7f,0x00,0x00} };  //9              
void setup()
{
  Serial.begin(9600);
  SPI.begin();
  pinMode(slaveSelect,OUTPUT);
  digitalWrite(slaveSelect,HIGH);
  sendCommand(shutDown,1);
  sendCommand(dispTest,0);
  sendCommand(intensity,1);
  sendCommand(scanLimit,7);
  sendCommand(decodeMode,0);
  for(i=0;i<8;i++)
    sendCommand(i+1,character[0][i]);
}   
void loop()
{
  if(Serial.available())
  {
    int ch=Serial.read();
    if(ch>='0' && ch<='9')
    {
      for(i=0;i<8;i++)
        sendCommand(i+1,character[ch-'0'][i]);
    }   
  }      
}
void sendCommand(byte command,byte value)
{
  digitalWrite(slaveSelect,LOW);
  SPI.transfer(command);
  SPI.transfer(value);
  digitalWrite(slaveSelect,HIGH);
}   

程式中只有定義第10接腳

但是輸出的 腳位  11和  13接腳 未定義,該如何從程式中加入程式碼讓它輸出會有 High 和 Low

求 Arduino 高手解答
喜歡嗎?分享這篇文章給親朋好友︰
               感謝作者     

Rank: 5Rank: 5

數位軟體勳章

狀態︰ 離線
2
發表於 2016-7-22 22:13:48 |只看該作者
本帖最後由 alphi 於 2016-7-22 22:15 編輯
  1. #include <SPI.h>
  2. const int slaveSelect=10;
  3. const int decodeMode=9;
  4. const int intensity=10;
  5. const int scanLimit=11;
  6. const int UserDefinePin=13;
  7. const int shutDown=12;
  8. const int dispTest=15;
  9. byte i;
  10. const int col=8;
  11. const byte character[10][8]=  //PABCDEFG               
  12.   { {0x00,0x00,0x7f,0x41,0x41,0x7f,0x00,0x00},    //0
  13.     {0x00,0x00,0x00,0x00,0x00,0x7f,0x00,0x00},    //1
  14.     {0x00,0x00,0x79,0x49,0x49,0x4f,0x00,0x00},    //2
  15.     {0x00,0x00,0x49,0x49,0x49,0x7f,0x00,0x00},    //3
  16.     {0x00,0x00,0x0f,0x08,0x08,0x7f,0x00,0x00},    //4
  17.     {0x00,0x00,0x4f,0x49,0x49,0x79,0x00,0x00},    //5
  18.     {0x00,0x00,0x7f,0x49,0x49,0x79,0x00,0x00},    //6
  19.     {0x00,0x00,0x01,0x01,0x01,0x7f,0x00,0x00},    //7
  20.     {0x00,0x00,0x7f,0x49,0x49,0x7f,0x00,0x00},    //8
  21.     {0x00,0x00,0x4f,0x49,0x49,0x7f,0x00,0x00} };  //9              
  22. void setup()
  23. {
  24.   Serial.begin(9600);
  25.   SPI.begin();
  26.   pinMode(slaveSelect,OUTPUT);
  27.   digitalWrite(slaveSelect,HIGH);

  28.    //set pin.11 is output
  29. pinMode(scanLimit,OUTPUT);
  30.   //set pin.11 is output high
  31. digitalWrite(scanLimit,HIGH);

  32.   //set pin.13 is output
  33.   pinMode(slaveSelect,OUTPUT);
  34.   //set pin.13 is output high
  35.   digitalWrite(slaveSelect,HIGH);

  36.   sendCommand(shutDown,1);
  37.   sendCommand(dispTest,0);
  38.   sendCommand(intensity,1);
  39.   sendCommand(scanLimit,7);
  40.   sendCommand(decodeMode,0);
  41.   for(i=0;i<8;i++)
  42.     sendCommand(i+1,character[0][i]);
  43. }   
  44. void loop()
  45. {
  46.   if(Serial.available())
  47.   {
  48.     int ch=Serial.read();
  49.     if(ch>='0' && ch<='9')
  50.     {
  51.       for(i=0;i<8;i++)
  52.         sendCommand(i+1,character[ch-'0'][i]);
  53.     }   
  54.   }      
  55. }
  56. void sendCommand(byte command,byte value)
  57. {
  58.   digitalWrite(slaveSelect,LOW);
  59.   SPI.transfer(command);
  60.   SPI.transfer(value);
  61.   digitalWrite(slaveSelect,HIGH);
  62. }
複製代碼
失敗只有一種:那就是半途而廢

Rank: 1

狀態︰ 離線
3
發表於 2016-7-29 01:44:19 |只看該作者
alphi 發表於 2016-7-22 22:13  

感謝您的幫忙  因為上網找了一堆 可是不知道怎麼插入程式碼  非常感謝~~
請注意︰利用多帳號發表自問自答的業配文置入性行銷廣告者,將直接禁訪或刪除帳號及全部文章!
您需要登錄後才可以回覆 登入 | 註冊


本論壇為非營利自由討論平台,所有個人言論不代表本站立場。文章內容如有涉及侵權,請通知管理人員,將立即刪除相關文章資料。侵權申訴或移除要求:abuse@oursogo.com

GMT+8, 2024-4-27 03:44

© 2004-2024 SOGO論壇 OURSOGO.COM
回頂部