error compiling, expected unqualified-id

C:\Program Files (x86)\Arduino\hardware\arduino\avr\cores\arduino/binary.h:31:12: error: expected unqualified-id before numeric constant

#define B1 1

above is the important line of my error message. I am trying to use the adafruit servo shield and a translation of a code that worked for me without it. (actually a few things are different because i am trying to simplify it until I have success in steps. Here is my code.

#include <Wire.h>
#include <Adafruit_PWMServoDriver.h>

Adafruit_PWMServoDriver pwm = Adafruit_PWMServoDriver();

int SERVOMIN = 150;
int SERVOMAX = 600;

int coxa = 56;
int femur = 47;
int tibia = 57;
int x;
int y;
int z;

void setup() {
  // put your setup code here, to run once:

void loop() {
  // put your main code here, to run repeatedly:
int joyx = analogRead(A0);
int joyy = analogRead(A1);
int joyz = analogRead(A2);
int xShift = map(joyx, 0, 1023, -4, 4);
int yShift = map(joyy, 0, 1023, -4, 4);
int zShift = map(joyz, 0, 1023, -4, 4);
x = x + xShift; y = y + yShift; z = z + zShift;
float G = atan(x/y);
float D = (sqrt ((x*x) + (y*y))) + coxa;
float L = sqrt (((D-coxa)*(D-coxa))+(z*z));
float A = acos (((femur*femur)+(tibia*tibia)-(L*L))/(2*femur*tibia));
float B = (acos(((femur*femur)+(L*L)-(tibia*tibia))/(2*femur*L))+acos(((L*L)+(z*z)-((D-coxa)*(D-coxa)))/(2*L*z)));
int G1 = map(degrees(G),0,180,150,600);
int A1 = map(degrees(A),0,180,150,600);
int B1 = map(degrees(B),0,180,150,600); 
pwm.setPWM(0, 0, G1);
int Blue = map(degrees(B),0,180,150,600); 
pwm.setPWM(0, 0, G1);

You've fallen foul of Arduino's bizarre binary handling

When asking for help with a computer problem, please post the complete text of any and all error messages, not just the one you think is the important one.

In this case, I can see what's going on.
B1 is already defined by the Arduino IDE (on the line you quoted - they've got B followed by every permutation of 0's and 1's up to 8 characters #defined to the value of that in binary - see here ), and it's done using a #define, which works like find/replace (this makes the error less obvious). You're trying to use the same name for one of your variables.

To fix, simply rename your B1 to something different.

And while your at it you might want to give it a useful name and make it a const as well :slight_smile:

Single letter names for variables are a bad idea. Many of them are compile time find and replace defines. So your code doesn't come out looking like you think it does. Stay away from one letter names. Use good descriptive names for your variables.