七段顯示器 腳位圖
_
|_|
|_|.
由上到下順時鐘旋轉分別為
A
F B
G
E C
D .
針腳
由左到右所對應的英文分別為
GF地AB
ED地C.
A=4
B=3
C=2
D=12
E=13
F=10
G=11
. = 1
本來是用for跑0-9,後來想想改用random跑比較爽一點XD
#define NUM 8
#define t true //not bright
#define f false //bright
boolean data[10][NUM] = {
{t, f, f, f, f, t, f, f}, // 0
{t, f, f, t, t, t, t, t}, // 1
{t, t, f, f, t, f, f, f}, // 2
{t, f, f, f, t, f, f, t}, // 3
{t, f, f, t, f, f, t, t}, // 4
{t, f, t, f, f, f, f, t}, // 5
{t, f, t, f, f, f, f, f}, // 6
{t, f, f, f, t, t, t, t}, // 7
{t, f, f, f, f, f, f, f}, // 8
{t, f, f, f, f, f, f, t}, // 9
};
int pins[NUM]={1,2,3,4,10,11,12,13};
void setup(){
for(int i=0;i<NUM;i++)
{
pinMode(pins[i],OUTPUT);
}
}
void writeNumber(int n){
for(int i = 0; i < NUM; i++){
if (data[n][i]== t){
digitalWrite(pins[i],HIGH);
}
else{
digitalWrite(pins[i],LOW);
}
//digitalWrite(pins[i], data[n][i] == t ? HIGH : LOW);
//analogWrite(pins[i],50);
}
}
void loop(){
/* for(int n = 0; n <= 9; n++){
writeNumber(n);
}
*/
unsigned int n=0;
n=random(10);
writeNumber(n);
delay(1000);
/* for(int i=0;i<NUM;i++){
digitalWrite(pins[i],HIGH);
}
delay(1000);
for(int i=0;i<NUM;i++){
digitalWrite(pins[i],LOW);
}
delay(1000);
*/
}
0 意見:
張貼留言