Code Error Help: Motor Speed Control

Hi, Please help me to debug the error in the following code

#include <Wire.h>
//speed controlling
char crpm[4];int i=0;int rpm;
int interrupt_pin=3; //output pin of the zero cross detector
int digital_pin=10; //input pin of the opto-coupler
int a,start,duration,distance,cur_dis,del,dimming;int actual_rpm;
bool prev=false;
int b,c,d,delay_time=0,dimtime;

long int total_rpm=0;
int j=1;

void setup()
{
Wire.begin(); // join i2c bus (address optional for master)
Serial.begin(9600); // start serial for output
//speed controlling
pinMode(digital_pin, OUTPUT);// Set AC Load pin as output
attachInterrupt(1, zero_crosss_int, RISING); //zero crossing detetctor er output digital pin 3 er sthe connected.

}

void zero_crosss_int(int delay_time) //function to be fired at the zero crossing to dim the light
{
// Firing angle calculation : 1 full 50Hz wave =1/50=20ms
// Every zerocrossing thus: (50Hz)-> 10ms (1/2 Cycle)
// 10ms=10000us
// (10000us - 10us) / 128 = 75 (Approx)

dimtime = delay_time;
digitalWrite(digital_pin, LOW); // No longer trigger the TRIAC (the next zero crossing will swith it off) TRIAC
delayMicroseconds(dimtime); // Wait till firing the TRIAC
digitalWrite(digital_pin, HIGH); // Fire the TRIAC
int ontime=10000-dimtime-10;
delayMicroseconds(ontime); // triac On propogation delay

}

void loop()
{

Wire.requestFrom(8, 4); // request 6 bytes from slave device #8
while (Wire.available()) // slave may send less than requested
{
crpm = Wire.read(); // receive a byte as character

  • i++;*
  • }*
  • i=0;*
  • rpm=atoi(crpm);*
    _ rpm=2*rpm;_
  • total_rpm=total_rpm+rpm;*
  • if (j>49)*
    {
  • actual_rpm=total_rpm/50;*
  • Serial.println(actual_rpm);*
  • //delay(500);*
  • //delay_time setup*
  • if (actual_rpm>1250)*
  • {*
  • delay_time=delay_time+1000;*
  • }*
  • else if ((delay_time>500)&&(actual_rpm<1150))*
  • {*
  • delay_time=delay_time-20;*
  • }*
  • total_rpm=0;*
  • j=0;*
    }
  • zero_crosss_int(delay_time);*
  • j++;*
    }

For starters delay_time is defined twice:

int b,c,d,delay_time=0,dimtime;
const byte interruptPin = 1;
long int total_rpm=0;
int j=1;
int delay_time;

Then, it's not correctly defined:

void zero_crosss_int(delay_time)

Then, you're trying to assign a byte to a char array:

crpm = Wire.read(); // receive a byte as character

speed_control_final.ino: In function 'void setup()':
speed_control_final.ino:20:45: error: invalid conversion from 'void ()(int)' to 'void ()()' [-fpermissive]
In file included from speed_control_final.ino:3:0:
C:\Program Files (x86)\Arduino\hardware\arduino\avr\cores\arduino/Arduino.h:141:6: error: initializing argument 2 of 'void attachInterrupt(uint8_t, void ()(), int)' [-fpermissive]
void attachInterrupt(uint8_t, void (
)(void), int mode);
^
Error compiling.

You can NOT pass values to interrupt service routines.

You can have the ISR use the value in a global variable.

Please debug this code so it gets compiled. The project description can be found at the following link:

#include <Wire.h>
//speed controlling
char crpm[5]; int i = 0; int rpm;
int interrupt_pin = 3; //output pin of the zero cross detector
int digital_pin = 10; //input pin of the opto-coupler
int a, start, duration, distance, cur_dis, del, dimming; int actual_rpm;
bool prev = false;
int b, c, d,dimtime;
volatile int delay_time;

long int total_rpm = 0;
int j = 1;


void setup()
{
  Wire.begin();        // join i2c bus (address optional for master)
  Serial.begin(9600);  // start serial for output
  //speed controlling
  pinMode(digital_pin, OUTPUT);// Set AC Load pin as output
  attachInterrupt(1, zero_crosss_int, RISING); //zero crossing detetctor er output digital pin 3 er sthe connected.


}

void zero_crosss_int()  //function to be fired at the zero crossing to dim the light
{
  // Firing angle calculation : 1 full 50Hz wave =1/50=20ms
  // Every zerocrossing thus: (50Hz)-> 10ms (1/2 Cycle)
  // 10ms=10000us
  // (10000us - 10us) / 128 = 75 (Approx)

  dimtime = delay_time;
  digitalWrite(digital_pin, LOW);    // No longer trigger the TRIAC (the next zero crossing will swith it off) TRIAC
  delayMicroseconds(dimtime);    // Wait till firing the TRIAC
  digitalWrite(digital_pin, HIGH);   // Fire the TRIAC
  int ontime = 10000 - dimtime - 10;
  //delayMicroseconds(ontime);         // triac On propogation delay

}

void loop()
{

  Wire.requestFrom(8, 4);    // request 6 bytes from slave device #8
  while (Wire.available() && i < 4) // slave may send less than requested
  {
    crpm[i] = Wire.read(); // receive a byte as character
    i++;
  }

  if (i > 0) {
    crpm[i] = '\0';
    rpm = atoi(crpm);
    rpm = 2 * rpm;
    total_rpm = total_rpm + rpm;

    if (j > 49)
    {
      actual_rpm = total_rpm / 50;
      Serial.println(actual_rpm);

      //delay(500);

      //delay_time setup
      if (actual_rpm > 1250)
      {
        delay_time = delay_time + 1000;
      }
      else if ((delay_time > 500) && (actual_rpm < 1150))
      {
        delay_time = delay_time - 20;
      }
      total_rpm = 0;
      j = 0;
    }
    //zero_crosss_int(delay_time);
    j++;
    i = 0;
  }
}

the code now compiles but dont be surprised if it doesn’t work as your want it to… donno where you got this code but the logic is messed up IMHO.