Who know the diffiences between the following 2 p?

//First~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ byte database[12][6] = { {0x8c, 0x02, 0x8c, 0x02, 0x8c, 0x02}, {0xbc, 0x02, 0xbc, 0x02, 0xbc, 0x02}, {0x74, 0x01, 0x74, 0x01, 0x74, 0x01}, {0x84, 0x03, 0x84, 0x03, 0x84, 0x03}, {0x94, 0x00, 0x94, 0x00, 0x94, 0x00}, {0x17, 0x01, 0x17, 0x01, 0x17, 0x01}, {0xe3, 0x02, 0xe3, 0x02, 0xe3, 0x02}, {0x40, 0x03, 0x40, 0x03, 0x40, 0x03}, {0x53, 0x00, 0x52, 0x01, 0x53, 0x00}, {0xd5, 0x02, 0x8a, 0x03, 0xd5, 0x02}, {0x00, 0x00, 0x00, 0x00, 0x00, 0x00}, {0x42, 0x02, 0x42, 0x02, 0x42, 0x02} };

byte Instrc[] = {0xff, 0xff, 0x00, 0x07, 0x03, 0x1E, 0x8C, 0x02, 0xff, 0x02, 0x00}; //This 11 bytes is the Instruction Template for writing the angles to the Motor.

int nRE = 22; //The enable port for Receiving data int DE = 23; //The enable port for Transfering data

int i,j;

void setup() { pinMode(nRE,OUTPUT); pinMode(DE,OUTPUT); digitalWrite(nRE,LOW); //Enable for Receiving data digitalWrite(DE,HIGH); //Enable for Transfering data Serial.begin(9600); Serial1.begin(500000); // ID = 0x00; i = 0; j = 0; }

void loop() { Instrc[2] = i; // "i" is the ID of the motor Instrc[6] = database*[j]; //The low byte of position* _ Instrc[7] = database*[++j]; //The high byte of position*_ * Instrc[10] = ~( Instrc[2]+Instrc[3]+Instrc[4]+Instrc[5]+Instrc[6]+Instrc[7]+Instrc[8]+Instrc[9] ); //Calculate the check sum* * Serial1.write(Instrc,11); //Write the instruction* * delay(50);* * i++; //Write data for next motor * * j--;* * if(i > 11)* * {* * i = 0;* * j = j + 2; //Write data for next stage* * delay(500);* * }* * if((i > 11) && (j > 5)) //Judge if the data has been send all* * {* * i = 0;* * j = 0;* * }* }

//Second~~~~~~~~~~~~~~~~~~~~~~~~~~ int nRE = 22; int DE = 23; byte D0[] = {0xFF, 0xFF, 0x00, 0x07, 0x03, 0x1E, 0x8C, 0x02, 0xff, 0x02, 0x00}; byte D1[] = {0xFF, 0xFF, 0x01, 0x07, 0x03, 0x1E, 0xBC, 0x02, 0xff, 0x02, 0x00}; byte D2[] = {0xFF, 0xFF, 0x02, 0x07, 0x03, 0x1E, 0x74, 0x01, 0xff, 0x02, 0x00}; byte D3[] = {0xFF, 0xFF, 0x03, 0x07, 0x03, 0x1E, 0x84, 0x03, 0xff, 0x02, 0x00}; byte D4[] = {0xFF, 0xFF, 0x04, 0x07, 0x03, 0x1E, 0x94, 0x00, 0xff, 0x02, 0x00}; byte D5[] = {0xFF, 0xFF, 0x05, 0x07, 0x03, 0x1E, 0x17, 0x01, 0xff, 0x02, 0x00}; byte D6[] = {0xFF, 0xFF, 0x06, 0x07, 0x03, 0x1E, 0xE3, 0x02, 0xff, 0x02, 0x00}; byte D7[] = {0xFF, 0xFF, 0x07, 0x07, 0x03, 0x1E, 0x40, 0x03, 0xff, 0x02, 0x00}; byte D8[] = {0xFF, 0xFF, 0x08, 0x07, 0x03, 0x1E, 0x53, 0x00, 0xff, 0x02, 0x00}; byte D9[] = {0xFF, 0xFF, 0x09, 0x07, 0x03, 0x1E, 0xD5, 0x02, 0xff, 0x02, 0x00}; byte D10[] = {0xFF, 0xFF, 0x0A, 0x07, 0x03, 0x1E, 0x00, 0x00, 0xff, 0x02, 0x00}; byte D11[] = {0xFF, 0xFF, 0x0B, 0x07, 0x03, 0x1E, 0x42, 0x02, 0xff, 0x02, 0x00}; //byte Sum;

byte E0[] = {0xFF, 0xFF, 0x00, 0x07, 0x03, 0x1E, 0x8C, 0x02, 0xff, 0x02, 0x00}; byte E1[] = {0xFF, 0xFF, 0x01, 0x07, 0x03, 0x1E, 0xBC, 0x02, 0xff, 0x02, 0x00}; byte E2[] = {0xFF, 0xFF, 0x02, 0x07, 0x03, 0x1E, 0x74, 0x01, 0xff, 0x02, 0x00}; byte E3[] = {0xFF, 0xFF, 0x03, 0x07, 0x03, 0x1E, 0x84, 0x03, 0xff, 0x02, 0x00}; byte E4[] = {0xFF, 0xFF, 0x04, 0x07, 0x03, 0x1E, 0x94, 0x00, 0xff, 0x02, 0x00}; byte E5[] = {0xFF, 0xFF, 0x05, 0x07, 0x03, 0x1E, 0x17, 0x01, 0xff, 0x02, 0x00}; byte E6[] = {0xFF, 0xFF, 0x06, 0x07, 0x03, 0x1E, 0xE3, 0x02, 0xff, 0x02, 0x00}; byte E7[] = {0xFF, 0xFF, 0x07, 0x07, 0x03, 0x1E, 0x40, 0x03, 0xff, 0x02, 0x00}; byte E8[] = {0xFF, 0xFF, 0x08, 0x07, 0x03, 0x1E, 0x52, 0x01, 0xff, 0x02, 0x00}; byte E9[] = {0xFF, 0xFF, 0x09, 0x07, 0x03, 0x1E, 0x8A, 0x03, 0xff, 0x02, 0x00}; byte E10[] = {0xFF, 0xFF, 0x0A, 0x07, 0x03, 0x1E, 0x00, 0x00, 0xff, 0x02, 0x00}; byte E11[] = {0xFF, 0xFF, 0x0B, 0x07, 0x03, 0x1E, 0x42, 0x02, 0xff, 0x02, 0x00}; //byte Instrc1[] = {0xFF, 0xFF, 0x01, 0x07, 0x03, 0x1E, 0x00, 0x00, 0x03, 0x03, 0xD0}; //int val[20];

byte F0[] = {0xFF, 0xFF, 0x00, 0x07, 0x03, 0x1E, 0x8C, 0x02, 0xff, 0x02, 0x00}; byte F1[] = {0xFF, 0xFF, 0x01, 0x07, 0x03, 0x1E, 0xBC, 0x02, 0xff, 0x02, 0x00}; byte F2[] = {0xFF, 0xFF, 0x02, 0x07, 0x03, 0x1E, 0x8F, 0x00, 0xff, 0x02, 0x00}; byte F3[] = {0xFF, 0xFF, 0x03, 0x07, 0x03, 0x1E, 0x67, 0x02, 0xff, 0x02, 0x00}; byte F4[] = {0xFF, 0xFF, 0x04, 0x07, 0x03, 0x1E, 0x94, 0x00, 0xff, 0x02, 0x00}; byte F5[] = {0xFF, 0xFF, 0x05, 0x07, 0x03, 0x1E, 0x17, 0x01, 0xff, 0x02, 0x00}; byte F6[] = {0xFF, 0xFF, 0x06, 0x07, 0x03, 0x1E, 0xE3, 0x02, 0xff, 0x02, 0x00}; byte F7[] = {0xFF, 0xFF, 0x07, 0x07, 0x03, 0x1E, 0x40, 0x03, 0xff, 0x02, 0x00}; byte F8[] = {0xFF, 0xFF, 0x08, 0x07, 0x03, 0x1E, 0x53, 0x00, 0xff, 0x02, 0x00}; byte F9[] = {0xFF, 0xFF, 0x09, 0x07, 0x03, 0x1E, 0xD5, 0x02, 0xff, 0x02, 0x00}; byte F10[] = {0xFF, 0xFF, 0x0A, 0x07, 0x03, 0x1E, 0x00, 0x00, 0xff, 0x02, 0x00}; byte F11[] = {0xFF, 0xFF, 0x0B, 0x07, 0x03, 0x1E, 0x42, 0x02, 0xff, 0x02, 0x00}; int ledPin = 13; int i; void setup() { pinMode(nRE,OUTPUT); pinMode(DE,OUTPUT); pinMode(ledPin,OUTPUT);

D0[10] = ~( D0[2]+D0[3]+D0[4]+D0[5]+D0[6]+D0[7]+D0[8]+D0[9] );

D1[10] = ~( D1[2]+D1[3]+D1[4]+D1[5]+D1[6]+D1[7]+D1[8]+D1[9] );

D2[10] = ~( D2[2]+D2[3]+D2[4]+D2[5]+D2[6]+D2[7]+D2[8]+D2[9] );

D3[10] = ~( D3[2]+D3[3]+D3[4]+D3[5]+D3[6]+D3[7]+D3[8]+D3[9] );

D4[10] = ~( D4[2]+D4[3]+D4[4]+D4[5]+D4[6]+D4[7]+D4[8]+D4[9] );

D5[10] = ~( D5[2]+D5[3]+D5[4]+D5[5]+D5[6]+D5[7]+D5[8]+D5[9] );

D6[10] = ~( D6[2]+D6[3]+D6[4]+D6[5]+D6[6]+D6[7]+D6[8]+D6[9] );

D7[10] = ~( D7[2]+D7[3]+D7[4]+D7[5]+D7[6]+D7[7]+D7[8]+D7[9] );

D8[10] = ~( D8[2]+D8[3]+D8[4]+D8[5]+D8[6]+D8[7]+D8[8]+D8[9] );

D9[10] = ~( D9[2]+D9[3]+D9[4]+D9[5]+D9[6]+D9[7]+D9[8]+D9[9] );

D10[10] = ~( D10[2]+D10[3]+D10[4]+D10[5]+D10[6]+D10[7]+D10[8]+D10[9] );

D11[10] = ~( D11[2]+D11[3]+D11[4]+D11[5]+D11[6]+D11[7]+D11[8]+D11[9] );

E0[10] = ~( E0[2]+E0[3]+E0[4]+E0[5]+E0[6]+E0[7]+E0[8]+E0[9] );

E1[10] = ~( E1[2]+E1[3]+E1[4]+E1[5]+E1[6]+E1[7]+E1[8]+E1[9] );

E2[10] = ~( E2[2]+E2[3]+E2[4]+E2[5]+E2[6]+E2[7]+E2[8]+E2[9] );

E3[10] = ~( E3[2]+E3[3]+E3[4]+E3[5]+E3[6]+E3[7]+E3[8]+E3[9] );

E4[10] = ~( E4[2]+E4[3]+E4[4]+E4[5]+E4[6]+E4[7]+E4[8]+E4[9] );

E5[10] = ~( E5[2]+E5[3]+E5[4]+E5[5]+E5[6]+E5[7]+E5[8]+E5[9] );

E6[10] = ~( E6[2]+E6[3]+E6[4]+E6[5]+E6[6]+E6[7]+E6[8]+E6[9] );

E7[10] = ~( E7[2]+E7[3]+E7[4]+E7[5]+E7[6]+E7[7]+E7[8]+E7[9] );

E8[10] = ~( E8[2]+E8[3]+E8[4]+E8[5]+E8[6]+E8[7]+E8[8]+E8[9] );

E9[10] = ~( E9[2]+E9[3]+E9[4]+E9[5]+E9[6]+E9[7]+E9[8]+E9[9] );

E10[10] = ~( E10[2]+E10[3]+E10[4]+E10[5]+E10[6]+E10[7]+E10[8]+E10[9] );

E11[10] = ~( E11[2]+E11[3]+E11[4]+E11[5]+E11[6]+E11[7]+E11[8]+E11[9] );

F0[10] = ~( F0[2]+F0[3]+F0[4]+F0[5]+F0[6]+F0[7]+F0[8]+F0[9] );

F1[10] = ~( F1[2]+F1[3]+F1[4]+F1[5]+F1[6]+F1[7]+F1[8]+F1[9] );

F2[10] = ~( F2[2]+F2[3]+F2[4]+F2[5]+F2[6]+F2[7]+F2[8]+F2[9] );

F3[10] = ~( F3[2]+F3[3]+F3[4]+F3[5]+F3[6]+F3[7]+F3[8]+F3[9] );

F4[10] = ~( F4[2]+F4[3]+F4[4]+F4[5]+F4[6]+F4[7]+F4[8]+F4[9] );

F5[10] = ~( F5[2]+F5[3]+F5[4]+F5[5]+F5[6]+F5[7]+F5[8]+F5[9] );

F6[10] = ~( F6[2]+F6[3]+F6[4]+F6[5]+F6[6]+F6[7]+F6[8]+F6[9] );

F7[10] = ~( F7[2]+F7[3]+F7[4]+F7[5]+F7[6]+F7[7]+F7[8]+F7[9] );

F8[10] = ~( F8[2]+F8[3]+F8[4]+F8[5]+F8[6]+F8[7]+F8[8]+F8[9] );

F9[10] = ~( F9[2]+F9[3]+F9[4]+F9[5]+F9[6]+F9[7]+F9[8]+F9[9] );

F10[10] = ~( F10[2]+F10[3]+F10[4]+F10[5]+F10[6]+F10[7]+F10[8]+F10[9] );

F11[10] = ~( F11[2]+F11[3]+F11[4]+F11[5]+F11[6]+F11[7]+F11[8]+F11[9] ); Serial.begin(9600); Serial1.begin(500000); //Serial1.flush(); }

void loop() { digitalWrite(nRE,LOW); digitalWrite(DE,HIGH);

Serial1.write(D0,11); delay(50); Serial1.write(D1,11); delay(50); Serial1.write(D2,11); delay(50); Serial1.write(D3,11); delay(50); Serial1.write(D4,11); delay(50); Serial1.write(D5,11); delay(50); Serial1.write(D6,11); delay(50); Serial1.write(D7,11); delay(50); Serial1.write(D8,11); delay(50); Serial1.write(D9,11); delay(50); Serial1.write(D10,11); delay(50); Serial1.write(D11,11); delay(50);

delay(500);

Serial1.write(E0,11); delay(50); Serial1.write(E1,11); delay(50); Serial1.write(E2,11); delay(50); Serial1.write(E3,11); delay(50); Serial1.write(E4,11); delay(50); Serial1.write(E5,11); delay(50); Serial1.write(E6,11); delay(50); Serial1.write(E7,11); delay(50); Serial1.write(E8,11); delay(50); Serial1.write(E9,11); delay(50); Serial1.write(E10,11); delay(50); Serial1.write(E11,11); delay(50);

delay(500);

Serial1.write(D0,11); delay(50); Serial1.write(D1,11); delay(50); Serial1.write(D2,11); delay(50); Serial1.write(D3,11); delay(50); Serial1.write(D4,11); delay(50); Serial1.write(D5,11); delay(50); Serial1.write(D6,11); delay(50); Serial1.write(D7,11); delay(50); Serial1.write(D8,11); delay(50); Serial1.write(D9,11); delay(50); Serial1.write(D10,11); delay(50); Serial1.write(D11,11); delay(50);

delay(500);

Serial1.write(F0,11); delay(50); Serial1.write(F1,11); delay(50); Serial1.write(F2,11); delay(50); Serial1.write(F3,11); delay(50); Serial1.write(F4,11); delay(50); Serial1.write(F5,11); delay(50); Serial1.write(F6,11); delay(50); Serial1.write(F7,11); delay(50); Serial1.write(F8,11); delay(50); Serial1.write(F9,11); delay(50); Serial1.write(F10,11); delay(50); Serial1.write(F11,11); delay(50);

delay(500);

}

Why it doesn't work the same???

How knows?

Tell me , Please~ :'(

My board is Arduino Mega.

The IDE is Arduino 0021.

So I take it that the first example is an attempted re-write of the second, but it doesn't work?

void loop()
{
 Instrc[2] = i; // "i" is the ID of the motor
 Instrc[6] = database[i][j]; //The low byte of position
 Instrc[7] = database[i][++j]; //The high byte of position
 Instrc[10] = ~( Instrc[2]+Instrc[3]+Instrc[4]+Instrc[5]+Instrc[6]+Instrc[7]+Instrc[8]+Instrc[9] ); //Calculate the check sum
 Serial1.write(Instrc,11); //Write the instruction
 delay(50);
 i++; //Write data for next motor  
 j--;
 if(i > 11)
 {
   i = 0;
   j = j + 2; //Write data for next stage
   delay(500);
 }
 if((i > 11) && (j > 5)) //Judge if the data has been send all
 {
   i = 0;
   j = 0;
 }
}

Your second "if" statement ("if((i > 11) && (j > 5))") will never trigger because you just reset i to zero in the previous if statement. "j" will continue to grow and you'll be outputting random data from random places. You probably need to nest those ifs:

if (i > 11) {
  i == 0;
  if (j > 5) {
    j == 0;
  } else {
    j = j+2;
    delay(500);
  }
}

Also, your "++j" and subsequent "j--" is messy and obscures your intent. Just use "database*[j+1]"*

You probably need to nest those ifs

Or do as any sane person would, and rewrite as a pair of nested "for" loops.

That’ll make it something like:

   for (j=0; j <=5; j+=2) { // For each stage
      for (i=0; i <=11; i++) { // For each motor
         Instrc[2] = i; // "i" is the ID of the motor
         Instrc[6] = database[i][j]; //The low byte of position
         Instrc[7] = database[i][j+1]; //The high byte of position
         Instrc[10] = ~(Instrc[2]+Instrc[3]+Instrc[4]+Instrc[5]+Instrc[6]+Instrc[7]+Instrc[8]+Instrc[9] ); //Calculate the check sum
         Serial1.write(Instrc,11); //Write the instruction
         delay(50);
     } // next motor
     delay(InterStageDelay);
  } // next stage

Thank you very much! :)