Hey
i successfully uploaded your library and i am really excited to use it however every time i try to compile this code i get an error before sharp saying "expected initialer before sharp".... but the SharpIR is orange and is the initializer, why is it missing this?
also i am relatively new to all this. I would really appreciate if you checked the rest of the short code to see if it will do what i want.
thank you!
#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,
SharpIR sharp(A2, 25, 93, 1080);
void setup() {
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
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 {
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
}
}