5

When I am trying to compile the following code,

int delayTime = 1;
int charBreak = 2.1;
#include <MemoryFree.h>

int rled1 = 1;
int rled2 = 2;
int rled3 = 3;
int rled4 = 4;
int rled5 = 5;
int gled1 = 6;
int gled2 = 7;
int gled3 = 8;
int gled4 = 9;
int gled5 = 10;
int bled1 = 11;
int bled2 = 12;
int bled3 = 13;
int bled4 = 14;
int bled5 = 15;

void setup()
{
  Serial.begin(9600);
}

int ra[] = {4,288,18464,288,4};
int ga[] = {2,144,9232,144,2};
int ba[] = {1,72,4616,72,2};
int rb[] = {18724,16644,16644,2080,0};
int gb[] = {9362,8322,8322,1040,0};
int bb[] = {4681,4161,4161,520,0};
int rc[] = {2336,16388,16388,2080,0};
int gc[] = {1168,8194,8194,1040,0};
int bc[] = {584,4097,4097,520,0};
int rd[] = {18724,16388,16388,2336,0};
int gd[] = {9362,8194,8194,1168,0};
int bd[] = {4681,4097,4097,584,0};
int re[] = {18724,16644,16644,16388,0};
int ge[] = {9362,8322,8322,8194,0};
int be[] = {4681,4161,4161,4097,0};
int rf[] = {18724,16640,16640,16384,0};
int gf[] = {9362,8320,8320,8192,0};
int bf[] = {4681,4160,4160,4096,0};
int rg[] = {2336,16388,16420,16416,2084};
int gg[] = {1168,8194,8210,8208,1042};
int bg[] = {584,4097,4105,4104,521};
int rh[] = {18724,256,256,256,18724};
int gh[] = {9362,128,128,128,9362};
int bh[] = {4681,64,64,64,4681};
int ri[] = {0,16388,18724,16388,0};
int gi[] = {0,8194,9362,8194,0};
int bi[] = {0,4097,4681,4097,0};
int rj[] = {32,4,16388,18720,16384};
int gj[] = {16,2,8194,9360,8192};
int bj[] = {8,1,4097,4680,4096};
int rk[] = {18724,256,2080,16388,0};
int gk[] = {9362,128,1040,8194,0};
int bk[] = {4681,64,520,4097,0};
int rl[] = {18724,4,4,4,0};
int gm[] = {9362,2,2,2,0};
int bm[] = {4681,1,1,1,0};
int rm[] = {18724,2304,36,2304,18724};
int gm[] = {9362,1152,18,1152,9362};
int bm[] = {4681,576,9,576,4681};
int rn[] = {18724,2304,36,18724,0};
int gn[] = {9362,1152,18,9362,0};
int bn[] = {4681,576,9,4681,0};
int ro[] = {2336,16388,16388,2336,0};
int go[] = {1168,8194,8194,1168,0};
int bo[] = {584,4097,4097,584,0};
int rp[] = {18724,16640,16640,2048,0};
int gp[] = {9362,8320,8320,1024,0};
int bp[] = {4681,4160,4160,512,0};
int rq[] = {2336,16388,16420,2336,36};
int gq[] = {1168,8194,8210,1168,18};
int bq[] = {584,4097,4105,584,9};
int rr[] = {18724,16640,16672,2052,0};
int gr[] = {9362,8320,8336,1026,0};
int br[] = {4681,4160,4168,513,0};
int rs[] = {2048,16644,16644,32,0};
int gs[] = {1024,8322,8322,16,0};
int bs[] = {512,4161,4161,8,0};
int rt[] = {16384,16384,18724,16384,16384};
int gt[] = {8192,8192,9362,8192,8192};
int bt[] = {4096,4096,4681,4096,4096};
int ru[] = {18720,4,4,18720,0};
int gu[] = {9360,2,2,9360,0};
int bu[] = {4680,1,1,4680,0};
int rv[] = {18432,288,4,288,18432};
int gv[] = {9216,144,2,144,9216};
int bv[] = {4608,72,1,72,4608};
int rw[] = {18688,36,2304,36,18688};
int gw[] = {9344,18,1152,18,9344};
int bw[] = {4672,9,576,9,4672};
int rx[] = {16388,2080,256,2080,16388};
int gx[] = {8194,1040,128,1040,8194};
int bx[] = {4097,520,64,520,4097};
int ry[] = {16388,2080,256,2048,16384};
int gy[] = {8194,1040,128,1024,8192};
int by[] = {4097,520,64,512,4096};
int rz[] = {16420,16644,16644,18436,0};
int gz[] = {8210,8322,8322,9218,0};
int bz[] = {4105,4161,4161,4609,0};
int reos[] = {0,4,0,0,0};
int geos[] = {0,2,0,0,0};
int beos[] = {0,1,0,0,0};
int rque[] = {2048,16420,16640,2048,0};
int gque[] = {1024,8210,8320,1024,0};
int bque[] = {512,4105,4160,512,0};
int rexcl[] = {0,18692,0,0,0};
int gexcl[] = {0,9346,0,0,0};
int bexcl[] = {0,4673,0,0,0};

void displayLine(int line)
{
  int myline; myline = line;
  if (myline>=16384) {digitalWrite(rled1, HIGH); myline-=16384;} else {digitalWrite(rled1, LOW);}
  if (myline>=8192) {digitalWrite(gled1, HIGH); myline-=8192;} else {digitalWrite(gled1, LOW);}
  if (myline>=4096) {digitalWrite(bled1, HIGH); myline-=4096;} else {digitalWrite(bled1, LOW);}
  if (myline>=2048) {digitalWrite(rled2, HIGH); myline-=2048;} else {digitalWrite(rled2, LOW);}
  if (myline>=1024) {digitalWrite(gled2, HIGH); myline-=1024;} else {digitalWrite(gled2, LOW);}
  if (myline>=512) {digitalWrite(bled2, HIGH); myline-=512;} else {digitalWrite(bled2, LOW);}
  if (myline>=256) {digitalWrite(rled3, HIGH); myline-=256;} else {digitalWrite(rled3, LOW);}
  if (myline>=128) {digitalWrite(gled3, HIGH); myline-=128;} else {digitalWrite(gled3, LOW);}
  if (myline>=64) {digitalWrite(bled3, HIGH); myline-=64;} else {digitalWrite(bled3, LOW);}
  if (myline>=32) {digitalWrite(rled4, HIGH); myline-=32;} else {digitalWrite(rled4, LOW);}
  if (myline>=16) {digitalWrite(gled4, HIGH); myline-=16;} else {digitalWrite(gled4, LOW);}
  if (myline>=8) {digitalWrite(bled4, HIGH); myline-=8;} else {digitalWrite(bled4, LOW);}
  if (myline>=4) {digitalWrite(rled5, HIGH); myline-=4;} else {digitalWrite(rled5, LOW);}
  if (myline>=2) {digitalWrite(gled5, HIGH); myline-=2;} else {digitalWrite(gled5, LOW);}
  if (myline>=1) {digitalWrite(bled5, HIGH); myline-=1;} else {digitalWrite(bled5, LOW);}

}

void displayChar(char c)
{
  if (c == 'ra'){for (int i = 0; i <5; i++){displayLine(ra[i]);delay(delayTime);}displayLine(0);}
  if (c == 'rb'){for (int i = 0; i <5; i++){displayLine(rb[i]);delay(delayTime);}displayLine(0);}
  if (c == 'rc'){for (int i = 0; i <5; i++){displayLine(rc2[i]);delay(delayTime);}displayLine(0);}
  if (c == 'rd'){for (int i = 0; i <5; i++){displayLine(rd[i]);delay(delayTime);}displayLine(0);}
  if (c == 're'){for (int i = 0; i <5; i++){displayLine(re[i]);delay(delayTime);}displayLine(0);}
  if (c == 'rf'){for (int i = 0; i <5; i++){displayLine(rf[i]);delay(delayTime);}displayLine(0);}
  if (c == 'rg'){for (int i = 0; i <5; i++){displayLine(rg[i]);delay(delayTime);}displayLine(0);}
  if (c == 'rh'){for (int i = 0; i <5; i++){displayLine(rh[i]);delay(delayTime);}displayLine(0);}
  if (c == 'ri'){for (int it = 0; it <5; it++){displayLine(ri[it]);delay(delayTime);}displayLine(0);}
  if (c == 'rj'){for (int i = 0; i <5; i++){displayLine(rj[i]);delay(delayTime);}displayLine(0);}
  if (c == 'rk'){for (int i = 0; i <5; i++){displayLine(rk[i]);delay(delayTime);}displayLine(0);}
  if (c == 'rl'){for (int i = 0; i <5; i++){displayLine(rl[i]);delay(delayTime);}displayLine(0);}
  if (c == 'rm'){for (int i = 0; i <5; i++){displayLine(rm[i]);delay(delayTime);}displayLine(0);}
  if (c == 'rn'){for (int i = 0; i <5; i++){displayLine(rn[i]);delay(delayTime);}displayLine(0);}
  if (c == 'ro'){for (int i = 0; i <5; i++){displayLine(ro[i]);delay(delayTime);}displayLine(0);}
  if (c == 'rp'){for (int i = 0; i <5; i++){displayLine(rp[i]);delay(delayTime);}displayLine(0);}
  if (c == 'rq'){for (int i = 0; i <5; i++){displayLine(rq[i]);delay(delayTime);}displayLine(0);}
  if (c == 'rr'){for (int i = 0; i <5; i++){displayLine(rr[i]);delay(delayTime);}displayLine(0);}
  if (c == 'rs'){for (int i = 0; i <5; i++){displayLine(rs[i]);delay(delayTime);}displayLine(0);}
  if (c == 'rt'){for (int i = 0; i <5; i++){displayLine(rt[i]);delay(delayTime);}displayLine(0);}
  if (c == 'ru'){for (int i = 0; i <5; i++){displayLine(ru[i]);delay(delayTime);}displayLine(0);}
  if (c == 'rv'){for (int i = 0; i <5; i++){displayLine(rv[i]);delay(delayTime);}displayLine(0);}
  if (c == 'rw'){for (int i = 0; i <5; i++){displayLine(rw[i]);delay(delayTime);}displayLine(0);}
  if (c == 'rx'){for (int i = 0; i <5; i++){displayLine(rx[i]);delay(delayTime);}displayLine(0);}
  if (c == 'ry'){for (int i = 0; i <5; i++){displayLine(ry[i]);delay(delayTime);}displayLine(0);}
  if (c == 'rz'){for (int i = 0; i <5; i++){displayLine(rz[i]);delay(delayTime);}displayLine(0);}
  if (c == 'r!'){for (int i = 0; i <5; i++){displayLine(rexcl[i]);delay(delayTime);}displayLine(0);}
  if (c == 'r?'){for (int i = 0; i <5; i++){displayLine(rques[i]);delay(delayTime);}displayLine(0);}
  if (c == 'r.'){for (int i = 0; i <5; i++){displayLine(reos[i]);delay(delayTime);}displayLine(0);}
  if (c == 'ga'){for (int i = 0; i <5; i++){displayLine(ga[i]);delay(delayTime);}displayLine(0);}
  if (c == 'gb'){for (int i = 0; i <5; i++){displayLine(gb[i]);delay(delayTime);}displayLine(0);}
  if (c == 'gc'){for (int i = 0; i <5; i++){displayLine(gc2[i]);delay(delayTime);}displayLine(0);}
  if (c == 'gd'){for (int i = 0; i <5; i++){displayLine(gd[i]);delay(delayTime);}displayLine(0);}
  if (c == 'ge'){for (int i = 0; i <5; i++){displayLine(ge[i]);delay(delayTime);}displayLine(0);}
  if (c == 'gf'){for (int i = 0; i <5; i++){displayLine(gf[i]);delay(delayTime);}displayLine(0);}
  if (c == 'gg'){for (int i = 0; i <5; i++){displayLine(gg[i]);delay(delayTime);}displayLine(0);}
  if (c == 'gh'){for (int i = 0; i <5; i++){displayLine(gh[i]);delay(delayTime);}displayLine(0);}
  if (c == 'gi'){for (int it = 0; it <5; it++){displayLine(gi[it]);delay(delayTime);}displayLine(0);}
  if (c == 'gj'){for (int i = 0; i <5; i++){displayLine(gj[i]);delay(delayTime);}displayLine(0);}
  if (c == 'gk'){for (int i = 0; i <5; i++){displayLine(gk[i]);delay(delayTime);}displayLine(0);}
  if (c == 'gl'){for (int i = 0; i <5; i++){displayLine(gl[i]);delay(delayTime);}displayLine(0);}
  if (c == 'gm'){for (int i = 0; i <5; i++){displayLine(gm[i]);delay(delayTime);}displayLine(0);}
  if (c == 'gn'){for (int i = 0; i <5; i++){displayLine(gn[i]);delay(delayTime);}displayLine(0);}
  if (c == 'go'){for (int i = 0; i <5; i++){displayLine(go[i]);delay(delayTime);}displayLine(0);}
  if (c == 'gp'){for (int i = 0; i <5; i++){displayLine(gp[i]);delay(delayTime);}displayLine(0);}
  if (c == 'gq'){for (int i = 0; i <5; i++){displayLine(gq[i]);delay(delayTime);}displayLine(0);}
  if (c == 'gr'){for (int i = 0; i <5; i++){displayLine(gr[i]);delay(delayTime);}displayLine(0);}
  if (c == 'gs'){for (int i = 0; i <5; i++){displayLine(gs[i]);delay(delayTime);}displayLine(0);}
  if (c == 'gt'){for (int i = 0; i <5; i++){displayLine(gt[i]);delay(delayTime);}displayLine(0);}
  if (c == 'gu'){for (int i = 0; i <5; i++){displayLine(gu[i]);delay(delayTime);}displayLine(0);}
  if (c == 'gv'){for (int i = 0; i <5; i++){displayLine(gv[i]);delay(delayTime);}displayLine(0);}
  if (c == 'gw'){for (int i = 0; i <5; i++){displayLine(gw[i]);delay(delayTime);}displayLine(0);}
  if (c == 'gx'){for (int i = 0; i <5; i++){displayLine(gx[i]);delay(delayTime);}displayLine(0);}
  if (c == 'gy'){for (int i = 0; i <5; i++){displayLine(gy[i]);delay(delayTime);}displayLine(0);}
  if (c == 'gz'){for (int i = 0; i <5; i++){displayLine(gz[i]);delay(delayTime);}displayLine(0);}
  if (c == 'g!'){for (int i = 0; i <5; i++){displayLine(gexcl[i]);delay(delayTime);}displayLine(0);}
  if (c == 'g?'){for (int i = 0; i <5; i++){displayLine(gques[i]);delay(delayTime);}displayLine(0);}
  if (c == 'g.'){for (int i = 0; i <5; i++){displayLine(geos[i]);delay(delayTime);}displayLine(0);}
  if (c == 'ba'){for (int i = 0; i <5; i++){displayLine(ba[i]);delay(delayTime);}displayLine(0);}
  if (c == 'bb'){for (int i = 0; i <5; i++){displayLine(bb[i]);delay(delayTime);}displayLine(0);}
  if (c == 'bc'){for (int i = 0; i <5; i++){displayLine(bc2[i]);delay(delayTime);}displayLine(0);}
  if (c == 'bd'){for (int i = 0; i <5; i++){displayLine(bd[i]);delay(delayTime);}displayLine(0);}
  if (c == 'be'){for (int i = 0; i <5; i++){displayLine(be[i]);delay(delayTime);}displayLine(0);}
  if (c == 'bf'){for (int i = 0; i <5; i++){displayLine(bf[i]);delay(delayTime);}displayLine(0);}
  if (c == 'bg'){for (int i = 0; i <5; i++){displayLine(bg[i]);delay(delayTime);}displayLine(0);}
  if (c == 'bh'){for (int i = 0; i <5; i++){displayLine(bh[i]);delay(delayTime);}displayLine(0);}
  if (c == 'bi'){for (int it = 0; it <5; it++){displayLine(bi[it]);delay(delayTime);}displayLine(0);}
  if (c == 'bj'){for (int i = 0; i <5; i++){displayLine(bj[i]);delay(delayTime);}displayLine(0);}
  if (c == 'bk'){for (int i = 0; i <5; i++){displayLine(bk[i]);delay(delayTime);}displayLine(0);}
  if (c == 'bl'){for (int i = 0; i <5; i++){displayLine(bl[i]);delay(delayTime);}displayLine(0);}
  if (c == 'bm'){for (int i = 0; i <5; i++){displayLine(bm[i]);delay(delayTime);}displayLine(0);}
  if (c == 'bn'){for (int i = 0; i <5; i++){displayLine(bn[i]);delay(delayTime);}displayLine(0);}
  if (c == 'bo'){for (int i = 0; i <5; i++){displayLine(bo[i]);delay(delayTime);}displayLine(0);}
  if (c == 'bp'){for (int i = 0; i <5; i++){displayLine(bp[i]);delay(delayTime);}displayLine(0);}
  if (c == 'bq'){for (int i = 0; i <5; i++){displayLine(bq[i]);delay(delayTime);}displayLine(0);}
  if (c == 'br'){for (int i = 0; i <5; i++){displayLine(br[i]);delay(delayTime);}displayLine(0);}
  if (c == 'bs'){for (int i = 0; i <5; i++){displayLine(bs[i]);delay(delayTime);}displayLine(0);}
  if (c == 'bt'){for (int i = 0; i <5; i++){displayLine(bt[i]);delay(delayTime);}displayLine(0);}
  if (c == 'bu'){for (int i = 0; i <5; i++){displayLine(bu[i]);delay(delayTime);}displayLine(0);}
  if (c == 'bv'){for (int i = 0; i <5; i++){displayLine(bv[i]);delay(delayTime);}displayLine(0);}
  if (c == 'bw'){for (int i = 0; i <5; i++){displayLine(bw[i]);delay(delayTime);}displayLine(0);}
  if (c == 'bx'){for (int i = 0; i <5; i++){displayLine(bx[i]);delay(delayTime);}displayLine(0);}
  if (c == 'by'){for (int i = 0; i <5; i++){displayLine(by[i]);delay(delayTime);}displayLine(0);}
  if (c == 'bz'){for (int i = 0; i <5; i++){displayLine(bz[i]);delay(delayTime);}displayLine(0);}
  if (c == 'b!'){for (int i = 0; i <5; i++){displayLine(bexcl[i]);delay(delayTime);}displayLine(0);}
  if (c == 'b?'){for (int i = 0; i <5; i++){displayLine(bques[i]);delay(delayTime);}displayLine(0);}
  if (c == 'b.'){for (int i = 0; i <5; i++){displayLine(beos[i]);delay(delayTime);}displayLine(0);}
  delay(charBreak);
}

void displayString(char* s)
{
  for (int i = 0; i<=strlen(s); i++)
  {
  displayChar(s[i]);
  }
}

void loop()
{
  displayString("sunil");
  Serial.print("freeMemory()=");
    Serial.println(freeMemory());
}

I am getting the following error.

sketch_jul17b:63: error: redefinition of 'int gm []'
sketch_jul17b:60: error: 'int gm [5]' previously defined here
sketch_jul17b:64: error: redefinition of 'int bm []'
sketch_jul17b:61: error: 'int bm [5]' previously defined here
sketch_jul17b.ino: In function 'void displayChar(char)':
sketch_jul17b:139: error: 'rc2' was not declared in this scope
sketch_jul17b:164: error: 'rques' was not declared in this scope
sketch_jul17b:168: error: 'gc2' was not declared in this scope
sketch_jul17b:177: error: 'gl' was not declared in this scope
sketch_jul17b:193: error: 'gques' was not declared in this scope
sketch_jul17b:197: error: 'bc2' was not declared in this scope
sketch_jul17b:206: error: 'bl' was not declared in this scope
sketch_jul17b:222: error: 'bques' was not declared in this scope

I don't know why this error is occurring.

  • Redefining variable names is a huge reason to avoid meaningless names like you're using. Use names like "RedLedPinNumber" and "RedLedCurrentState" and "GreenLedCurrentState" - MUCH easier to remember if you created one of those already. Variables take up the same amount of memory regardless of their names. – Jasmine Jul 16 '14 at 23:59
2

You have a combination of trying to define the same name twice, for example "gm"

int gm[] = {9362,2,2,2,0};
int bm[] = {4681,1,1,1,0};
int rm[] = {18724,2304,36,2304,18724};
int gm[] = {9362,1152,18,1152,9362};

And using others such "rc2" which you have never defined.

Your code won't compile and work until you make it self-consistent.

  • Please note that user2973 has found some additional problems in your code beyond the error messages you posted. – Chris Stratton Jul 16 '14 at 20:27
7

This can also happen if you have saved a version of the code (for example duplicate file for backup) within the current sketch folder.

  • Thanks, Bruno. Strangely enough, this was my problem with the example of a downloaded library that had the same example saved with .ino and .pde extensions. Deleted the .pde and worked fine. – user24319 Jul 29 '16 at 13:56
  • No worries, thanks for the comment! I knew this was going to help some-one as it is an easy mistake to make. (I did it when I duplicated the file inside the sketch folder. This would be the same as creating a tab page inside the IDE so the code is double defined. Which is the same problem as the original question. Hence the same error. – Bruno Jul 30 '16 at 11:23
3

The first errors happen because you are trying to define a variable with the same name in the same scope twice, like here:

int gm[] = {9362,2,2,2,0};
int bm[] = {4681,1,1,1,0};
int rm[] = {18724,2304,36,2304,18724};
int gm[] = {9362,1152,18,1152,9362};

gm is defined two times which is not allowed.

The other error happens because you are referencing variables you never declared like here:

if (c == 'rc'){for (int i = 0; i <5; i++){displayLine(rc2[i]);delay(delayTime);}displayLine(0);}

rc2 isn't defined anywhere.


Besides there are some other issues with your code:

int charBreak = 2.1;

int types can only contain whole numbers, so charBreak will be set to two and not two point one. You probably wan't to use a float.

In void displayChar(char c) you try to compare a char with two chars:

if (c == 'ra')

That won't work. The char type can only contain a single character, so the comparison will always be false. Two chars like this 'ab' in single quotes are interpreted as 16 bit number. Two chars in double quotes are interpreted as a null-terminated string:

char cstring1[] = "ab";
char cstring2[] = {'a', 'b', '\0'};

if (strcmp(cstring1, cstring2) == 0)
  // The two strings are identical

strcmp returns 0 on match-.

  • Thank you so much for the help with comparing characters. I was actually stuck there. – user3826856 Jul 17 '14 at 8:45

protected by Community Oct 17 '18 at 10:19

Thank you for your interest in this question. Because it has attracted low-quality or spam answers that had to be removed, posting an answer now requires 10 reputation on this site (the association bonus does not count).

Would you like to answer one of these unanswered questions instead?

Not the answer you're looking for? Browse other questions tagged or ask your own question.