error code expected initializer

Success!

Only error code now is the attach interrupt. I have searched and tried a few things but not found a solution.

I do appreciate all the help and advice given. Its a big learning curve.

#define ENCODER0PINA         20      // this pin needs to support interrupts
#define ENCODER0PINB         18      // interuppt
#define CPR                  400     // encoder cycles per revolution
#define CLOCKWISE            1       // direction constant
#define COUNTER_CLOCKWISE    2       // direction constant

volatile long encoder0Position = 0; // variables modified by interrupt handler must be declared as volatile
volatile long interruptsReceived = 0;
short currentDirection = CLOCKWISE;// track direction: 0 = counter-clockwise; 1 = clockwise
long previousPosition = 0;// track last position to see if worth printing new output
int SENSOR_PIN = 0; // center pin of the potentiometer
int RPWM_Output = 5; // Arduino PWM output pin 5; connect to IBT-2 pin 1 (RPWM)
int LPWM_Output = 6; // Arduino PWM output pin 6; connect to IBT-2 pin 2 (LPWM)


void setup()
{
  Serial.begin(9600);
  Serial.println("<Arduino is ready>");
  pinMode(RPWM_Output, OUTPUT);
  pinMode(LPWM_Output, OUTPUT);
  pinMode(36, INPUT_PULLUP); //home switch

  // inputs
  pinMode(ENCODER0PINA, INPUT_PULLUP);
  pinMode(ENCODER0PINB, INPUT_PULLUP);
  attachInterrupt(20, RISING); // interrupts
  Serial.begin (9600);        // enable diagnostic output
  Serial.println("\n\n\n");
  Serial.println("Ready.");
  analogWrite(LPWM_Output, 100);     //move to home switch
  digitalRead (36);
  if (LOW);
  Serial.println ("Switch closed."); //set encoder to zero, to be coded
  delay (1000);
  analogWrite(RPWM_Output, 100); //move to new start position, to be coded
}

void loop()
{
  if (encoder0Position != previousPosition);
  Serial.print(encoder0Position, DEC);
  Serial.print("\t");
  Serial.print(currentDirection == CLOCKWISE ? "clockwise" : "counter-clockwise");
  Serial.print("\t");
  Serial.println(interruptsReceived, DEC);
  previousPosition = encoder0Position;
  void onInterrupt();    // interrupt function needs to do as little as possible
  int a = digitalRead(ENCODER0PINA);
  int b = digitalRead(ENCODER0PINB);  // read both inputs

  if (a == b)       // b is leading a (counter-clockwise)
  {
    encoder0Position--;
    currentDirection = COUNTER_CLOCKWISE;
  }
  else
  {
    encoder0Position++;      // a is leading b (clockwise)
    currentDirection = CLOCKWISE;
    encoder0Position = encoder0Position % CPR;   // track 0 to 20000
    interruptsReceived++;        // track the number of interrupts
    int sensorVal = digitalRead(36); //read the pushbutton value into a variable
    Serial.println(sensorVal);   //print out the value of the pushbutton
  }
  {
    int sensorValue = analogRead(SENSOR_PIN);
    // sensor value is in the range 0 to 1023
    // the lower half of it we use for reverse rotation; the upper half for forward rotation

    if (sensorValue < 512)
    {
      int reversePWM = -(sensorValue - 511) / 2;  // reverse rotation
      analogWrite(LPWM_Output, 0);
      analogWrite(RPWM_Output, reversePWM);
    }
    else
    {
      int forwardPWM = (sensorValue - 512) / 2;  // forward rotation
      analogWrite(LPWM_Output, forwardPWM);
      analogWrite(RPWM_Output, 0);
    }
  }
}

Error messages,

Arduino: 1.8.7 (Windows 8.1), TD: 1.44, Board: "Arduino/Genuino Mega or Mega 2560, ATmega2560 (Mega 2560)"

C:\Users\HP\Documents\Arduino\formatted\formatted.ino: In function 'void setup()':

C:\Users\HP\Documents\Arduino\formatted\formatted.ino:30:29: warning: invalid conversion from 'int' to 'void (*)()' [-fpermissive]

attachInterrupt(20, RISING); // interrupts

^

formatted:30:29: error: too few arguments to function 'void attachInterrupt(uint8_t, void (*)(), int)'

In file included from sketch\formatted.ino.cpp:1:0:

C:\Program Files (x86)\Arduino\hardware\arduino\avr\cores\arduino/Arduino.h:150:6: note: declared here

void attachInterrupt(uint8_t, void (*)(void), int mode);

^

exit status 1
too few arguments to function 'void attachInterrupt(uint8_t, void (*)(), int)'

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

attachInterrupt(20, RISING); // interrupts
formatted:30:29: error: too few arguments to function 'void attachInterrupt(uint8_t, void (*)(), int)'

If you ever figure that out, then look at where your ISR is buried.

Im hoping with attachInterrupt(20, RISING); // interrupts i have interrupts on pin 20 ?

Would you be able to clarify it so i can see whats incorrect?

Read the reference page for attachInterrupt to see whether your usage is correct:

  attachInterrupt(20, RISING); // interrupts

When a rising signal appears on pin 20 which function should be called ?

Im thinking the interrupts should be called. But could be something else, like read? Ive had a good read of the reference tried a few things but cant figure it out yet. I tried attachInterrupt(digitalPinToInterrupt(20), ISR, RISING); buts thats a no go. im sure its something obvious!

Not sure if it helps, but to do need to be able to count encoder pulses so i can set distances for the servo to move.

You're getting close.

attachInterrupt() may be limited to certain pins. You haven't told us which board you're using so I don't know which pins you can use but they should be documented in the attachInterrupt() reference page.

You're correct that the interrupt triggers an ISR but the attachInterrupt() function takes as its second parameter the name of a function defined in your sketch, which is called from the ISR when the interrupt is triggered. attachInterrupt() is intended to make the use of interrupts more beginner friendly and portable by hiding the low level details in the Arduino core library.

Im using a mega 2560.

Enoder is on Digital pins 18 and 20.

#define ENCODER0PINA 20 // this pin needs to support interrupts
#define ENCODER0PINB 18 // interuppt
#define CPR 400 // encoder cycles per revolution
#define CLOCKWISE 1 // direction constant
#define COUNTER_CLOCKWISE 2 // direction constant

const byte interruptPin = 20;
volatile byte state = LOW;

I added the const byte and volatile lines but they havent helped.

Please post your complete program as it is now

#define ENCODER0PINA         20      // this pin needs to support interrupts
#define ENCODER0PINB         18      // interuppt
#define CPR                  400     // encoder cycles per revolution
#define CLOCKWISE            1       // direction constant
#define COUNTER_CLOCKWISE    2       // direction constant

const byte interruptPin = 20;
volatile byte state = LOW;
volatile long encoder0Position = 0; // variables modified by interrupt handler must be declared as volatile
volatile long interruptsReceived = 0;
short currentDirection = CLOCKWISE;// track direction: 0 = counter-clockwise; 1 = clockwise
long previousPosition = 0;// track last position to see if worth printing new output
int SENSOR_PIN = 0; // center pin of the potentiometer
int RPWM_Output = 5; // Arduino PWM output pin 5; connect to IBT-2 pin 1 (RPWM)
int LPWM_Output = 6; // Arduino PWM output pin 6; connect to IBT-2 pin 2 (LPWM)


void setup()
{
  Serial.begin(9600);
  Serial.println("<Arduino is ready>");
  pinMode(RPWM_Output, OUTPUT);
  pinMode(LPWM_Output, OUTPUT);

  // inputs
  pinMode(ENCODER0PINA, INPUT_PULLUP);
  pinMode(ENCODER0PINB, INPUT_PULLUP);
  pinMode(36, INPUT_PULLUP); //home switch
  pinMode(20, INPUT_PULLUP); //interrupt pin
  attachInterrupt(digitalPinToInterrupt(3),RISING);
  Serial.begin (9600);        // enable diagnostic output
  Serial.println("\n\n\n");
  Serial.println("Ready.");
  analogWrite(LPWM_Output, 100);     //move to home switch
  digitalRead (36);
  if (LOW);
  Serial.println ("Switch closed."); //set encoder to zero, to be coded
  delay (1000);
  analogWrite(RPWM_Output, 100); //move to new start position, to be coded
}

void loop()
{
  if (encoder0Position != previousPosition);
  Serial.print(encoder0Position, DEC);
  Serial.print("\t");
  Serial.print(currentDirection == CLOCKWISE ? "clockwise" : "counter-clockwise");
  Serial.print("\t");
  Serial.println(interruptsReceived, DEC);
  previousPosition = encoder0Position;
  void onInterrupt();    // interrupt function needs to do as little as possible
  int a = digitalRead(ENCODER0PINA);
  int b = digitalRead(ENCODER0PINB);  // read both inputs

  if (a == b)       // b is leading a (counter-clockwise)
  {
    encoder0Position--;
    currentDirection = COUNTER_CLOCKWISE;
  }
  else
  {
    encoder0Position++;      // a is leading b (clockwise)
    currentDirection = CLOCKWISE;
    encoder0Position = encoder0Position % CPR;   // track 0 to 20000
    interruptsReceived++;        // track the number of interrupts
    int sensorVal = digitalRead(36); //read the pushbutton value into a variable
    Serial.println(sensorVal);   //print out the value of the pushbutton
  }
  {
    int sensorValue = analogRead(SENSOR_PIN);
    // sensor value is in the range 0 to 1023
    // the lower half of it we use for reverse rotation; the upper half for forward rotation

    if (sensorValue < 512)
    {
      int reversePWM = -(sensorValue - 511) / 2;  // reverse rotation
      analogWrite(LPWM_Output, 0);
      analogWrite(RPWM_Output, reversePWM);
    }
    else
    {
      int forwardPWM = (sensorValue - 512) / 2;  // forward rotation
      analogWrite(LPWM_Output, forwardPWM);
      analogWrite(RPWM_Output, 0);
    }
  }
}

I havent been able to work out where ive gone wrong on this at all.

i take that i dont need to add ISR.

attachInterrupt(digitalPinToInterrupt(20), RISING); is what i have,

attachInterrupt(digitalPinToInterrupt(interruptPin), ?????, CHANGE);

Thinking something should be where ????? is..... But no idea what.

Read this very closely and see what difference there is between the required syntax and what is in your code. This has already been pointed out to you so many times there are few ways left to demonstrate what needs to be done.

bmachining:
Thinking something should be where ????? is..... But no idea what.

That's where you put the name of the function in your sketch that should be called when the interrupt is triggered. You should really take a little time to study and experiment with the example code on the attachInterrupt() reference page.

You really shouldn't have even started on this project until you understood the basics of each of the individual parts work.
A good place to start is with the example sketches, including the ones under the File > Examples menu and their associated tutorials:
https://www.arduino.cc/en/Tutorial/HomePage
It's much easier to learn when you're starting with known-good code instead of some mess you slapped together. You need to go through each example line by line, not moving on until you understand what each does. Then you should make some modifications and experiments and verify they work as expected to verify that your understanding is correct.

Where i am stuck is what function should be called, more precisely what it needs or should be called.

Doubt its blink, more like count, store etc?

I did start with a code that was meant to work! hence the frustration and questions!

Where i am stuck is what function should be called, more precisely what it needs or should be called.

What do you want to happen when the interrupt is triggered ?
Write the code that does what you want
Put it in a function and give it a name of your choice
Use that function name in attachInterrupt()

Makes sense!

Anyone know of a code for multi turn servo with encoder? might be easier to start with something closer!

Taa

Anyone know of a code for multi turn servo with encoder?

Do you have such a device ?
Can you provide a link to it ?

might be easier to start with something closer!

It might actually be easier to start from scratch rather than hacking code that you do not understand

What exactly do you want to happen when the interrupt is triggered ?

Heres one i prepared earlier,

Servo1.jpg

Servo2.jpg

A link to a device would have been better

Is there any chance that you could provide details of the encoder and the servo ?
Does the servo turn a certain angle when written to or is it the speed and direction that is controlled ?
Does the servo use the normal control signal range of 1000 to 2000 microsecond pulses with 1500 being either stopped or centered depending on the type of servo ?

What exactly do you want to happen when the interrupt is triggered ?

Sorry, no links, i designed and built it myself. It is a 12v DC motor, double gear reduction driving a leadscrew which translates rotary into linear motion. Approx 350KG/cm torque.

Encoder is driven by the leadscrew. It has approx 120mm travel.

So you can see why i need a arduino to control it. Direction control,needs proportional travel controlled by a potentiometer., ie further pot turned further it travels, returning to zero when pot zeroed.
Encoder is 400 P/R incremental optical. I have a home switch to zero encoder count at startup.