Hi
I'm new to programming and to Arduino (Uno) and am having trouble understanding how to solve an error code "expected constructor, destructor or type conversion before ';' token" in the following code. I've solve a lot of other issues but stuck on this one. The error message appears to be connected to the line
void_lowlevel_ReadEncoder(int &rotate,int& press)
If anybody can spot my mistake I'd be very grateful. The code is to operate a magnetic sensor connected to an encoder and Uno the idea being to plot the magnetic field against distance. It was working but I've messed it up somehow.
#include <Wire.h>
#include<Adafruit_LSM303.h>
Adafruit_LSM303 lsm;
int val;
int totmag;
// Digital pin definitions
enum enDigitalPins
{
// Rotary encoder input lines
dpInEncoderA=2,
dpInEncoderB=4,
dpInEncoderPress=6,
};
static void _ResetPins()
{
// Rotary encoder input lines
// Configure as input, turn on pullup resistors
pinMode(dpInEncoderA, INPUT);
digitalWrite(dpInEncoderA, HIGH);
pinMode(dpInEncoderB, INPUT);
digitalWrite(dpInEncoderB, HIGH);
pinMode(dpInEncoderPress, INPUT);
digitalWrite(dpInEncoderPress, HIGH);
}
void setup()
{
//configure the pins
_ResetPins();
// init serial communication
Serial.begin(9600);
config_MP();
Serial.println("Ready to begin");
// start adafruit
if (!lsm.begin()) // Try to initialise and warn if we couldn't detect
{
Serial.println("Oops...unable to initialise the LSM303. Check wiring");
while (1);
}
//end adafruit
}
void_lowlevel_ReadEncoder(int &rotate,int& press)
{
rotate = (digitalRead(dpInEncoderB) * 2) +digitalRead(dpInEncoderA);
press =digitalRead(dpInEncoderPress);
}
void loop()
{
ReadEncoder();
}
void ReadEncoder()
{
int Position, Press;
int isFwd = 0;
int depth = 0;
_ResetPins();
Serial.println("Reading the encoder... rotate the knob by one click");
_lowlevel_ReadEncoder(Position, Press);
while (!Serial.available())
{
int Position2, Press2;
do
{
_lowlevel_ReadEncoder(Position2, Press2);
}while ((Position2 == Position) && (Press2 == Press));
if (Position2 != Position)
{
// "Forward" is shown by the position going from (0 to 1) or (1 to 3)
// or (3 to 2) or (2 to 0). Anything else indicates that the user is
// turning the device the other way.
int isFwd = ((Position == 0) && (Position2 == 1)) ||
((Position == 1) && (Position2 == 3)) ||
((Position == 3) && (Position2 == 2)) ||
((Position == 2) && (Position2 == 0));
depth = depth + (isFwd ? 10 : -10); //this yields four depth measurements
lsm.read(); // reads the magnetometer
val =sq(lsm.magData.x);
val = val +sq(lsm.magData.y);
val = val +sq(lsm.magData.z);
val =sqrt(val); // calculate total magnetic field
float Pi = 3.14159;
// Calculate the angle of the vector y,x
float heading = (atan2(lsm.magData.z,lsm.magData.x) * 180) / Pi;
// Normalise to 0-360
if (heading < 0)
{
heading = 360 + heading;
}
Serial.print(depth/4);
Serial.print(",");
//Serial.print((int)lsm.magData.x);
//Serial.print(".");
Serial.print((int)lsm.magData.y);
Serial.print(".");
//Serial.print((int)lsm.magData.z);
//Serial.print(".");
Serial.print(depth/4);
Serial.print(".");
Serial.print(val);
Serial.print(".");
Serial.print(depth/4);
Serial.print(".");
Serial.println((int)lsm.accelData.z);
Serial.print("Compass Heading: ");
Serial.println(heading);
}
if (Press2 != Press)
{
Serial.println(Press ? "Press" :"Release");
}
Position = Position2;
Press = Press2;
}
}