compiler errors - Page 1
Forum section: electronics / general

author: m3vuv
author_rank: Super Contributor
timestamp: December 13, 2020, 07:02:59 am
content: 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 voltagedelay (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 constant1^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 hereconst 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 ' previously defined hereconst 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 hereconst 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 hereconst 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 hereconst 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 hereint 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 hereunsigned 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 hereint 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 herefloat 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 herefloat 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 herefloat 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 herebyte 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 herebyte 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 herebyte 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 herebool 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 herebool 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 hereButton 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 hereButton 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 herevoid 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 herevoid 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 herevoid 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 herevoid 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 herevoid loop() {^~~~exit status 1expected unqualified-id before numeric constantThis report would have more information with"Show verbose output during compilation"option enabled in File -> Preferences.

author: brucehoult
author_rank: Super Contributor
timestamp: December 13, 2020, 07:36:38 am
content: 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.

author: m3vuv
author_rank: Super Contributor
timestamp: December 13, 2020, 07:42:33 am
content: 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 voltagedelay (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);}}

author: m3vuv
author_rank: Super Contributor
timestamp: December 13, 2020, 07:44:06 am
content: 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 herevoid 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 herevoid loop() {^~~~exit status 1redefinition of 'void setup()'This report would have more information with"Show verbose output during compilation"option enabled in File -> Preferences.

author: retiredfeline
author_rank: Frequent Contributor
timestamp: December 13, 2020, 07:50:47 am
content: I'm guessing you accidentally have two copies of the whole program in one file.

author: Ed.Kloonk
author_rank: Super Contributor
timestamp: December 13, 2020, 07:56:22 am
content: Quote from: retiredfeline on December 13, 2020, 07:50:47 amThat'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.

author: magic
author_rank: Super Contributor
timestamp: December 13, 2020, 10:55:52 am
content: 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.

author: newbrain
author_rank: Super Contributor
timestamp: December 14, 2020, 08:22:55 am
content: Quote from: retiredfeline on December 13, 2020, 07:50:47 amWell, given that they have the exact same post duplicated in "Programming" section, this seems plausible!

author: m3vuv
author_rank: Super Contributor
timestamp: December 16, 2020, 08:38:28 pm
content: sorted,somehow i got a duplicate,deleted a lot and it works,thanks.