Hey there
So i downloaded this custom library (http://playground.arduino.cc/Main/SharpIR) that is suppose to take X amount of readings from my sharp sensor and then average them out to get a more accurate distance. I tried testing it out using a simple two motor car code however i kept getting this error “expected initializer before sharp”. However if you look at the code I DO have an initializer (its just custom) as the SharpIR.
Is there a reason why the code will not compile? Is it because it is custom and maybe it can not ready the SharpIR initializer part?
Thanks for any help!
EDIT:
I did some tweaking and for some reason it will compile if i change the first bit to this:
SharpIR sharp(A2, 25, 93, 1080);
void setup() {
SharpIR sharp(A2, 25, 93, 1080);
Serial.begin(9600);
Serial.println(“Autonomous RC Car”);
pinMode(BRAKE_A, OUTPUT);
pinMode(BRAKE_B, OUTPUT);
pinMode(DIR_A, OUTPUT);
pinMode(DIR_B, OUTPUT);
I have no idea why repeating it twice helps.
#include <SharpIR.h>
const int
PWM_A = 3,
PWM_B = 11,
DIR_A = 12,
DIR_B = 13,
BRAKE_A = 9,
BRAKE_B = 8,
SNS_A = A0,
SNS_B = A1,
[b]SharpIR sharp(A2, 25, 93, 1080);[/b]
void setup() {
Serial.begin(9600);
Serial.println("Autonomous RC Car");
pinMode(BRAKE_A, OUTPUT);
pinMode(BRAKE_B, OUTPUT);
pinMode(DIR_A, OUTPUT);
pinMode(DIR_B, OUTPUT);
}
void loop() {
int dis = sharp.distance();
if(dis > 10) { // If distance is greater than 10 cm do the following
Serial.print("Path is clear OK to go");
digitalWrite(BRAKE_A, LOW);
digitalWrite(BRAKE_B, LOW);
digitalWrite(DIR_A, HIGH); // motor 1 forward
digitalWrite(DIR_B, HIGH); // motor 2 forward
analogWrite(PWM_A, 200); // motor 1 speed 200
analogWrite(PWM_B, 200); // mtoor 2 speed 200
delay(3000); // go for 3 seconds
digitalWrite(BRAKE_A, HIGH); // motor 1 brake
digitalWrite(BRAKE_B, HIGH); // motor 2 brake
}
else {
Serial.print("Path is not clear reversing");
digitalWrite(BRAKE_A, LOW);
digitalWrite(BRAKE_B, LOW);
digitalWrite(DIR_A, LOW); // motor 1 reverse
digitalWrite(DIR_B, LOW); // motor 2 reverse
analogWrite(PWM_A, 200); // motor 1 speed 200
analogWrite(PWM_B, 200); // mtoor 2 speed 200
delay(3000); // go for 3 seconds
digitalWrite(BRAKE_A, HIGH); // motor 1 brake
digitalWrite(BRAKE_B, HIGH); // motor 2 brake
delay(1000); // wait a second
digitalWrite(BRAKE_A, LOW);
digitalWrite(BRAKE_B, LOW);
digitalWrite(DIR_A, LOW); // motor 1 reverse
digitalWrite(DIR_B, HIGH); // motor 1 forward
analogWrite(PWM_A, 200); // motor 1 speed 200
analogWrite(PWM_B, 200); // motor 2 speed 200
delay(1600); // I am going to tweak this number to get as close to a 90 degree turn as possible
digitalWrite(BRAKE_A, HIGH); // motor 1 brake
digitalWrite(BRAKE_B, HIGH); // motor 2 brake
}
}