Pages: [1] 2   Go Down
Author Topic: invalid conversion from 'int' to 'void'  (Read 1813 times)
0 Members and 1 Guest are viewing this topic.
Offline Offline
Newbie
*
Karma: 0
Posts: 8
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Hi..I'm new to arduino..i want to developed an automatic valve using a servo motor that will react upon a flow sensor.. but my problem is when I want to verify the code, it keep saying "invalid conversion from 'int' to 'void'" at line -attachInterrupt(0, rpm, RISING); //and the interrupt is attached-

Code:
#include <Servo.h>

Servo myservo;
volatile int NbTopsFan; //measuring the rising edges of the signal
int Calc; 
int potPin = 0; //analog pin ued to connect the sensor
int ledPin = 9;  //select pin for the servo
int val = 0;  //variable to read the value from the analog pin
int rpm;   //This is the function that the interupt calls
void setup()
{
  NbTopsFan++;  //This function measures the rising and falling edge of the
{
  myservo.attach(9); //set up the servo as usual

  pinMode(ledPin, OUTPUT);  //variable to store the value coming from the sensor
  pinMode(potPin, INPUT); //initializes digital pin 0 as an input
  Serial.begin(9600); //for watching the speeds in the serial monitor
  attachInterrupt(0, rpm, RISING); //and the interrupt is attached
}
void loop(){
  NbTopsFan = 0;      //Set NbTops to 0 ready for calculations
  sei();            //Enables interrupts
 val = analogRead(potPin);    // read the value from the sensor
  val = map(val,0,1023,0,179);
  cli();            //Disable interrupts
  Calc = (NbTopsFan * 60 / 7.5); //(Pulse frequency x 60) / 7.5Q, = flow rate
   if (val>79) myservo.writeMicroseconds(0);  //set servo to mid-point
 
   else if (val<80) myservo.writeMicroseconds(1500); 
 
  Serial.print (Calc, DEC); //Prints the number calculated above
  Serial.print (" L/hour\r\n"); //Prints "L/hour" and returns a  new line
  Serial.println(val);
 delay(10);

}

please someone help me..thank you very much
Logged

East Anglia (UK)
Offline Offline
Faraday Member
**
Karma: 118
Posts: 4400
May all of your blinks be without delay()
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

You don't have a function called rpm for the interrupt to call, you have a variable called rpm
Logged

Please do not send me PMs asking for help.  Post in the forum then everyone will benefit from seeing the questions and answers.

UK
Offline Offline
Faraday Member
**
Karma: 100
Posts: 4153
Where is your SSCCE?!?!
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

Quote
Code:
int rpm;   //This is the function that the interupt calls
No it isn't - it's an integer variable that can store between -32768 and 32767.
Logged

Get 10% off all 4D Systems TFT screens this month: use discount code MAJENKO10

0
Online Online
Shannon Member
****
Karma: 222
Posts: 12710
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Your curly braces are also mis-nested - you need to indent your code properly to make it readable.
Logged

[ I won't respond to messages, use the forum please ]

Offline Offline
Newbie
*
Karma: 0
Posts: 8
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

 thank you.. so what is the problem with this line? since its highlighted.. i still don't get it..

Code:
attachInterrupt(0, rpm, RISING); //and the interrupt is attached
-

what its relation to this line:-
Code:
int rpm;   //This is the function that the interupt calls

(in case if I have change the word 'function' to 'variable')
Logged

Offline Offline
Newbie
*
Karma: 0
Posts: 8
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Your curly braces are also mis-nested - you need to indent your code properly to make it readable.

sorry Markt.. can you show me where the code I need to indent? sorry..still learning..
Logged

California
Offline Offline
Faraday Member
**
Karma: 92
Posts: 3447
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

sorry Markt.. can you show me where the code I need to indent? sorry..still learning..

In the Arduino IDE, press Ctrl+T
Logged

Offline Offline
Newbie
*
Karma: 0
Posts: 8
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

sketch_may03a.ino: In function 'void setup()':
sketch_may03a:19: error: invalid conversion from 'int' to 'void (*)()'
sketch_may03a:19: error: initializing argument 2 of 'void attachInterrupt(uint8_t, void (*)(), int)'
sketch_may03a:22: error: a function-definition is not allowed here before '{' token
sketch_may03a:39: error: expected `}' at end of input


These messages show my error..really dont know how to edit the code..
Logged

California
Offline Offline
Faraday Member
**
Karma: 92
Posts: 3447
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

sketch_may03a.ino: In function 'void setup()':
sketch_may03a:19: error: invalid conversion from 'int' to 'void (*)()'
sketch_may03a:19: error: initializing argument 2 of 'void attachInterrupt(uint8_t, void (*)(), int)'
sketch_may03a:22: error: a function-definition is not allowed here before '{' token
sketch_may03a:39: error: expected `}' at end of input


These messages show my error..really dont know how to edit the code..

Each left curly brace should have a corresponding right curly brace.
Logged

Offline Offline
Newbie
*
Karma: 0
Posts: 8
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

sketch_may03a.ino: In function 'void setup()':
sketch_may03a:19: error: invalid conversion from 'int' to 'void (*)()'
sketch_may03a:19: error: initializing argument 2 of 'void attachInterrupt(uint8_t, void (*)(), int)'
sketch_may03a:22: error: a function-definition is not allowed here before '{' token
sketch_may03a:39: error: expected `}' at end of input


These messages show my error..really dont know how to edit the code..

Each left curly brace should have a corresponding right curly brace.

you mean every '{' must be pair with this code '}' also right?
Logged

Offline Offline
Newbie
*
Karma: 0
Posts: 8
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

This is my code after editing, i have change the int to void for the rpm
Code:
void rpm()   //integer function that can store between -32768 and 32767.

this is my full code
Code:
#include <Servo.h>

Servo myservo;
volatile int NbTopsFan; //measuring the rising edges of the signal
int Calc; 
int potPin = 0; //analog pin ued to connect the sensor
int ledPin = 9;  //select pin for the servo
int val = 0;  //variable to read the value from the analog pin
void rpm()   //integer function that can store between -32768 and 32767.

{
  NbTopsFan++;  //This function measures the rising and falling edge of the
}
{
  myservo.attach(9); //set up the servo as usual

  pinMode(ledPin, OUTPUT);  //variable to store the value coming from the sensor
  pinMode(potPin, INPUT); //initializes digital pin 0 as an input
  Serial.begin(9600); //for watching the speeds in the serial monitor
  attachInterrupt(0, rpm, RISING); //and the interrupt is attached
}
void loop()
{
  NbTopsFan = 0;      //Set NbTops to 0 ready for calculations
  sei();            //Enables interrupts
  val = analogRead(potPin);    // read the value from the sensor
  val = map(val,0,1023,0,179);
  cli();            //Disable interrupts
  Calc = (NbTopsFan * 60 / 7.5); //(Pulse frequency x 60) / 7.5Q, = flow rate
   
   if (val>79) myservo.writeMicroseconds(0);  //set servo to mid-point
 
   else if (val<80) myservo.writeMicroseconds(1500); 
 
  Serial.print (Calc, DEC); //Prints the number calculated above
  Serial.print (" L/hour\r\n"); //Prints "L/hour" and returns a  new line
  Serial.println(val);
 delay(10);

}

BUT I still got this error message at this line,
Code:
{
  NbTopsFan++;  //This function measures the rising and falling edge of the
}
{
it says
sketch_may03a:14: error: expected unqualified-id before '{' token

hmm...how do i fix this error?
Logged

California
Offline Offline
Faraday Member
**
Karma: 92
Posts: 3447
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

hmm...how do i fix this error?

See my previous post.
Logged

Johannesburg. UTC+2
Online Online
Faraday Member
**
Karma: 114
Posts: 4952
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

I think you've dived in a bit too deep, too soon with this project.

Interrupts and functions should be "phase II" of your Arduino journey if you are, as you say, new to this.

Phase I ought to be the core learning examples here and then have a look at functions
Logged

The Elders of the Internet know who I am
I'm on LinkedIn: http://www.linkedin.com/in/jimbrownza

East Anglia (UK)
Offline Offline
Faraday Member
**
Karma: 118
Posts: 4400
May all of your blinks be without delay()
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

As Jimbo says, you may have dived in too deep but you can fix the code.
First I suggest that you move the rpm function to the very end of your code as the current layout is confusing both to read and to the compiler.
Code:
void rpm()   //integer function that can store between -32768 and 32767.
{
  NbTopsFan++;  //This function measures the rising and falling edge of the
}
The comments are wrong but that won't affect operation of the program.

Once you have done that you will see more easily that you have no setup() function.  Well, you have the code for it but no function name.  Add the function name and the code will compile.  Whether or not it works or does what you want I do not know.
Logged

Please do not send me PMs asking for help.  Post in the forum then everyone will benefit from seeing the questions and answers.

Offline Offline
Newbie
*
Karma: 0
Posts: 8
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Helo guys..thanks for the help before this..
this is my code after editing and it seems doesnt have any error
Code:
#include <Servo.h>

Servo myservo;
volatile int NbTopsFan; //measuring the rising edges of the signal
int Calc;                               
int hallsensor = 0;    //analogue pin of the sensor
int ledPin = 9;  //select pin for the servo

int val = 0;  //variable to read the value from the analog pin
void rpm()
{
  NbTopsFan++;  //This function measures the rising and falling edge of the
 
}
void setup()
{
 
  myservo.attach(9); //set up the servo as usual
 
   
  pinMode(hallsensor, INPUT); //initializes digital pin 0 as an input
  pinMode(ledPin, OUTPUT);  //variable to store the value coming from the sensor
  Serial.begin(9600); //for watching the speeds in the serial monitor
  attachInterrupt(0, rpm, RISING); //and the interrupt is attached
}

void loop()
{
  NbTopsFan = 0;      //Set NbTops to 0 ready for calculations
  sei();            //Enables interrupts
  delay (1000);      //Wait 1 second
  cli();            //Disable interrupts
  Calc = (NbTopsFan * 60 / 7.5); //(Pulse frequency x 60) / 7.5Q, = flow rate
  val = analogRead(hallsensor); // read the value from sensor
  val = map(val,0,1023,0,179);
  if (val>79)myservo.writeMicroseconds(0);  //set servo to mid-point
 
  else if (val<80)myservo.writeMicroseconds(1500);
 
  Serial.print (Calc, DEC); //Prints the number calculated above
  Serial.println(val);
  Serial.print (" L/hour\r\n"); //Prints "L/hour" and returns a  new line
 delay(10);
}

BUT I still got one problem, why the when I open the serial monitor there are no value for the 'L/hour' although I had write the 
Code:
Serial.print (Calc, DEC); //Prints the number calculated above

and
Code:
Serial.print (" L/hour\r\n"); //Prints "L/hour" and returns a  new line

the serial monitor just look like this:
( Here I attach the serial monitor pic)


Is this the suitable code? any suggestion on what the suitable code for me if I want to control the servo motor degree of rotation due to the flow rate calculate by the flow sensor..


* SERIAL MONITOR.PNG (18.58 KB, 391x367 - viewed 29 times.)
Logged

Pages: [1] 2   Go Up
Jump to: