Label not defined?

Hey, sorry if my terminology is not on point because I am not the most best with coding ect... I am trying to use:

void loop() {
  // PORTD = 0xA-Left-Right-00000
  // PORTB = 0x00-G-F-E-D-C-B

  PORTD = B01000000;
  goto left;
  PORTD = B00100000;
  goto right;
}

void left() {
  PORTB = B00110011;
  goto loop;
}

void right() {
  PORTB = B00110011;
  goto loop;
}

This code is for multiplexing two seven segment displays. The error I get it:

exit status 1
label 'left' used but not defined

Can someone explain how I'm meat to define these labels before the loop();?

goto expects a label, and really has no place in your program

left() is a function, and should be CALLED:

    left();

Okay, thank for the reply. I'm still not sure got to get my code working? Will my idea not work?

Rrplace the goto right and left with right() and left() and remove the "goto loop"

And you're setting PORTB to the same value in right and left, which I doubt is what you want

goto's should be avoided. Functions work as good and are easy to follow.

Just:

void loop() {
  // PORTD = 0xA-Left-Right-00000
  // PORTB = 0x00-G-F-E-D-C-B

  PORTD = B01000000;
  left();
  PORTD = B00100000;
  right();
}

void left() {
  PORTB = B00110011;
}

void right() {
  PORTB = B00110011;
}

But I have to say, now it will tell you things like B01000000 not defined... That's not the way to notate binary, 0b01000000 is :wink:

septillion:
But I have to say, now it will tell you things like B01000000 not defined... That's not the way to notate binary, 0b01000000 is :wink:

After adding

setup()
{
}

to the code in your reply, I get:

Binary sketch size: 480 bytes (of a 30,720 byte maximum)

So, clearly, B01000000 is defined.

Ah, you are right! :o Never knew Arduino/AVR-GCC accepted B as a binary prefix as well :o Learned something :slight_smile: Although I find 0b more universal :slight_smile:

Never knew Arduino/AVR-GCC accepted B as a binary prefix as well

It doesn't, really. The Arduino.h file contains a bunch of #define statements that make it look like B01000000 is a real value, when it is really nothing more than some text that will be replaced by the preprocessor.

septillion:
Ah, you are right! :o Never knew Arduino/AVR-GCC accepted B as a binary prefix as well :o Learned something :slight_smile: Although I find 0b more universal :slight_smile:

It is really universal except that it is not standard C. It is a gccism. (Though it appears that that clang accepts it, too - I just tried)

0b apparently isn't universal C as well.... ::slight_smile:

0bXXXX is a gcc-ism.
Bxxxxx is an arduino-ism. (which is at least portable to other compilers.)