Hi,
I have attached a Ping))) sensor (http://arduino.cc/en/Tutorial/Ping?from=Tutorial.UltrasoundSensor) and an Easy Driver (Easy Driver stepper motor driver) to my Arduino. I am trying to make a bipolar 12v stepper motor rotate once (200 steps) for every 10 cm that the Ping))) senses.
I keep getting the "error: expected unquealified-id before '{' token"
const int pingPin = 7;
long duration, inches, cm;
int steps;
void setup() {
Serial.begin(9600);
pinMode(8, OUTPUT);
pinMode(9, OUTPUT);
digitalWrite(8, LOW);
digitalWrite(9, LOW);
}
void loop()
{
pinMode(pingPin, OUTPUT);
digitalWrite(pingPin, LOW);
delayMicroseconds(2);
digitalWrite(pingPin, HIGH);
delayMicroseconds(5);
digitalWrite(pingPin, LOW);
pinMode(pingPin, INPUT);
duration = pulseIn(pingPin, HIGH);
inches = microsecondsToInches(duration);
cm = microsecondsToCentimeters(duration);
Serial.print(inches);
Serial.print("in, ");
Serial.print(cm);
Serial.print("cm");
Serial.println();
delay(100);
}
long microsecondsToInches(long microseconds)
{
return microseconds / 74 / 2;
}
long microsecondsToCentimeters(long microseconds)
{
return microseconds / 29 / 2;
}
{
if (steps < cm * 20) {
digitalWrite(8, LOW);
digitalWrite(9, HIGH);
delayMicroseconds(100);
digitalWrite(9, LOW);
delayMicroseconds(100);
steps = steps + 1;
}
if (steps > cm * 20) {
digitalWrite(8, HIGH);
digitalWrite(9, HIGH);
delayMicroseconds(100);
digitalWrite(9, LOW);
delayMicroseconds(100);
steps = steps - 1;
}
if (steps == cm * 20) {
digitalWrite(9, LOW);
delayMicroseconds(100);}
}
What am I doing wrong?
Thanks for any help.