0% found this document useful (0 votes)
26 views8 pages

Addr - 10K - 10K - 10K Send - Table PWM - DC - Table: Uint8 - T Uint8 - T Uint8 - T

The document contains an Arduino code that controls a device using I2C communication. It defines segments for inboard, middle, and outboard configurations, along with various data tables for PWM and welcome messages. The main functions include initializing the device, sending data, and executing sequential lighting patterns or welcome/farewell sequences.

Uploaded by

Saiful Islam
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
26 views8 pages

Addr - 10K - 10K - 10K Send - Table PWM - DC - Table: Uint8 - T Uint8 - T Uint8 - T

The document contains an Arduino code that controls a device using I2C communication. It defines segments for inboard, middle, and outboard configurations, along with various data tables for PWM and welcome messages. The main functions include initializing the device, sending data, and executing sequential lighting patterns or welcome/farewell sequences.

Uploaded by

Saiful Islam
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd

#include<Wire.

h>
#include<avr/pgmspace.h>
#define Addr_10K_10K_10K 0x80 //DeviceAddress
uint8_t i=0,j,loops,done=0;
uint8_t send_table[7];
uint8_t PWM_DC_Table[48];

/*

Inboard Middle Outboard

0x26 0x2F 0x38


0x27 0x30 0x39
0x29 0x32 0x3B
0x2A 0x33 0x3C
0x2C 0x35 0x3E
0x2D 0x36 0x3F

*/

uint8_t Inboard_Segment[6]=
{
0x26,0x27,0x29,0x2A,0x2C,0x2D
};

uint8_t Middle_Segment[6]=
{
0x2F,0x30,0x32,0x33,0x35,0x36
};

uint8_t Outboard_Segment[6]=
{
0x38,0x39,0x3B,0x3C,0x3E,0x3F
};

uint8_t ST_Inboard_DC[96]=
{
2,0,0,0,0,0,
2,2,0,0,0,0,
2,2,2,0,0,0,
2,2,2,2,0,0,
2,2,2,2,2,0,
2,2,2,2,2,2,
0,2,2,2,2,2,
0,0,2,2,2,2,
0,0,0,2,2,2,
0,0,0,0,2,2,
0,0,0,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0,0,0,2,2,2,
0,0,0,0,2,2,
0,0,0,0,0,2,
0,0,0,0,0,0
};

uint8_t Welcome_Outboard_DC[114]=
{
0,0,0,0,0,0,
0,0,0,0,0,0,
0,0,0,0,0,0,
0,0,0,0,0,0,
0,0,0,0,0,0,
0,0,0,0,0,0,
0,0,0,0,0,0,
0,0,0,0,0,0,
0,0,0,0,0,0,
0,0,0,0,0,0,
0,0,0,0,0,0,
0,0,0,0,0,0,
0,0,0,0,0,0,
2,0,0,0,0,0,
2,2,0,0,0,0,
2,2,2,0,0,0,
2,2,2,2,0,0,
2,2,2,2,2,0,
2,2,2,2,2,2
};

void setup()
{
Bus_reset();
Init_3138();

for (i=0;i<48;i++)
{
PWM_DC_Table[i]=i;
}
}
void loop()
{
Sequential_Turn();
//Welcome();
//Farewell();
}

void Bus_reset(void)
{
pinMode(1,OUTPUT);
digitalWrite(1,LOW);
delay(1); //delay 1s,Reset Signal>150us is OK
Serial.begin(115200);//UART 115200
send_table[0] = 0X55;
Serial.write(send_table,1);
}
uint16_t crc_16_ibm (uint8_t *buf, uint8_t len)//CRC calibration
{
uint16_t crc = 0;
uint16_t I;
while (len--)
{
crc ^= *buf++;
for (I = 0; I < 8; I++)
{
crc = (crc >> 1) ^ ((crc & 1) ? 0xa001 : 0);
}
}
return crc;
}
void Update(void)
{
uint16_t crc;
send_table[0] = 0X98;
send_table[1] = 0X80;
crc = crc_16_ibm(send_table,2);
send_table[2] = (uint8_t)crc;
send_table[3] = (uint8_t)(crc>>8);
Serial.write(send_table,4);
}

void URAT_WriteByte(int DeviceAddress, int WriteAddress, int


SendByte)//URAT agreement
{
uint16_t crc;
send_table[0]=0X80;
send_table[1]=DeviceAddress;
send_table[2]=WriteAddress;
send_table[3]=SendByte;
crc = crc_16_ibm(send_table,4);
send_table[4] = (uint8_t)crc;
send_table[5] = (uint8_t)(crc>>8);
Serial.write(send_table,6);
}
void Init_3138(void)
{
URAT_WriteByte(Addr_10K_10K_10K,0x01,0x3f);// set GCC
for(i=0x14;i<0x26;i++)
{
URAT_WriteByte(Addr_10K_10K_10K,i,0x7f);//set SL
}
Update();
}

void Sequential_Turn(void)
{
i=0;

for (loops=0;loops<16;loops++)
{

for (j=0;j<6;j++) //Inboard


{

URAT_WriteByte(Addr_10K_10K_10K,Inboard_Segment[j],ST_Inboard_DC[i]);
URAT_WriteByte(Addr_10K_10K_10K,Middle_Segment[j],ST_Middle_DC[i]);

URAT_WriteByte(Addr_10K_10K_10K,Outboard_Segment[j],ST_Outboard_DC[i]);

i++;
}

Update();
delay(30);
}

delay(750);
}

void Welcome (void)


{
i=0;

for (loops=0;loops<19;loops++)
{

for (j=0;j<6;j++) //Inboard


{

URAT_WriteByte(Addr_10K_10K_10K,Inboard_Segment[j],Welcome_Inboard_DC[i])
;

URAT_WriteByte(Addr_10K_10K_10K,Middle_Segment[j],Welcome_Middle_DC[i]);

URAT_WriteByte(Addr_10K_10K_10K,Outboard_Segment[j],Welcome_Outboard_DC[i
]);

if(i<113)i++;
}

Update();
if(i==6)delay(2000);
if(i==113)delay(2000);
delay(35);
}

void Farewell (void)


{

i=114;

for (loops=0;loops<19;loops++)
{

for (j=6;j>0;j--) //Inboard


{
URAT_WriteByte(Addr_10K_10K_10K,Inboard_Segment[j-
1],Welcome_Inboard_DC[i-1]);
URAT_WriteByte(Addr_10K_10K_10K,Middle_Segment[j-
1],Welcome_Middle_DC[i-1]);
URAT_WriteByte(Addr_10K_10K_10K,Outboard_Segment[j-
1],Welcome_Outboard_DC[i-1]);

if(i>1)i--;
}

Update();
if(i==108)delay(2000);
if(i==1)delay(2000);
delay(35);
}

You might also like