expected initializer before...

Status
Not open for further replies.

Gripporillat

Well-known member
Hi everybody!

I get this error but I can't figure it out:
"expected initializer before 'MIDIchannel'"



Code:
#include "SkyController.h"
byte MIDIchannel = 1;
SkyPoti poti(A0, 1);



void setup() {
}

void loop() {
  poti.send();
}

Your help will be highly appreciated! :)


Edit:

This is SkyController.h:

Code:
#ifndef SkyController_h
#define SkyController_h

#include "SkyPoti.h"


#endif

This is Skypoti.h

Code:
#ifndef SkyPoti_h
#define SkyPoti_h



#include "Arduino.h"
#define NOW true

class SkyPoti
{
  public:
	SkyPoti(int pin, int number);
    void send(bool now=false);
  private:
	int _value;
	int _pin;
	int _number;
	int read();
    
}


#endif

This is Skypoti.cpp

Code:
#include "Arduino.h"
#include "SkyPoti.h"

//Constructor
SkyPoti::Skypoti(int pin, int number) {
	pinMode(pin, INPUT);
	_pin = pin;
	_value = 0;
	_number = number;
}

//reads pin, converts into MIDI value and returns value
int SkyPoti::read() {
	return round(analogRead(_pin)/(1023/127));
}

//sends directly if NOW, otherwise checks for alteration and sends if so
void SkyPoti::send(bool now) {
	if (now) {
	usbMIDI.sendControlChange(_number, _value, MIDIchannel);
	} else if (this->read()!= _value) {
	_value = this->read();
	usbMIDI.sendControlChange(_number, _value, MIDIchannel);
	}
}
 
You're missing a semicolon ';' after the class definition in Skypoti.h.

It should be this:

Code:
#ifndef SkyPoti_h
#define SkyPoti_h



#include "Arduino.h"
#define NOW true

class SkyPoti
{
  public:
	SkyPoti(int pin, int number);
    void send(bool now=false);
  private:
	int _value;
	int _pin;
	int _number;
	int read();
    
};  //  <--- added semicolon here


#endif
 
You need a ';' at the end of your class declaration:
Code:
class SkyPoti
{
  public:
	SkyPoti(int pin, int number);
    void send(bool now=false);
  private:
	int _value;
	int _pin;
	int _number;
	int read();
    
};
 
Thank you guys!

After fixing it, this is the next error which I don't understand: error:

"ISO C++ forbids declaration of 'Skypoti' with no type [-fpermissive]

SkyPoti::Skypoti(int pin, int number, byte channel)"


I thought constructors must not have return types?
 
Is it a problem with the case of the p .vs. P ? :: SkyPoti::Skypoti(

And is the code changed to a third param?

Code:
class SkyPoti
{
  public:
	SkyPoti(int pin, int number);
 
Status
Not open for further replies.
Back
Top