SOGO論壇
標題:
如何加入宣告 arduino 11和13腳位 讓矩陣LED亮
[列印本頁]
作者:
andy84717
時間:
2016-7-20 15:36:29
標題:
如何加入宣告 arduino 11和13腳位 讓矩陣LED亮
最近在做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 高手解答
作者:
alphi
時間:
2016-7-22 22:13:48
本帖最後由 alphi 於 2016-7-22 22:15 編輯
#include <SPI.h>
const int slaveSelect=10;
const int decodeMode=9;
const int intensity=10;
const int scanLimit=11;
const int UserDefinePin=13;
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);
//set pin.11 is output
pinMode(scanLimit,OUTPUT);
//set pin.11 is output high
digitalWrite(scanLimit,HIGH);
//set pin.13 is output
pinMode(slaveSelect,OUTPUT);
//set pin.13 is output high
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);
}
複製代碼
作者:
andy84717
時間:
2016-7-29 01:44:19
alphi 發表於 2016-7-22 22:13
感謝您的幫忙 因為上網找了一堆 可是不知道怎麼插入程式碼 非常感謝~~
歡迎光臨 SOGO論壇 (https://oursogo.com/)
Powered by OURSOGO.COM