Hey guys, I've been searching for help on this for hours and can't find it. Created a file SonarSensor.h:
#ifndef SonarSensor
#define SonarSensor
#include <WProgram.h>
//SonarSensor.h: a class to abstract the sonar sensors, since there will be multiple.
class SonarSensor
{
public:
SonarSensor(int digitalPin, int analogOutputPin);
int getRawReading();
int getScaledReading();
private:
void pulse();
float scaleFactor;
int RXpin, int ANpin; //digital control and analog output, respectively
};
#endif
and SonarSensor.cpp:
#include <WProgram.h>
#include "SonarSensor.h"
//SonarSensor.cpp: a class to abstract the sonar sensors, since there will be multiple.
void SonarSensor::pulse()
{
//pulse sonar
digitalWrite(RXpin, LOW);
digitalWrite(RXpin, HIGH);
delay(5);
digitalWrite(RXpin, LOW);
}
SonarSensor::SonarSensor(int digitalPin, int analogOutputPin)
{
scaleFactor = 0.5f; //can't initalize otherwise
RXpin = digitalPin;
ANpin = analogOutputPin;
pinMode(RXpin, OUTPUT);
pinMode(ANpin, INPUT);
}
//returns raw sonar value, only useful for debugging
int SonarSensor::getRawReading()
{
pulse();
return analogRead(ANpin);
}
//returns the sonar value in inches
int SonarSensor::getScaledReading()
{
return getRawReading() * scaleFactor;
}
put them in a folder, put them in a library, and tried creating a file to test it:
#include "SonarSensor.h"
void setup()
{}
void loop()
{}
here are the errors I'm getting:
C:\Documents and Settings\acm\Desktop\arduino-0017\hardware\libraries\SonarSensor\/SonarSensor.h:9: error: expected unqualified-id before 'int'
C:\Documents and Settings\acm\Desktop\arduino-0017\hardware\libraries\SonarSensor\/SonarSensor.h:9: error: expected `)' before 'int'
C:\Documents and Settings\acm\Desktop\arduino-0017\hardware\libraries\SonarSensor\/SonarSensor.h:16: error: expected unqualified-id before 'int'
..(and more)
I have no idea what the heck "expected unqualified-id before 'int'" means. using Arduino 0018 alpha on Windows XP. Please help!