#include <SoftwareSerial.h>
#include <SimpleModbusSlave.h>
int a[2] = {A0,A1};
int fnd_a = 3;
int buffer[2] = {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
};
enum
{
/* ADC0,
ADC1,
ADC2,
ADC3,
ADC4,
ADC5, */
FND_STATE, //40001
TOTAL_ERRORS, // leave this one
TOTAL_REGS_SIZE // total number of registers for function 3 and 16 share the same register array
};
unsigned int holdingRegs[TOTAL_REGS_SIZE]; // function 3 and 16 register array
void setup()
{
modbus_configure(9600, 1, 2, TOTAL_REGS_SIZE,0); //국번1
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<2; 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()
{
holdingRegs[TOTAL_ERRORS] = modbus_update(holdingRegs);
int i,k = 0;
int STATUS;
byte fndState = holdingRegs[FND_STATE];
analogValue = fndState;
// Serial.println(FND_STATE);
buffer[1] = (analogValue%100)/10;
buffer[0] = analogValue%10;
for(i=0; i<2; i++){
STATUS = buffer[1-i];
fnd(STATUS);
digitalWrite(a[k],LOW);
delay(5);
digitalWrite(a[k],HIGH);
k++;
k = k % 2;
}
}
댓글 없음:
댓글 쓰기