custom library problem


[size=12]i have created few custom libraries make code cleaner.
but when declare variable class in library error---error: expected constructor, destructor, or type conversion before ';' token in function 'void loop()':.
here code inside arduino software:[/size]
code: [select]
//include libraries                                                                                                                                                                                                                                        
 #include <sensor.h>
 #include <wheel.h>
 #include <servoview.h>
 
 sensor sight();
 wheel wheels();
 servoview proximity();
 
 void setup() {
   // set other pins you're using outputs:
   
 }

 void loop() {
   
   if (sight.viewisclear())
   {
     wheels.forward(120);
   }
   else
   {
     wheels.reverse(120);
   }

 }


[size=12]here class code:[/size]
code: [select]
#ifndef sensor
#define sensor

#include "wprogram.h"

class sensor
{
 public:
   sensor();
     ~sensor();
     boolean viewisclear();
 private:
     int sensorpin = 4;
     int sensorval = 0;

};

#endif

code: [select]
#include "wprogram.h"
#include "sensor.h"

sensor::sensor()
{

}

boolean sensor::viewisclear()
 {
  sensorval = analogread(sensorpin);
 
 if (sensorval > 370)
 {
  carok = false;
  return false;
 }
 
 else
 return true;
 }

sensor::~sensor()
{

}

code: [select]
     int sensorpin = 4;
     int sensorval = 0;

is not allowed in header unless:
code: [select]
     static const int sensorpin = 4;
     static const int sensorval = 0;



Arduino Forum > Forum 2005-2010 (read only) > Software > Syntax & Programs > custom library problem


arduino

Comments

Popular posts from this blog

CAN'T INSTALL MAMBELFISH 1.5 FROM DIRECTORY - Joomla! Forum - community, help and support

error: expected initializer before 'void'

CPU load monitoring using GPIO and leds - Raspberry Pi Forums