byte backspace = 0x5c; // use to indicate backspace '\'
byte hold = 0x2b; //tbd +
byte oneLeft = 0x3c; //tbd <
byte normal = 0x3d; //tbd =
byte oneRight = 0x3e; //tbd >
byte move_control = normal;
I use them as part of a switch:case here within loop for serial data coming in to map them to readable names
if (Serial.available()>0){
incomingByte = Serial.read();
goodFont = 3;
// mapping from incoming character to font_array or other commands: \ + = < >
// invalid characters are not defined and are ignored
switch(incomingByte){
case 0x2b:
// change scroll movement
move_control = hold; // +, hold
goodFont = 2; // not a character to add to displayArray
break;
case 0x3c:
// change scroll movement
move_control = oneLeft; // <, move 1 left
goodFont = 2; // not a character to add to displayArray
break;
case 0x3d:
// change scroll movement
move_control = normal; // normal
goodFont = 2; // not a character to add to displayArray
break;
case 0x3e:
// change scroll movement
move_control = oneRight; // >, move 1 right
goodFont = 2; // not a character to add to displayArray
break;
case 0x5c:
// use 0x5c '\' for backspace to delete characters
move_control = backspace;
goodFont = 2; // not a character to add to displayArray
break;
} // end switch
So why is it when I try to adjust a pointer right after this, I get this error:
‘hold’ cannot appear in a constant-expression
I tried moving the switch:case chunks around, I get the same error message at the first case: listed.
switch (move_control){
// other movement checks
case hold:
// do nothing
break;
case oneRight:
if (displayStart<190){
displayStart = displayStart +1;
}
else {
displayStart = 0; // if not <191, must be 191
}
move_control = hold;
break;// end test move right
case oneLeft:
if (displayStart>0){
displayStart = displayStart -1;
}
else {
displayStart = 191; // if not >0, must be 0
}
move_control = hold;
break; // end test move left
case backspace:
if ( displayEnd >5){
displayEnd = displayEnd -6; // move end of array back 1 character + spacer
}
break;
case normal:
// allow shifting on time checks
move_control = normal;
break;
updateDisplay = 1;
} // end move control
Can you post code that reproduces the problem? For example, this compiles OK:
byte backspace = 0x5c; // use to indicate backspace '\'
byte hold = 0x2b; //tbd +
byte oneLeft = 0x3c; //tbd <
byte normal = 0x3d; //tbd =
byte oneRight = 0x3e; //tbd >
byte move_control = normal;
byte incomingByte, goodFont;
void setup ()
{
if (Serial.available()>0){
incomingByte = Serial.read();
goodFont = 3;
// mapping from incoming character to font_array or other commands: \ + = < >
// invalid characters are not defined and are ignored
switch(incomingByte){
case 0x2b:
// change scroll movement
move_control = hold; // +, hold
goodFont = 2; // not a character to add to displayArray
break;
case 0x3c:
// change scroll movement
move_control = oneLeft; // <, move 1 left
goodFont = 2; // not a character to add to displayArray
break;
case 0x3d:
// change scroll movement
move_control = normal; // normal
goodFont = 2; // not a character to add to displayArray
break;
case 0x3e:
// change scroll movement
move_control = oneRight; // >, move 1 right
goodFont = 2; // not a character to add to displayArray
break;
case 0x5c:
// use 0x5c '\' for backspace to delete characters
move_control = backspace;
goodFont = 2; // not a character to add to displayArray
break;
} // end switch
}
}
void loop () {}
What does static contribute to a constant, global variable?
It specifies internal linkage.
Just one use,
If a variable is declared (.h) as extern ( external linkage ), a static definition of a variable gives the 'defined in' translation unit its own copy initialised to the static initialisation, while other translation units share the definition of external variable.
IIRC "static" global variables are module- (i.e. file-) private. That is, they can't be accessed by other modules (.c(pp) files) even if they host an "extern" declaration that refers to it.
OK. Thanks to both of you for the responses. Most of what I do with the Arduino is all in one file, so I forgot about the need to localize the scope of the variable.
pyro_65, tuxduino, not quite sure what all that means. All my code is either 1 .ino file, or multiple tabs under 1 .ino file.
Not complex enough for .h and .cpp stuff.
I make all my variables global so I can access anything from anywhere in the code. Maybe poor programming practice, but it works for me.
I am not sure why they are disparaged on Arduino, but #define would work here, too.
#define code does not allow for type checking. A #define statement in one file doesn't provide any information that another file can use, unless the #define statement is in a header file that is included in other files.
CrossRoads:
pyro_65, tuxduino, not quite sure what all that means. All my code is either 1 .ino file, or multiple tabs under 1 .ino file.
Not complex enough for .h and .cpp stuff.
I make all my variables global so I can access anything from anywhere in the code. Maybe poor programming practice, but it works for me.
Yes, thats my SOP also. I understand the why and reasons for good scoping practices, especially for large programs being worked on by multiple people, but using mostly globals works well for me in my simple projects. I also avoid trying to create any C++ only features, other then utilizing existing C++ library functions that others have created. Simple straight C for this simple mind seems to be all I really require so far.
I don't think I've see anyone disparage them, you see it used in sketches that are posted.
This is the first time in 2+ years of arduino coding where I had this problem. Lucky?