Go Down

Topic: invalid conversion from 'int' to 'void' (Read 1 time) previous topic - next topic

ijultohid

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

this is my full code
Code: [Select]
#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: [Select]
{
  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?

Arrch


JimboZA

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
Roy from ITCrowd: Have you tried turning it off an on again?
I'm on LinkedIn: http://www.linkedin.com/in/jimbrownza

UKHeliBob

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: [Select]
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.
Please do not send me PMs asking for help.  Post in the forum then everyone will benefit from seeing the questions and answers.

ijultohid

Helo guys..thanks for the help before this..
this is my code after editing and it seems doesnt have any error
Code: [Select]
#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: [Select]
Serial.print (Calc, DEC); //Prints the number calculated above

and
Code: [Select]
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..

Go Up