Error: expected initializer before numeric constant

I am getting an error when trying to compile my code, and I've tried to add/remove semicolons from the end of the variables. Here's my code (not yet finished):

#include <U8x8lib.h>;        // Include the OLED Screen library (U8X8)
#define breakout 0;          // If you have broken out the OLED Module, set this to 1
#define ledPin 3;            // Define a PWM capable pin
#define analogIn 0;          // Defines the potentiometer input
int analogVal 0;            // Value of the potentiometer
int PWMOut 0;
int square 0;           // PWM Wave
U8X8_SSD1306_128X64_NONAME_HW_I2C u8x8(/* reset=*/ U8X8_PIN_NONE);  // Tell the OLED library which display you are using
               
void setup() {
  pinMode(ledPin, OUTPUT);   
  pinMode(analogIn, INPUT); // Set pin modes for the LED and potentiometer
  u8x8.begin                // Initialize the OLED Display
  Serial.begin(9600);       // Start serial at 9600 baud
  if(breakout = 0){
    u8x8.setBusClock(100000); // Sets I2C Bus clock speed (Not needed if the module is connected to the PCB) 
  }
                            
  
}

void loop() {
  analogVal = analogRead(analogIn);
  PWMOut = map(analogVal, 0, 1023, 0, 255)
  analogWrite(ledPin, PWMOut)
  u8x8.clear();                                   // Clear the display
  u8x8.setFont(u8x8_font_amstrad_cpc_extended_f); // Set the font
  u8x8.setCursor(0, 0);                           // Set cursor position
  u8x8.print("Input: ");
  u8x8.print(analogVal);
  u8x8.setCursor(0, 33);                          // Set cursor to new line (uses a system similar to coordinates)
  u8x8.print("PWM: ");
  u8x8.print(PWMOut);
  squareWave = digitalRead(ledPin);
  Serial.println(squareWave);

}

Error Messages:

Arduino: 1.8.16 (Windows Store 1.8.51.0) (Windows 10), Board: "Arduino Uno"

LED_PWM:5:15: error: expected initializer before numeric constant

int analogVal 0; // Value of the potentiometer

           ^

LED_PWM:6:12: error: expected initializer before numeric constant

int PWMOut 0;

        ^

LED_PWM:8:12: error: expected initializer before numeric constant

int square 0; // PWM Wave

        ^

C:\Users\antoi\Documents\Arduino\Sketches\Grove Beginner Kit\LED_PWM\LED_PWM.ino: In function 'void setup()':

LED_PWM:3:17: error: expected ')' before ';' token

#define ledPin 3; // Define a PWM capable pin

             ^

C:\Users\antoi\Documents\Arduino\Sketches\Grove Beginner Kit\LED_PWM\LED_PWM.ino:12:11: note: in expansion of macro 'ledPin'

pinMode(ledPin, OUTPUT);

       ^~~~~~

LED_PWM:12:17: error: expected primary-expression before ',' token

pinMode(ledPin, OUTPUT);

             ^

LED_PWM:4:19: error: expected ')' before ';' token

#define analogIn 0; // Defines the potentiometer input

               ^

C:\Users\antoi\Documents\Arduino\Sketches\Grove Beginner Kit\LED_PWM\LED_PWM.ino:13:11: note: in expansion of macro 'analogIn'

pinMode(analogIn, INPUT); // Set pin modes for the LED and potentiometer

       ^~~~~~~~

LED_PWM:13:19: error: expected primary-expression before ',' token

pinMode(analogIn, INPUT); // Set pin modes for the LED and potentiometer

               ^

LED_PWM:15:3: error: expected ';' before 'Serial'

Serial.begin(9600); // Start serial at 9600 baud

^~~~~~

LED_PWM:14:8: error: statement cannot resolve address of overloaded function

u8x8.begin // Initialize the OLED Display


LED_PWM:16:15: error: expected primary-expression before '=' token

if(breakout = 0){

            ^

C:\Users\antoi\Documents\Arduino\Sketches\Grove Beginner Kit\LED_PWM\LED_PWM.ino: In function 'void loop()':

LED_PWM:24:3: error: 'analogVal' was not declared in this scope

analogVal = analogRead(analogIn);

^~~~~~~~~

C:\Users\antoi\Documents\Arduino\Sketches\Grove Beginner Kit\LED_PWM\LED_PWM.ino:24:3: note: suggested alternative: 'analogRead'

analogVal = analogRead(analogIn);

^~~~~~~~~

analogRead

LED_PWM:4:19: error: expected ')' before ';' token

#define analogIn 0;          // Defines the potentiometer input

                ^

C:\Users\antoi\Documents\Arduino\Sketches\Grove Beginner Kit\LED_PWM\LED_PWM.ino:24:26: note: in expansion of macro 'analogIn'

analogVal = analogRead(analogIn);

                       ^~~~~~~~

LED_PWM:24:34: error: expected primary-expression before ')' token

analogVal = analogRead(analogIn);

                               ^

LED_PWM:25:3: error: 'PWMOut' was not declared in this scope

PWMOut = map(analogVal, 0, 1023, 0, 255)

^~~~~~

LED_PWM:26:21: error: expected primary-expression before ',' token

analogWrite(ledPin, PWMOut)

                  ^

LED_PWM:35:3: error: 'squareWave' was not declared in this scope

squareWave = digitalRead(ledPin);

^~~~~~~~~~

C:\Users\antoi\Documents\Arduino\Sketches\Grove Beginner Kit\LED_PWM\LED_PWM.ino:35:3: note: suggested alternative: 'square'

squareWave = digitalRead(ledPin);

^~~~~~~~~~

square

LED_PWM:3:17: error: expected ')' before ';' token

#define ledPin 3;            // Define a PWM capable pin

              ^

C:\Users\antoi\Documents\Arduino\Sketches\Grove Beginner Kit\LED_PWM\LED_PWM.ino:35:28: note: in expansion of macro 'ledPin'

squareWave = digitalRead(ledPin);

                         ^~~~~~

LED_PWM:35:34: error: expected primary-expression before ')' token

squareWave = digitalRead(ledPin);

                               ^

exit status 1

expected initializer before numeric constant



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

You are confusing #define statements with variables. Variables need assignment which is = and end with a ; but defines to not

#define analogIn 0          // Defines the potentiometer input
int analogVal = 0;            // Value of the potentiometer

Note, if analogIn is really one of the analog pins, it would be better to use the Ax notation

#define analogIn A0

Bad syntax:

#define breakout 0          // If you have broken out the OLED Module, set this to 1
#define ledPin 3            // Define a PWM capable pin
#define analogIn 0;         // Defines the potentiometer input
int analogVal = 0;            // Value of the potentiometer
int PWMOut = 0;
int square = 0;           // PWM Wave

Ok. Thanks for the help. Ill be sure to make the changes.

Oops. Looks like I forgot to remove the ';' in:
#define analogIn 0; // Defines the potentiometer input

That should be:
#define analogIn 0 // Defines the potentiometer input

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.