Author Topic: compiler errors  (Read 1558 times)

0 Members and 1 Guest are viewing this topic.

Offline m3vuvTopic starter

  • Super Contributor
  • ***
  • !
  • Posts: 1738
  • Country: gb
compiler errors
« on: December 13, 2020, 07:02:59 am »
hi all,im trying to load this into a uno but get these errors,any ideas what is wrong?
#include<JC_Button.h>
#include <Adafruit_SSD1306.h>

#define SCREEN_WIDTH 128 // OLED display width, in pixels
#define SCREEN_HEIGHT 64 // OLED display height, in pixels

// Declaration for an SSD1306 display connected to I2C (SDA, SCL pins)
#define OLED_RESET     4 // Reset pin # (or -1 if sharing Arduino reset pin)
Adafruit_SSD1306 display(SCREEN_WIDTH, SCREEN_HEIGHT, &Wire, OLED_RESET);


const float Low_BAT_level = 3.0;
//Current steps with a 3R load (R7)
const int Current [] = {0,100,200,300,400,500,600,700,800,900,1000};
const byte PWM_Pin = 10;
const byte Buzzer = 9;
const int BAT_Pin = A1;
int PWM_Value = 0;
unsigned long Capacity = 0;
int ADC_Value = 0;
float Vcc = 4.28; // Voltage of Arduino 5V pin ( Mesured by Multimeter )
float BAT_Voltage = 0;
float sample =0;
byte Hour = 0, Minute = 0, Second = 0;
bool calc = false, Done = false;
Button UP_Button(2, 25, false, true);
Button Down_Button(3, 25, false, true);


void setup () {
//
Serial.begin(9600);
pinMode(PWM_Pin, OUTPUT);
pinMode(Buzzer, OUTPUT);
analogWrite(PWM_Pin, PWM_Value);
UP_Button.begin();
Down_Button.begin();
display.begin(SSD1306_SWITCHCAPVCC, 0x3C);
display.clearDisplay();
display.setTextColor(WHITE);
display.setTextSize(2);
display.setCursor(12,25);
display.print("EASY TECH");
display.display();
delay(2000);
display.clearDisplay();
display.setTextSize(2);
display.setCursor(2,15);
display.print("Adj Curr:");
display.setCursor(2,40);
display.print("UP/Down:");
display.print("0");
display.display();
}

//************************* End of Setup function *******************************

void loop() {
  UP_Button.read();
  Down_Button.read();
if (UP_Button.wasReleased() && PWM_Value < 256 && calc == false)
 {
  PWM_Value = PWM_Value + 25;
  if(PWM_Value > 256){
    PWM_Value=PWM_Value-25;
  }
  analogWrite(PWM_Pin,PWM_Value);
  display.clearDisplay();
  display.setCursor(2,25);
  display.print("Curr:");   
  display.print(String(Current[PWM_Value / 25])+"mA");
  display.display();
  Serial.println(String(Current[PWM_Value / 25]));
  Serial.print(PWM_Value);
 }
if (Down_Button.wasReleased() && PWM_Value > 1 && calc == false)
{
  PWM_Value = PWM_Value - 25;
  analogWrite(PWM_Pin,PWM_Value);
  display.clearDisplay();
  display.setCursor(2,25);
  display.print("Curr:");   
  display.print(String(Current[PWM_Value / 25])+"mA");
  display.display();
  Serial.println(String(Current[PWM_Value / 25]) + "mA");
 
}

if (UP_Button.pressedFor (1000) && calc == false)
{
  digitalWrite(Buzzer, HIGH);
  delay(100);
  digitalWrite(Buzzer, LOW);
  display.clearDisplay();
  timerInterrupt();
   
  }
}

//************************* End of Loop function *******************************

void timerInterrupt(){
  calc = true;
  while (Done == false)  {
     Second ++;
    if (Second == 60)  {
      Second = 0;
      Minute ++;     
    }
    if (Minute == 60)  {
      Minute = 0;
      Hour ++;
    }

 //************ Measuring Battery Voltage ***********
 
  for(int i=0;i< 100;i++)
  {
   sample=sample+analogRead(BAT_Pin); //read the Battery voltage
   delay (2);
  }
  sample=sample/100;
  BAT_Voltage = sample * Vcc/ 1024.0;
 
  //*********************************************

    display.clearDisplay();
    display.setTextSize(2);
    display.setCursor(20,5);
    display.print(String(Hour) + ":" + String(Minute) + ":" + String(Second));

    display.setTextSize(1);
    display.setCursor(0,25);
    display.print("Disch Curr: ");   
    display.print(String(Current[PWM_Value / 25])+"mA");
     
   
    display.setCursor(2,40);   
    display.print("Bat Volt:" + String(BAT_Voltage)+"V" );



    Capacity =  (Hour * 3600) + (Minute * 60) + Second;
    Capacity = (Capacity * Current[PWM_Value / 25]) / 3600;
    display.setCursor(2, 55);
    display.print("Capacity:" + String(Capacity) + "mAh");
    display.display();

   
    if (BAT_Voltage < Low_BAT_level)
    {
      Capacity =  (Hour * 3600) + (Minute * 60) + Second;
      Capacity = (Capacity * Current[PWM_Value / 25]) / 3600;
      display.clearDisplay();
      display.setTextSize(2);     
      display.setCursor(2,15);     
      display.print("Capacity:");
      display.setCursor(2,40);
      display.print(String(Capacity) + "mAh");
      display.display();
      Done = true;
      PWM_Value = 0;
      analogWrite(PWM_Pin, PWM_Value);
      digitalWrite(Buzzer, HIGH);
      delay(100);
      digitalWrite(Buzzer, LOW);
      delay(100);
      digitalWrite(Buzzer, HIGH);
      delay(100);
      digitalWrite(Buzzer, LOW);
      delay(100);
    }
       delay(1000);
  }
   
}

i get these errors:Arduino: 1.8.13 (Windows 7), Board: "Arduino Uno"





















sketch_dec13a:180:1: error: expected unqualified-id before numeric constant

 1

 ^

sketch_dec13a:371:13: error: redefinition of 'const float Low_BAT_level'

 const float Low_BAT_level = 3.0;

             ^~~~~~~~~~~~~

C:\Users\me\Desktop\sketch_dec13a\sketch_dec13a.ino:13:13: note: 'const float Low_BAT_level' previously defined here

 const float Low_BAT_level = 3.0;

             ^~~~~~~~~~~~~

sketch_dec13a:373:20: error: redefinition of 'const int Current []'

 const int Current [] = {0,100,200,300,400,500,600,700,800,900,1000};

                    ^

C:\Users\me\Desktop\sketch_dec13a\sketch_dec13a.ino:15:11: note: 'const int Current [11]' previously defined here

 const int Current [] = {0,100,200,300,400,500,600,700,800,900,1000};

           ^~~~~~~

sketch_dec13a:374:12: error: redefinition of 'const byte PWM_Pin'

 const byte PWM_Pin = 10;

            ^~~~~~~

C:\Users\me\Desktop\sketch_dec13a\sketch_dec13a.ino:16:12: note: 'const byte PWM_Pin' previously defined here

 const byte PWM_Pin = 10;

            ^~~~~~~

sketch_dec13a:375:12: error: redefinition of 'const byte Buzzer'

 const byte Buzzer = 9;

            ^~~~~~

C:\Users\me\Desktop\sketch_dec13a\sketch_dec13a.ino:17:12: note: 'const byte Buzzer' previously defined here

 const byte Buzzer = 9;

            ^~~~~~

sketch_dec13a:376:11: error: redefinition of 'const int BAT_Pin'

 const int BAT_Pin = A1;

           ^~~~~~~

C:\Users\me\Desktop\sketch_dec13a\sketch_dec13a.ino:18:11: note: 'const int BAT_Pin' previously defined here

 const int BAT_Pin = A1;

           ^~~~~~~

sketch_dec13a:377:5: error: redefinition of 'int PWM_Value'

 int PWM_Value = 0;

     ^~~~~~~~~

C:\Users\me\Desktop\sketch_dec13a\sketch_dec13a.ino:19:5: note: 'int PWM_Value' previously defined here

 int PWM_Value = 0;

     ^~~~~~~~~

sketch_dec13a:378:15: error: redefinition of 'long unsigned int Capacity'

 unsigned long Capacity = 0;

               ^~~~~~~~

C:\Users\me\Desktop\sketch_dec13a\sketch_dec13a.ino:20:15: note: 'long unsigned int Capacity' previously defined here

 unsigned long Capacity = 0;

               ^~~~~~~~

sketch_dec13a:379:5: error: redefinition of 'int ADC_Value'

 int ADC_Value = 0;

     ^~~~~~~~~

C:\Users\me\Desktop\sketch_dec13a\sketch_dec13a.ino:21:5: note: 'int ADC_Value' previously defined here

 int ADC_Value = 0;

     ^~~~~~~~~

sketch_dec13a:380:7: error: redefinition of 'float Vcc'

 float Vcc = 4.28; // Voltage of Arduino 5V pin ( Mesured by Multimeter )

       ^~~

C:\Users\me\Desktop\sketch_dec13a\sketch_dec13a.ino:22:7: note: 'float Vcc' previously defined here

 float Vcc = 4.28; // Voltage of Arduino 5V pin ( Mesured by Multimeter )

       ^~~

sketch_dec13a:381:7: error: redefinition of 'float BAT_Voltage'

 float BAT_Voltage = 0;

       ^~~~~~~~~~~

C:\Users\me\Desktop\sketch_dec13a\sketch_dec13a.ino:23:7: note: 'float BAT_Voltage' previously defined here

 float BAT_Voltage = 0;

       ^~~~~~~~~~~

sketch_dec13a:382:7: error: redefinition of 'float sample'

 float sample =0;

       ^~~~~~

C:\Users\me\Desktop\sketch_dec13a\sketch_dec13a.ino:24:7: note: 'float sample' previously defined here

 float sample =0;

       ^~~~~~

sketch_dec13a:383:6: error: redefinition of 'byte Hour'

 byte Hour = 0, Minute = 0, Second = 0;

      ^~~~

C:\Users\me\Desktop\sketch_dec13a\sketch_dec13a.ino:25:6: note: 'byte Hour' previously defined here

 byte Hour = 0, Minute = 0, Second = 0;

      ^~~~

sketch_dec13a:383:16: error: redefinition of 'byte Minute'

 byte Hour = 0, Minute = 0, Second = 0;

                ^~~~~~

C:\Users\me\Desktop\sketch_dec13a\sketch_dec13a.ino:25:16: note: 'byte Minute' previously defined here

 byte Hour = 0, Minute = 0, Second = 0;

                ^~~~~~

sketch_dec13a:383:28: error: redefinition of 'byte Second'

 byte Hour = 0, Minute = 0, Second = 0;

                            ^~~~~~

C:\Users\me\Desktop\sketch_dec13a\sketch_dec13a.ino:25:28: note: 'byte Second' previously defined here

 byte Hour = 0, Minute = 0, Second = 0;

                            ^~~~~~

sketch_dec13a:384:6: error: redefinition of 'bool calc'

 bool calc = false, Done = false;

      ^~~~

C:\Users\me\Desktop\sketch_dec13a\sketch_dec13a.ino:26:6: note: 'bool calc' previously defined here

 bool calc = false, Done = false;

      ^~~~

sketch_dec13a:384:20: error: redefinition of 'bool Done'

 bool calc = false, Done = false;

                    ^~~~

C:\Users\me\Desktop\sketch_dec13a\sketch_dec13a.ino:26:20: note: 'bool Done' previously defined here

 bool calc = false, Done = false;

                    ^~~~

sketch_dec13a:385:17: error: redefinition of 'Button UP_Button'

 Button UP_Button(2, 25, false, true);

                 ^

C:\Users\me\Desktop\sketch_dec13a\sketch_dec13a.ino:27:8: note: 'Button UP_Button' previously declared here

 Button UP_Button(2, 25, false, true);

        ^~~~~~~~~

sketch_dec13a:386:19: error: redefinition of 'Button Down_Button'

 Button Down_Button(3, 25, false, true);

                   ^

C:\Users\me\Desktop\sketch_dec13a\sketch_dec13a.ino:28:8: note: 'Button Down_Button' previously declared here

 Button Down_Button(3, 25, false, true);

        ^~~~~~~~~~~

C:\Users\me\Desktop\sketch_dec13a\sketch_dec13a.ino: In function 'void setup()':

sketch_dec13a:389:6: error: redefinition of 'void setup()'

 void setup () {

      ^~~~~

C:\Users\me\Desktop\sketch_dec13a\sketch_dec13a.ino:31:6: note: 'void setup()' previously defined here

 void setup () {

      ^~~~~

C:\Users\me\Desktop\sketch_dec13a\sketch_dec13a.ino: In function 'void loop()':

sketch_dec13a:417:6: error: redefinition of 'void loop()'

 void loop() {

      ^~~~

C:\Users\me\Desktop\sketch_dec13a\sketch_dec13a.ino:59:6: note: 'void loop()' previously defined here

 void loop() {

      ^~~~

C:\Users\me\Desktop\sketch_dec13a\sketch_dec13a.ino: In function 'void timerInterrupt()':

sketch_dec13a:461:6: error: redefinition of 'void timerInterrupt()'

 void timerInterrupt(){

      ^~~~~~~~~~~~~~

C:\Users\me\Desktop\sketch_dec13a\sketch_dec13a.ino:103:6: note: 'void timerInterrupt()' previously defined here

 void timerInterrupt(){

      ^~~~~~~~~~~~~~

C:\Users\me\Desktop\sketch_dec13a\sketch_dec13a.ino: In function 'void setup()':

sketch_dec13a:536:7: error: redefinition of 'void setup()'

  void setup() {

       ^~~~~

C:\Users\me\Desktop\sketch_dec13a\sketch_dec13a.ino:31:6: note: 'void setup()' previously defined here

 void setup () {

      ^~~~~

C:\Users\me\Desktop\sketch_dec13a\sketch_dec13a.ino: In function 'void loop()':

sketch_dec13a:541:6: error: redefinition of 'void loop()'

 void loop() {

      ^~~~

C:\Users\me\Desktop\sketch_dec13a\sketch_dec13a.ino:59:6: note: 'void loop()' previously defined here

 void loop() {

      ^~~~

exit status 1

expected unqualified-id before numeric constant



This report would have more information with
"Show verbose output during compilation"
option enabled in File -> Preferences.
 

Online brucehoult

  • Super Contributor
  • ***
  • Posts: 4455
  • Country: nz
Re: compiler errors
« Reply #1 on: December 13, 2020, 07:36:38 am »
You showed 176 lines of code and your errors start on line 180, so it's pretty hard to help you other than to say that your program seems to be longer than you think it is. And you repeated lots of things after line 180 that already happened before line 180.
 

Offline m3vuvTopic starter

  • Super Contributor
  • ***
  • !
  • Posts: 1738
  • Country: gb
Re: compiler errors
« Reply #2 on: December 13, 2020, 07:42:33 am »
try this. #include<JC_Button.h>
#include <Adafruit_SSD1306.h>

#define SCREEN_WIDTH 128 // OLED display width, in pixels
#define SCREEN_HEIGHT 64 // OLED display height, in pixels

// Declaration for an SSD1306 display connected to I2C (SDA, SCL pins)
#define OLED_RESET     4 // Reset pin # (or -1 if sharing Arduino reset pin)
Adafruit_SSD1306 display(SCREEN_WIDTH, SCREEN_HEIGHT, &Wire, OLED_RESET);


const float Low_BAT_level = 3.0;
//Current steps with a 3R load (R7)
const int Current [] = {0,100,200,300,400,500,600,700,800,900,1000};
const byte PWM_Pin = 10;
const byte Buzzer = 9;
const int BAT_Pin = A1;
int PWM_Value = 0;
unsigned long Capacity = 0;
int ADC_Value = 0;
float Vcc = 4.28; // Voltage of Arduino 5V pin ( Mesured by Multimeter )
float BAT_Voltage = 0;
float sample =0;
byte Hour = 0, Minute = 0, Second = 0;
bool calc = false, Done = false;
Button UP_Button(2, 25, false, true);
Button Down_Button(3, 25, false, true);


void setup () {
//
Serial.begin(9600);
pinMode(PWM_Pin, OUTPUT);
pinMode(Buzzer, OUTPUT);
analogWrite(PWM_Pin, PWM_Value);
UP_Button.begin();
Down_Button.begin();
display.begin(SSD1306_SWITCHCAPVCC, 0x3C);
display.clearDisplay();
display.setTextColor(WHITE);
display.setTextSize(2);
display.setCursor(12,25);
display.print("EASY TECH");
display.display(); 
delay(2000);
display.clearDisplay();
display.setTextSize(2);
display.setCursor(2,15);
display.print("Adj Curr:");
display.setCursor(2,40);
display.print("UP/Down:");
display.print("0");
display.display(); 
}

//************************* End of Setup function *******************************

void loop() {
  UP_Button.read();
  Down_Button.read();
if (UP_Button.wasReleased() && PWM_Value < 256 && calc == false)
 {
  PWM_Value = PWM_Value + 25;
  if(PWM_Value > 256){
    PWM_Value=PWM_Value-25;
  }
  analogWrite(PWM_Pin,PWM_Value);
  display.clearDisplay();
  display.setCursor(2,25);
  display.print("Curr:");   
  display.print(String(Current[PWM_Value / 25])+"mA");
  display.display(); 
  Serial.println(String(Current[PWM_Value / 25]));
  Serial.print(PWM_Value);
 }
if (Down_Button.wasReleased() && PWM_Value > 1 && calc == false)
{
  PWM_Value = PWM_Value - 25;
  analogWrite(PWM_Pin,PWM_Value);
  display.clearDisplay();
  display.setCursor(2,25);
  display.print("Curr:");   
  display.print(String(Current[PWM_Value / 25])+"mA");
  display.display(); 
  Serial.println(String(Current[PWM_Value / 25]) + "mA");
 
}

if (UP_Button.pressedFor (1000) && calc == false)
{
  digitalWrite(Buzzer, HIGH);
  delay(100);
  digitalWrite(Buzzer, LOW);
  display.clearDisplay();
  timerInterrupt();
   
  }
}

//************************* End of Loop function *******************************

void timerInterrupt(){
  calc = true;
  while (Done == false)  {
     Second ++;
    if (Second == 60)  {
      Second = 0;
      Minute ++;     
    }
    if (Minute == 60)  {
      Minute = 0;
      Hour ++;
    }

 //************ Measuring Battery Voltage ***********
 
  for(int i=0;i< 100;i++)
  {
   sample=sample+analogRead(BAT_Pin); //read the Battery voltage
   delay (2);
  }
  sample=sample/100;
  BAT_Voltage = sample * Vcc/ 1024.0;
 
  //*********************************************

    display.clearDisplay();
    display.setTextSize(2);
    display.setCursor(20,5);
    display.print(String(Hour) + ":" + String(Minute) + ":" + String(Second));

    display.setTextSize(1);
    display.setCursor(0,25);
    display.print("Disch Curr: ");   
    display.print(String(Current[PWM_Value / 25])+"mA");
     
   
    display.setCursor(2,40);   
    display.print("Bat Volt:" + String(BAT_Voltage)+"V" );



    Capacity =  (Hour * 3600) + (Minute * 60) + Second;
    Capacity = (Capacity * Current[PWM_Value / 25]) / 3600;
    display.setCursor(2, 55);
    display.print("Capacity:" + String(Capacity) + "mAh");
    display.display();

   
    if (BAT_Voltage < Low_BAT_level)
    {
      Capacity =  (Hour * 3600) + (Minute * 60) + Second;
      Capacity = (Capacity * Current[PWM_Value / 25]) / 3600;
      display.clearDisplay();
      display.setTextSize(2);     
      display.setCursor(2,15);     
      display.print("Capacity:");
      display.setCursor(2,40); 
      display.print(String(Capacity) + "mAh");
      display.display();
      Done = true;
      PWM_Value = 0;
      analogWrite(PWM_Pin, PWM_Value);
      digitalWrite(Buzzer, HIGH);
      delay(100);
      digitalWrite(Buzzer, LOW);
      delay(100);
      digitalWrite(Buzzer, HIGH);
      delay(100);
      digitalWrite(Buzzer, LOW);
      delay(100);
    }
       delay(1000);
  }
   
}

 

Offline m3vuvTopic starter

  • Super Contributor
  • ***
  • !
  • Posts: 1738
  • Country: gb
Re: compiler errors
« Reply #3 on: December 13, 2020, 07:44:06 am »
heres the errors i get:Arduino: 1.8.13 (Windows 7), Board: "Arduino Uno"





















C:\Users\me\Desktop\sketch_dec13b\sketch_dec13b.ino: In function 'void setup()':

sketch_dec13b:178:6: error: redefinition of 'void setup()'

 void setup() {

      ^~~~~

C:\Users\me\Desktop\sketch_dec13b\sketch_dec13b.ino:30:6: note: 'void setup()' previously defined here

 void setup () {

      ^~~~~

C:\Users\me\Desktop\sketch_dec13b\sketch_dec13b.ino: In function 'void loop()':

sketch_dec13b:183:6: error: redefinition of 'void loop()'

 void loop() {

      ^~~~

C:\Users\me\Desktop\sketch_dec13b\sketch_dec13b.ino:58:6: note: 'void loop()' previously defined here

 void loop() {

      ^~~~

exit status 1

redefinition of 'void setup()'



This report would have more information with
"Show verbose output during compilation"
option enabled in File -> Preferences.
 

Offline retiredfeline

  • Frequent Contributor
  • **
  • Posts: 572
  • Country: au
Re: compiler errors
« Reply #4 on: December 13, 2020, 07:50:47 am »
I'm guessing you accidentally have two copies of the whole program in one file.
 

Offline Ed.Kloonk

  • Super Contributor
  • ***
  • Posts: 4000
  • Country: au
  • Cat video aficionado
Re: compiler errors
« Reply #5 on: December 13, 2020, 07:56:22 am »
I'm guessing you accidentally have two copies of the whole program in one file.

That's what I'm wondering. Why is void setup and void loop throwing an error.

Really need to pair this back to square one, I think.
iratus parum formica
 

Online magic

  • Super Contributor
  • ***
  • Posts: 7154
  • Country: pl
Re: compiler errors
« Reply #6 on: December 13, 2020, 10:55:52 am »
TL;DR but either the above or you are including some header file twice. This may happen if you include a header which includes another header you have already included, and if the header files have no protection from multiple inclusion.
 

Offline newbrain

  • Super Contributor
  • ***
  • Posts: 1765
  • Country: se
Re: compiler errors
« Reply #7 on: December 14, 2020, 08:22:55 am »
I'm guessing you accidentally have two copies of the whole program in one file.
Well, given that they have the exact same post duplicated in "Programming" section, this seems plausible!  :-DD
Nandemo wa shiranai wa yo, shitteru koto dake.
 
The following users thanked this post: Ed.Kloonk, retiredfeline

Offline m3vuvTopic starter

  • Super Contributor
  • ***
  • !
  • Posts: 1738
  • Country: gb
Re: compiler errors
« Reply #8 on: December 16, 2020, 08:38:28 pm »
sorted,somehow i got a duplicate,deleted a lot and it works,thanks.
 


Share me

Digg  Facebook  SlashDot  Delicious  Technorati  Twitter  Google  Yahoo
Smf