" warning: "B1" redefined" can't upload code to Nano

Hello,

I can’t upload the code to my Arduino Nano, the IDE gets stuck when saying “uploading” or “sending” the code to the Nano, the only warning I get is this one:

D:\Users\abelt\Documents\Arduino\NanoChargerOff_V2\NanoChargerOff_V2.ino:13:0: warning: "B1" redefined

 #define B1  13 //Corresponde a R (LED Vermelho)

 ^

In file included from C:\Users\abelt\AppData\Local\Arduino15\packages\arduino\hardware\avr\1.6.21\cores\arduino/Arduino.h:32:0,

                 from sketch\NanoChargerOff_V2.ino.cpp:1:

C:\Users\abelt\AppData\Local\Arduino15\packages\arduino\hardware\avr\1.6.21\cores\arduino/binary.h:31:0: note: this is the location of the previous definition

 #define B1 1

 ^

The code is the following:

#define S0 8
#define S1 7
#define S2 10
#define S3 11
#define sensorOut 9
//OE liga a  ???

#define RLED  14
#define GLED  15
#define BLED  16
#define WLED  17
#define B1  13 //Corresponde a R (LED Vermelho)
#define B2  18 //Corresponde a G (LED verde)
#define B3  19  //Corresponde a B (LED azul)

#define Rele 12

int frequency = 0;

void setup() 
{
  pinMode(S0, OUTPUT);
  pinMode(S1, OUTPUT);
  pinMode(S2, OUTPUT);
  pinMode(S3, OUTPUT);
  pinMode(sensorOut, INPUT);
  
  // Setting frequency-scaling to 20%
  digitalWrite(S0,HIGH);
  digitalWrite(S1,LOW);
  
  Serial.begin(9600);

  //***

  pinMode(RLED, OUTPUT);
  pinMode(GLED, OUTPUT);
  pinMode(BLED, OUTPUT);
  pinMode(WLED, OUTPUT);
  pinMode(B1, INPUT); //-> RED
  pinMode(B2, INPUT); //-> GREEN
  pinMode(B3, INPUT); //-> BLUE
  
  pinMode(Rele, OUTPUT);
  digitalWrite(Rele, HIGH);

}


void loop() 
{ 

  static  byte LEDs[] = {RLED, GLED, BLED, WLED};
  static  byte Button[] = {B1, B2, B3};
  static  int triggerColor = 0;    


  if(triggerColor == 0)
  {
    digitalWrite(LEDs[0,1,2], HIGH);
    
    while(triggerColor == 0)
    {
      int i;
      for(i = 0; i < 3; i++)
      {
        if(digitalRead(Button[i]) == HIGH)
        {
          while(digitalRead(Button[i]) == HIGH);
          triggerColor = i + 1;
          digitalWrite(Button[0,1,2], LOW);
          
          digitalWrite(Button[i], HIGH);
          delay(500);
          digitalWrite(Button[i], LOW);
        }
      }
    }
  }
  
  
  //****

  if(triggerColor == 1)
  {
    // Setting red filtered photodiodes to be read
    digitalWrite(S2,LOW);
    digitalWrite(S3,LOW);
    // Reading the output frequency
    frequency = pulseIn(sensorOut, LOW);
    // Printing the value on the serial monitor
    Serial.print("R= ");//printing name
    Serial.print(frequency);//printing RED color frequency
    Serial.print("  ");
    delay(100);
  }
  else if(triggerColor == 2)
  {
    // Setting Green filtered photodiodes to be read
    digitalWrite(S2,HIGH);
    digitalWrite(S3,HIGH);
    // Reading the output frequency
    frequency = pulseIn(sensorOut, LOW);
    // Printing the value on the serial monitor
    Serial.print("G= ");//printing name
    Serial.print(frequency);//printing RED color frequency
    Serial.print("  ");
    delay(100);
  }
  else if(triggerColor == 3)
  {
    // Setting Blue filtered photodiodes to be read
    digitalWrite(S2,LOW);
    digitalWrite(S3,HIGH);
    // Reading the output frequency
    frequency = pulseIn(sensorOut, LOW);
    // Printing the value on the serial monitor
    Serial.print("B= ");//printing name
    Serial.print(frequency);//printing RED color frequency
    Serial.println("  ");
    delay(100);
  }

  int TriggerValue = 2000;  //Valor por defeito para o gatilho
  
  //Cód para desligar Relé:
  if(frequency >= TriggerValue)
  {
    digitalWrite(Rele, LOW);
    delay(5000);
    digitalWrite(Rele, HIGH);
  }
  
  //Cód para ajustar intensidade do gatilho
  if(digitalRead(B2) == HIGH)
  {
    while(1)
    {
    
        if(triggerColor == 1) { ReadR(); }
        else if(triggerColor == 2) { ReadG(); }
        else if(triggerColor == 3) { ReadB(); }
        
        static int bright;
        if(frequency > 255)
        {
          analogWrite(WLED, 100);
          bright = (frequency/5);
        }
        else
        {
          analogWrite(WLED, 0);
          bright = frequency;
        }
        
        analogWrite(LEDs[(triggerColor -1)], bright);
    
        if(digitalRead(B2) == HIGH) //Se o intensidade for selecionada
        {
          TriggerValue = frequency; //O valodr do gatilho é registado
          
          digitalWrite(LEDs[0,1,2,3], LOW); //desligam-se todos os LEDs
          
          int o;
          for(o = 0; o < 4; o++)  //Ligam-se todos os LEDs 1 a 1
          {
            digitalWrite(LEDs[o], HIGH);
            delay(250);
          }
          digitalWrite(LEDs[0,1,2,3], LOW); //e desligam-se todos os LEDs outra vez, 
                                            //isto para sinalizar que uma intensidade foi escolhida
          break;
        }

        if(digitalRead(B1) == HIGH)
        {
          break;
        }
        else if(digitalRead(B3) == HIGH)
        {
          break;
        }
    }
  }
  
  //redefinir cores
  if(digitalRead(B1) == HIGH)
  {
    triggerColor = 0;
  }

  //testar so o sensor deteta uma cor
  if(digitalRead(B3) == HIGH)
  {
    while(digitalRead(B3) == HIGH);
    while(1)
    {
      static int i;
      if(i == 0) { ReadR(); }
      else if(i == 1) { ReadG(); }
      else if(i == 2) { ReadB(); }
      else if(i >= 3) { i = 0; }
      
      static int bright;
      if(frequency > 255)
      {
        analogWrite(WLED, 100);
        bright = (frequency/5);
      }
      else
      {
        analogWrite(WLED, 0);
        bright = frequency;
      }
      
      analogWrite(LEDs[i], bright);
    
      if(digitalRead(B3) == HIGH)
      {
        break;
      }
      
      i++;
      
      delay(500);
    } //fim de while(1)
    while(digitalRead(B3) == HIGH);
    digitalWrite(LEDs[0,1,2,3], LOW);
  }
  


  
  delay(3000);
}

void ReadR()
{
      // Setting red filtered photodiodes to be read
    digitalWrite(S2,LOW);
    digitalWrite(S3,LOW);
    // Reading the output frequency
    frequency = pulseIn(sensorOut, LOW);
    // Printing the value on the serial monitor
    Serial.print("R= ");//printing name
    Serial.print(frequency);//printing RED color frequency
    Serial.print("  ");
    delay(100);
}

void ReadG()
{
      // Setting Green filtered photodiodes to be read
    digitalWrite(S2,HIGH);
    digitalWrite(S3,HIGH);
    // Reading the output frequency
    frequency = pulseIn(sensorOut, LOW);
    // Printing the value on the serial monitor
    Serial.print("G= ");//printing name
    Serial.print(frequency);//printing RED color frequency
    Serial.print("  ");
    delay(100);
}

void ReadB()
{
      // Setting Blue filtered photodiodes to be read
    digitalWrite(S2,LOW);
    digitalWrite(S3,HIGH);
    // Reading the output frequency
    frequency = pulseIn(sensorOut, LOW);
    // Printing the value on the serial monitor
    Serial.print("B= ");//printing name
    Serial.print(frequency);//printing RED color frequency
    Serial.println("  ");
    delay(100);
}

Don't use B1, B11, B10 etc - they're all predefined as binary literals by Arduino

Okay, I changed them from B1, B2, B3 to Button1, Button2, Button3

but now when I try to upload the code this message:

avrdude: stk500_getsync() attempt 1 of 10: not in sync: resp=0x53
avrdude: stk500_getsync() attempt 2 of 10: not in sync: resp=0x54
avrdude: stk500_getsync() attempt 3 of 10: not in sync: resp=0x41
avrdude: stk500_getsync() attempt 4 of 10: not in sync: resp=0x54
avrdude: stk500_getsync() attempt 5 of 10: not in sync: resp=0x55
avrdude: stk500_getsync() attempt 6 of 10: not in sync: resp=0x53
avrdude: stk500_getsync() attempt 7 of 10: not in sync: resp=0x09
avrdude: stk500_getsync() attempt 8 of 10: not in sync: resp=0x09
avrdude: stk500_getsync() attempt 9 of 10: not in sync: resp=0x20
avrdude: stk500_getsync() attempt 10 of 10: not in sync: resp=0x3d

This is the “new” code:

#define S0 8
#define S1 7
#define S2 10
#define S3 11
#define sensorOut 9
//OE liga a  ???

#define RLED  14
#define GLED  15
#define BLED  16
#define WLED  17
#define Button1  13 //Corresponde a R (LED Vermelho)
#define Button2  18 //Corresponde a G (LED verde)
#define Button3  19  //Corresponde a B (LED azul)

#define Rele 12

int frequency = 0;

void setup() 
{
  pinMode(S0, OUTPUT);
  pinMode(S1, OUTPUT);
  pinMode(S2, OUTPUT);
  pinMode(S3, OUTPUT);
  pinMode(sensorOut, INPUT);
  
  // Setting frequency-scaling to 20%
  digitalWrite(S0,HIGH);
  digitalWrite(S1,LOW);
  
  Serial.begin(9600);

  //***

  pinMode(RLED, OUTPUT);
  pinMode(GLED, OUTPUT);
  pinMode(BLED, OUTPUT);
  pinMode(WLED, OUTPUT);
  pinMode(Button1, INPUT); //-> RED
  pinMode(Button2, INPUT); //-> GREEN
  pinMode(Button3, INPUT); //-> BLUE
  
  pinMode(Rele, OUTPUT);
  digitalWrite(Rele, HIGH);

}


void loop() 
{ 

  static  byte LEDs[] = {RLED, GLED, BLED, WLED};
  static  byte Button[] = {Button1, Button2, Button3};
  static  int triggerColor = 0;    


  if(triggerColor == 0)
  {
    digitalWrite(LEDs[0,1,2], HIGH);
    
    while(triggerColor == 0)
    {
      int i;
      for(i = 0; i < 3; i++)
      {
        if(digitalRead(Button[i]) == HIGH)
        {
          while(digitalRead(Button[i]) == HIGH);
          triggerColor = i + 1;
          digitalWrite(Button[0,1,2], LOW);
          
          digitalWrite(Button[i], HIGH);
          delay(500);
          digitalWrite(Button[i], LOW);
        }
      }
    }
  }
  
  
  //****

  if(triggerColor == 1)
  {
    // Setting red filtered photodiodes to be read
    digitalWrite(S2,LOW);
    digitalWrite(S3,LOW);
    // Reading the output frequency
    frequency = pulseIn(sensorOut, LOW);
    // Printing the value on the serial monitor
    Serial.print("R= ");//printing name
    Serial.print(frequency);//printing RED color frequency
    Serial.print("  ");
    delay(100);
  }
  else if(triggerColor == 2)
  {
    // Setting Green filtered photodiodes to be read
    digitalWrite(S2,HIGH);
    digitalWrite(S3,HIGH);
    // Reading the output frequency
    frequency = pulseIn(sensorOut, LOW);
    // Printing the value on the serial monitor
    Serial.print("G= ");//printing name
    Serial.print(frequency);//printing RED color frequency
    Serial.print("  ");
    delay(100);
  }
  else if(triggerColor == 3)
  {
    // Setting Blue filtered photodiodes to be read
    digitalWrite(S2,LOW);
    digitalWrite(S3,HIGH);
    // Reading the output frequency
    frequency = pulseIn(sensorOut, LOW);
    // Printing the value on the serial monitor
    Serial.print("B= ");//printing name
    Serial.print(frequency);//printing RED color frequency
    Serial.println("  ");
    delay(100);
  }

  int TriggerValue = 2000;  //Valor por defeito para o gatilho
  
  //Cód para desligar Relé:
  if(frequency >= TriggerValue)
  {
    digitalWrite(Rele, LOW);
    delay(5000);
    digitalWrite(Rele, HIGH);
  }
  
  //Cód para ajustar intensidade do gatilho
  if(digitalRead(Button2) == HIGH)
  {
    while(1)
    {
    
        if(triggerColor == 1) { ReadR(); }
        else if(triggerColor == 2) { ReadG(); }
        else if(triggerColor == 3) { ReadB(); }
        
        static int bright;
        if(frequency > 255)
        {
          analogWrite(WLED, 100);
          bright = (frequency/5);
        }
        else
        {
          analogWrite(WLED, 0);
          bright = frequency;
        }
        
        analogWrite(LEDs[(triggerColor -1)], bright);
    
        if(digitalRead(Button2) == HIGH) //Se o intensidade for selecionada
        {
          TriggerValue = frequency; //O valodr do gatilho é registado
          
          digitalWrite(LEDs[0,1,2,3], LOW); //desligam-se todos os LEDs
          
          int o;
          for(o = 0; o < 4; o++)  //Ligam-se todos os LEDs 1 a 1
          {
            digitalWrite(LEDs[o], HIGH);
            delay(250);
          }
          digitalWrite(LEDs[0,1,2,3], LOW); //e desligam-se todos os LEDs outra vez, 
                                            //isto para sinalizar que uma intensidade foi escolhida
          break;
        }

        if(digitalRead(Button1) == HIGH)
        {
          break;
        }
        else if(digitalRead(Button3) == HIGH)
        {
          break;
        }
    }
  }
  
  //redefinir cores
  if(digitalRead(Button1) == HIGH)
  {
    triggerColor = 0;
  }

  //testar so o sensor deteta uma cor
  if(digitalRead(Button3) == HIGH)
  {
    while(digitalRead(Button3) == HIGH);
    while(1)
    {
      static int i;
      if(i == 0) { ReadR(); }
      else if(i == 1) { ReadG(); }
      else if(i == 2) { ReadB(); }
      else if(i >= 3) { i = 0; }
      
      static int bright;
      if(frequency > 255)
      {
        analogWrite(WLED, 100);
        bright = (frequency/5);
      }
      else
      {
        analogWrite(WLED, 0);
        bright = frequency;
      }
      
      analogWrite(LEDs[i], bright);
    
      if(digitalRead(Button3) == HIGH)
      {
        break;
      }
      
      i++;
      
      delay(500);
    } //fim de while(1)
    while(digitalRead(Button3) == HIGH);
    digitalWrite(LEDs[0,1,2,3], LOW);
  }
  


  
  delay(3000);
}

void ReadR()
{
      // Setting red filtered photodiodes to be read
    digitalWrite(S2,LOW);
    digitalWrite(S3,LOW);
    // Reading the output frequency
    frequency = pulseIn(sensorOut, LOW);
    // Printing the value on the serial monitor
    Serial.print("R= ");//printing name
    Serial.print(frequency);//printing RED color frequency
    Serial.print("  ");
    delay(100);
}

void ReadG()
{
      // Setting Green filtered photodiodes to be read
    digitalWrite(S2,HIGH);
    digitalWrite(S3,HIGH);
    // Reading the output frequency
    frequency = pulseIn(sensorOut, LOW);
    // Printing the value on the serial monitor
    Serial.print("G= ");//printing name
    Serial.print(frequency);//printing RED color frequency
    Serial.print("  ");
    delay(100);
}

void ReadB()
{
      // Setting Blue filtered photodiodes to be read
    digitalWrite(S2,LOW);
    digitalWrite(S3,HIGH);
    // Reading the output frequency
    frequency = pulseIn(sensorOut, LOW);
    // Printing the value on the serial monitor
    Serial.print("B= ");//printing name
    Serial.print(frequency);//printing RED color frequency
    Serial.println("  ");
    delay(100);
}
#define B1  13 //Corresponde a R (LED Vermelho)
#define B2  18 //Corresponde a G (LED verde)
#define B3  19  //Corresponde a B (LED azul)

To save yourself in future, think about including the comment in the literal name.
So, instead of B1, how about

#define LEDVermelho 13

.

In that way, your code is much easier to read.

I'm sorry, I haven't translated the comments to English.

#define Button1 13 //Corresponde a R (LED Vermelho)

The "//Corresponde a R (LED Vermelho)" translated to English means "Matches to a R (Red LED)", the pin 13 it is just a button in front of a LED.

Wait, I just needed to use the Old bootloader for this board.

Thank you for everything AWOL! :slight_smile: