Stray error from byte binary variable ?

Hello,

As I couldn't find a correct answer in the web, and I'm very new in Arduino programing, I dare to ask here.

In the Code below I try to initialize some byte Variables in Binary Format in the afficher(int x) function. But it gives me Errors back.

The Code is from the Web and I changed it a bit. I already tried to use the IDE function Tools/Autoformat and Tools/Fix-Encoding & Reload, without Success and Problems.

It's just for learning and testing.

How could it be solved ?

byte ledPin[8] = {2, 3, 4, 5, 6, 7, 8, 9}; // Numbers of pins on the Arduino
byte code[10] = {63, 6, 91, 79, 102, 109, 124, 7, 127, 103}; // code numbers 0 to 9: 63,6,91,79,102,109,124,7,127,103
int unite = 0;                                    // <U+202D>00111111<U+202C>, <U+202D>0110<U+202C>, <U+202D>01011011<U+202C>, <U+202D>01001111<U+202C>, <U+202D>01100110<U+202C>, <U+202D>01101101<U+202C>, <U+202D>01111100<U+202C>, <U+202D>0111<U+202C>, <U+202D>01111111<U+202C>, <U+202D>01100111<U+202C>
int dizaine = 0;
int duree;

void setup()
{
  randomSeed(analogRead(0));
  Serial.begin(9600);
  for (int i = 0; i <= 8; i++) // configuration of pins 2 to 9 in output
  {
    pinMode(ledPin[i], OUTPUT);
  }
  Serial.println("---------- Number guess Game -----------");
  Serial.println("Type a Number to play : ");
}

// Program principal
void loop()
{
  int i = random(0, 100);
  //duree=millis() / 1000; // stopwatch
  dizaine = i / 10; // Extraction of tens
  unite = i % 10; // Extraction of units

  if (duree >= 100) // RAZ when counter reach 99
  {
    dizaine = 0;
    unite = 0;
  }
  digitalWrite(9, LOW); // selection of units on display
  afficher(code[unite]); // show units
  delay(2000);
  digitalWrite(9, HIGH); // selection of tens on display
  afficher(code[dizaine]); //show tens
  delay(2000);
}

void afficher(int x) // Procedure coding the number in 7 segments
{
  byte zero = B00111111;
  byte one = B0000<U+202D>0110;
  byte two = B01011011;
  byte three = B<U+202D>01001111;
  byte for4 = B01100110;
  byte five = B<U+202D>01101101<U+202C>;
  byte six = B01111100;
  byte seven = B00000111<U+202C>;
  byte eight = B01111111<U+202C>;
  byte nine = B<U+202D>01100111;
  byte chiffre = x;
  byte segment = 0;
  for (int i = 2; i < 9; i++)
  {
    segment = chiffre & 00000001;
    //digitalWrite(i,segment);
    //chiffre=chiffre>>1;
    Serial.flush();
    //while(Serial.available() == 0) {}
    Serial.println(one, DEC);
    if ((Serial.read() - '0') == 0) {
      if ((byte)segment == zero) {
        Serial.print("Win, your Number is correct !");
        Serial.print("0");
      }
    }
    if ((Serial.read() - '0') == 1) {
      if ((byte)segment == one) {
        Serial.print("Win, your Number is correct !");
        Serial.print("1");
      }
    }
    if ((Serial.read() - '0') == 2) {
      if ((byte)segment == two) {
        Serial.print("Win, your Number is correct !");
        Serial.print("2");
      }
    }
    if ((Serial.read() - '0') == 3) {
      if ((byte)segment == three) {
        Serial.print("Win, your Number is correct !");
        Serial.print("3");
      }
    }
    if ((Serial.read() - '0') == 4) {
      if ((byte)segment == for4) {
        Serial.print("Win, your Number is correct !");
        Serial.print("4");
      }
    }
    if ((Serial.read() - '0') == 5) {
      if ((byte)segment == five) {
        Serial.print("Win, your Number is correct !");
        Serial.print("5");
      }
    }
    if ((Serial.read() - '0') == 6) {
      if ((byte)segment == six) {
        Serial.print("Win, your Number is correct !");
        Serial.print("6");
      }
    }
    if ((Serial.read() - '0') == 7) {
      if ((byte)segment == seven) {
        Serial.print("Win, your Number is correct !");
        Serial.print("7");
      }
    }
    if ((Serial.read() - '0') == 8) {
      if ((byte)segment == eight) {
        Serial.print("Win, your Number is correct !");
        Serial.print("8");
      }
    }
    if ((Serial.read() - '0') == 9) {
      if ((byte)segment == nine) {
        Serial.print("Win, your Number is correct !");
        Serial.print("9");
      }
    }
    digitalWrite(i, segment);
    chiffre = chiffre >> 1;
  }
}

Arduino: 1.8.10 (Windows 10), Board: "Arduino/Genuino Uno"
sketch_oct04a:59:20: error: stray '\342' in program
* byte one = 0b0000‭0110;*
* ^*
sketch_oct04a:59:21: error: stray '\200' in program
* byte one = 0b0000‭0110;*
* ^*
sketch_oct04a:59:22: error: stray '\255' in program
* byte one = 0b0000‭0110;*
* ^*
sketch_oct04a:61:18: error: stray '\342' in program
* byte three = 0b‭01001111;*
* ^*
sketch_oct04a:61:19: error: stray '\200' in program
* byte three = 0b‭01001111;*
* ^*
sketch_oct04a:61:20: error: stray '\255' in program
* byte three = 0b‭01001111;*
* ^*
sketch_oct04a:62:17: error: stray '\342' in program
* byte for4 = 0b‭01100110;*
* ^*
sketch_oct04a:62:18: error: stray '\200' in program
* byte for4 = 0b‭01100110;*
* ^*
sketch_oct04a:62:19: error: stray '\255' in program
* byte for4 = 0b‭01100110;*
* ^*
sketch_oct04a:63:17: error: stray '\342' in program
* byte five = 0b‭01101101‬;*
* ^*
sketch_oct04a:63:18: error: stray '\200' in program
* byte five = 0b‭01101101‬;*
* ^*
sketch_oct04a:63:19: error: stray '\255' in program
* byte five = 0b‭01101101‬;*
* ^*
sketch_oct04a:63:28: error: stray '\342' in program
* byte five = 0b‭01101101‬;*
* ^*
sketch_oct04a:63:29: error: stray '\200' in program
* byte five = 0b‭01101101‬;*
* ^*
sketch_oct04a:63:30: error: stray '\254' in program
* byte five = 0b‭01101101‬;*
* ^*
sketch_oct04a:64:16: error: stray '\342' in program
* byte six = 0b‭01111100;*
* ^*
sketch_oct04a:64:17: error: stray '\200' in program
* byte six = 0b‭01111100;*
* ^*
sketch_oct04a:64:18: error: stray '\255' in program
* byte six = 0b‭01111100;*
* ^*
sketch_oct04a:65:26: error: stray '\342' in program
* byte seven = 0b00000111‬;*
* ^*
sketch_oct04a:65:27: error: stray '\200' in program
* byte seven = 0b00000111‬;*
* ^*
sketch_oct04a:65:28: error: stray '\254' in program
* byte seven = 0b00000111‬;*
* ^*
sketch_oct04a:66:26: error: stray '\342' in program
* byte eight = 0b01111111‬;*
* ^*
sketch_oct04a:66:27: error: stray '\200' in program
* byte eight = 0b01111111‬;*
* ^*
sketch_oct04a:66:28: error: stray '\254' in program
* byte eight = 0b01111111‬;*
* ^*
sketch_oct04a:67:17: error: stray '\342' in program
* byte nine = 0b‭01100111;*
* ^*
sketch_oct04a:67:18: error: stray '\200' in program
* byte nine = 0b‭01100111;*
* ^*
sketch_oct04a:67:19: error: stray '\255' in program
* byte nine = 0b‭01100111;*
* ^*
\Documents\Arduino\sketch_oct04a\sketch_oct04a.ino: In function 'void afficher(int)':
sketch_oct04a:59:23: error: expected ',' or ';' before numeric constant
* byte one = 0b0000‭0110;*
* ^~~~*
sketch_oct04a:61:16: error: unable to find numeric literal operator 'operator""b'
* byte three = 0b‭01001111;*
* ^~*
sketch_oct04a:62:15: error: unable to find numeric literal operator 'operator""b'
* byte for4 = 0b‭01100110;*
* ^~*
sketch_oct04a:63:15: error: unable to find numeric literal operator 'operator""b'
* byte five = 0b‭01101101‬;*
* ^~*
sketch_oct04a:64:14: error: unable to find numeric literal operator 'operator""b'
* byte six = 0b‭01111100;*
* ^~*
sketch_oct04a:67:15: error: unable to find numeric literal operator 'operator""b'
* byte nine = 0b‭01100111;*
* ^~*
exit status 1
stray '\342' in program
This report would have more information with
"Show verbose output during compilation"
option enabled in File -> Preferences.

You copy-pasted the code from somewhere that inserted non-printing (ie, invisible) unicode characters. This is common when copy-pasting from websites and word processors (analogous to the classic "smart quote" issue when copying something in quotes from word, except at least there the bogus characters are visible).

Remove them. I think you can even copy the code from the code tags in your own post - IIRC the forum removes the unicode characters from inside code tags to prevent this problem (and I'm not seeing them copy/pasting your code into a text editor that shows them)

Worst case, retyping the lines in question will sort it out.

Hello,

Thank you for the answer.

I tried to copy the code from this post to the IDE, but it is still giving the same Errors.

This Code I typed by my Self :

byte zero = B00111111;
  byte one = B0000<U+202D>0110;
  byte two = B01011011;
  byte three = B<U+202D>01001111;
  byte for4 = B01100110;
  byte five = B<U+202D>01101101<U+202C>;
  byte six = B01111100;
  byte seven = B00000111<U+202C>;
  byte eight = B01111111<U+202C>;
  byte nine = B<U+202D>01100111;

This gives the Error, which I do not understand ?

That is very strange.

Edit: Okay, I see you're compiling for an Uno.

Though, the B******** macros seem to have been getting processed correctly as the preprocessed code that it's showing the error in looks right, so that points away from something to do with the board package.

If you write them as 0b00111111 (for example) instead of B00111111 does that change anything?

What about writing them as hex instead of binary?, eg, 0x3F instead of B00111111? (the first four numbers are 0x3F, 0x06, 0x5B, 0x4F)

And you've copied the whole code in from what you posted to the forums? (just wondering if the stray characters may be somewhere else, but be confusing the compiler enough that it is reporting them in a different place than the characters are)

Also curious about whether it reproduces in 1.8.9 - I hear there were some arduino builder bugs introduced in 1.8.10.

Hello DrAzzy,

Yes I already tried to use "0b" as Format.

Now I tried "0x", the Heximal Format, but it shows also Errors, not much but few :

Arduino: 1.8.10 (Windows 10), Board: "Arduino/Genuino Uno"
sketch_oct04a:42:20: error: stray '\342' in program

  • byte zero = 0x3F;‬*
  • ^*
    sketch_oct04a:42:21: error: stray '\200' in program
  • byte zero = 0x3F;‬*
  • ^*
    sketch_oct04a:42:22: error: stray '\254' in program
  • byte zero = 0x3F;‬*
  • ^*
    sketch_oct04a:47:19: error: stray '\342' in program
  • byte five = 0x6D‬;*
  • ^*
    sketch_oct04a:47:20: error: stray '\200' in program
  • byte five = 0x6D‬;*
  • ^*
    sketch_oct04a:47:21: error: stray '\254' in program
  • byte five = 0x6D‬;*
  • ^*
    sketch_oct04a:50:20: error: stray '\342' in program
  • byte eight = 0x7F‬;*
  • ^*
    sketch_oct04a:50:21: error: stray '\200' in program
  • byte eight = 0x7F‬;*
  • ^*
    sketch_oct04a:50:22: error: stray '\254' in program
  • byte eight = 0x7F‬;*
  • ^*
    exit status 1
    stray '\342' in program
    This report would have more information with
    "Show verbose output during compilation"
    option enabled in File -> Preferences.
  byte zero = 0x3F;<U+202C> 
  byte one = 0x6;
  byte two = 0x5B;
  byte three = 0x4F;
  byte four = 0x66;
  byte five = 0x6D<U+202C>;
  byte six = 0x7C;
  byte seven = 0x7;
  byte eight = 0x7F<U+202C>;
  byte nine = 0x67;

Thank you

with the dodgy characters removed...

byte zero = B00111111;
byte one = B00000110;
byte two = B01011011;
byte three = B01001111;
byte for4 = B01100110;
byte five = B01101101;
byte six = B01111100;
byte seven = B00000111;
byte eight = B01111111;
byte nine = B01100111;

In case you run into this problem again, pasting the code into a decent editor such as Notepad++ and setting the encoding to ansi will make the hidden characters visible.

for (int i = 0; i <= 8; i++) An eight element array has no element with the index 8.
The condition should be "i < 8"

Hello,

Thanks a lot to all and CaptainWow, now it compile and load the Code as well.

Thank you for the hints.

Kind regards