2017년 6월 8일 목요일
4개의 FND display
/////////4개의 FND display
int a[4] = {10,11,12,13}; //FND Control PIN
int fnd_a = 2; //FND의 a핀에 대한 포트값
int table[4][7] = { //FND출력값 테이블
{0,1,1,0,1,1,1}, //H //2,3,4,5,6,7,8핀
{1,0,0,1,1,1,1}, //E
{0,0,0,1,1,1,0}, //L
{1,1,0,0,1,1,1}, //P
};
void setup()
{
int i,j;
for(i=0; i<7; i++) //FND a핀부터 g핀까지 포트설정
pinMode(fnd_a+i, OUTPUT);
for(i=0; j<4; j++) //FND Control PIN
pinMode(a[j], OUTPUT);
}
void loop()
{
int i,j,k=0;
for(j=0; j<4; j++){
for(i=0; i<7; i++){
digitalWrite(fnd_a+i, table[j][i]); //H,E,L,P순환
digitalWrite(a[k], LOW); //a[]배열순환
}
delay(5);
digitalWrite(a[k], HIGH);
k++;
k = k % 4;
}
}
////////4자리숫자값을 4개의 FND에 각각표시하기
int a[4] = {10,11,12,13};
int fnd_a = 2;
int buffer[4] = {0};
int analogValue;
unsigned char table[10][7] = {
{1,1,1,1,1,1,0}, //0
{0,1,1,0,0,0,0}, //1
{1,1,0,1,1,0,1}, //2
{1,1,1,1,0,0,1}, //3
{0,1,1,0,0,1,1}, //4
{1,0,1,1,0,1,1}, //5
{1,0,1,1,1,1,1}, //6
{1,1,1,0,0,1,0}, //7
{1,1,1,1,1,1,1}, //8
{1,1,1,0,0,1,1} //9
};
void setup()
{
Serial.begin(9600);
int i,j;
for(i=fnd_a; i<fnd_a+7; i++) //FND a핀부터 g핀까지 포트설정
pinMode(i, OUTPUT);
for(j=0; j<4; j++) //FND Control PIN
pinMode(a[j], OUTPUT);
}
void fnd(int STATUS)
{
int j;
switch(STATUS){
case 0: for(j=0; j<7; j++) digitalWrite(fnd_a+j, table[0][j]); break;
case 1: for(j=0; j<7; j++) digitalWrite(fnd_a+j, table[1][j]); break;
case 2: for(j=0; j<7; j++) digitalWrite(fnd_a+j, table[2][j]); break;
case 3: for(j=0; j<7; j++) digitalWrite(fnd_a+j, table[3][j]); break;
case 4: for(j=0; j<7; j++) digitalWrite(fnd_a+j, table[4][j]); break;
case 5: for(j=0; j<7; j++) digitalWrite(fnd_a+j, table[5][j]); break;
case 6: for(j=0; j<7; j++) digitalWrite(fnd_a+j, table[6][j]); break;
case 7: for(j=0; j<7; j++) digitalWrite(fnd_a+j, table[7][j]); break;
case 8: for(j=0; j<7; j++) digitalWrite(fnd_a+j, table[8][j]); break;
case 9: for(j=0; j<7; j++) digitalWrite(fnd_a+j, table[9][j]); break;
}
}
void loop()
{
int i,k = 0;
int STATUS;
analogValue = analogRead(A0);
Serial.println(analogValue);
buffer[3] = analogValue/1000;
buffer[2] = (analogValue%1000)/100;
buffer[1] = (analogValue%100)/10;
buffer[0] = analogValue%10;
for(i=0; i<4; i++){
STATUS = buffer[3-i];
fnd(STATUS);
digitalWrite(a[k],LOW);
delay(5);
digitalWrite(a[k],HIGH);
k++;
k=k % 4;
}
}
//////////블루투스숫자입력-FND출력
#include <SoftwareSerial.h>
SoftwareSerial BTSerial(2,3);
int fnd_a = 5;
unsigned char table[9][7] = {
{0,1,1,0,0,0,0}, //1
{1,1,0,1,1,0,1}, //2
{1,1,1,1,0,0,1}, //3
{0,1,1,0,0,1,1}, //4
{1,0,1,1,0,1,1}, //5
{1,0,1,1,1,1,1}, //6
{1,1,1,0,0,1,0}, //7
{1,1,1,1,1,1,1}, //8
{1,1,1,0,0,1,1} //9
};
void setup()
{
BTSerial.begin(9600);
// Serial.begin(9600);
int i,j;
for(i=fnd_a; i<fnd_a+7; i++) //FND a핀부터 g핀까지 포트설정
pinMode(i, OUTPUT);
}
void fnd(int STATUS)
{
int j;
switch(STATUS){
case 1: for(j=0; j<7; j++) digitalWrite(fnd_a+j, table[0][j]); break;
case 2: for(j=0; j<7; j++) digitalWrite(fnd_a+j, table[1][j]); break;
case 3: for(j=0; j<7; j++) digitalWrite(fnd_a+j, table[2][j]); break;
case 4: for(j=0; j<7; j++) digitalWrite(fnd_a+j, table[3][j]); break;
case 5: for(j=0; j<7; j++) digitalWrite(fnd_a+j, table[4][j]); break;
case 6: for(j=0; j<7; j++) digitalWrite(fnd_a+j, table[5][j]); break;
case 7: for(j=0; j<7; j++) digitalWrite(fnd_a+j, table[6][j]); break;
case 8: for(j=0; j<7; j++) digitalWrite(fnd_a+j, table[7][j]); break;
case 9: for(j=0; j<7; j++) digitalWrite(fnd_a+j, table[8][j]); break;
}
}
void loop()
{
int STATUS,ch;
if(BTSerial.available())
{
STATUS = BTSerial.read();
// Serial.println(STATUS);
ch=(STATUS - '0');
// Serial.println(ch);
fnd(ch);
delay(10);
}
}
피드 구독하기:
댓글 (Atom)
댓글 없음:
댓글 쓰기