Hi,
I've been trying to execute, the below mentioned program for some reason I'm getting the error:
- expected primary-expression before '=' token
- error: expected ';' before '}' token
3.Compilation error: expected primary-expression before '=' token
and the code is
/*
*/
#define rotA 6
#define rotB 7
#define speed
//define variables for the rotary function
int speedLimit = 0;
int posA;
int posB;
const int led = 13;
const int buttonPin = 2;
const int buzzer = 3;
//Variables for the Ultra Sensor 1
const int trigPin1 = 4;
const int echoPin1 = 5;
float duration1, distance1;
//Variables for Ultra Sensor 2
const int trigPin2 = 9;
const int echoPin2 = 10;
float duration2, distance2;
//Variable for calculating Speed
unsigned long time1;
unsigned long time2;
int delT;
float opp1, opp2, opp3;
float adj1, adj2, adj3;
float hyp, deladj, addopp;
float speed;
void setup()
{
pinMode(rotA, INPUT);
pinMode(rotB, INPUT);
pinMode(trigPin1, OUTPUT);
pinMode(echoPin1, INPUT);
pinMode(buzzer, OUTPUT);
pinMode(led, OUTPUT);
pinMode(buttonPin, INPUT);
pinMode(led, OUTPUT);
pinMode(buzzer, OUTPUT);
Serial.begin(9600);
}
void loop()
{
posA = digitalRead(rotA);
if(rotA != posB)
{
noTone(buzzer);
if(digitalRead(rotB) != posA)
{
speedLimit = speedLimit + 5;
tone(buzzer,349);
delay(6);
noTone(buzzer);
}
else
{
speedLimit = speedLimit - 5;
tone(buzzer,330);
delay(6);
noTone(buzzer);
}
if(speedLimit < 0)
{
speedLimit = 0;
tone(buzzer,440);
delay(6);
noTone(buzzer);
}
else if(speedLimit > 120)
{
speedLimit = 120;
tone(buzzer,440);
delay(6);
noTone(buzzer);
}
noTone(buzzer);
Serial.print("Speed Limit: ");
Serial.println(speedLimit);
Serial.println("kmph");
}
posB = posA;
digitalWrite(trigPin1, LOW);
delayMicroseconds(2);
digitalWrite(trigPin1, HIGH);
delayMicroseconds(10);
digitalWrite(trigPin1, LOW);
duration1 = pulseIn(echoPin1, HIGH);
distance1 = (duration1*.0343)/2;
Serial.print("Distance: ");
Serial.println(distance1);
delay(100);
digitalWrite(trigPin2, LOW);
delayMicroseconds(2);
digitalWrite(trigPin2, HIGH);
delayMicroseconds(10);
digitalWrite(trigPin2, LOW);
duration2 = pulseIn(echoPin2, HIGH);
distance2 = (duration2*.0343)/2;
Serial.print("Distance: ");
Serial.println(distance2);
delay(100);
noTone(buzzer);
if(distance1 < 180)
{
tone(buzzer,261);
delay(300);
noTone(buzzer);
digitalWrite(led, HIGH); // turn the LED on (HIGH is the voltage level)
delay(300); // wait for a second
digitalWrite(led, LOW); // turn the LED off by making the voltage LOW
delay(300);
digitalWrite(led, HIGH); // turn the LED on (HIGH is the voltage level)
delay(300); // wait for a second
digitalWrite(led, LOW); // turn the LED off by making the voltage LOW
delay(300);
time1 = millis();
delay(1000); //we might have to remove this if the second sensor is not getting triggered
}
if(distance2 < 180)
{
tone(buzzer,392);
delay(300);
noTone(buzzer);
digitalWrite(led, HIGH); // turn the LED on (HIGH is the voltage level)
delay(300); // wait for a second
digitalWrite(led, LOW); // turn the LED off by making the voltage LOW
delay(300);
digitalWrite(led, HIGH); // turn the LED on (HIGH is the voltage level)
delay(300); // wait for a second
digitalWrite(led, LOW); // turn the LED off by making the voltage LOW
delay(300);
time2 = millis();
delay(1000);
}
if(time2 > time1)
{
delT = time2 - time1;
delT = delT*3600000; //converting it to seconds
opp1 = distance1/2; //opposite side, distance1, is hypoteneus
opp1 = sq(opp1);
distance1 = sq(distance1);
adj1 =sqrt(distance1-opp1);
distance1 = sqrt(distance1);
opp1 = sqrt(opp1);
opp2 = distance2/2; //opposite side, distance1, is hypoteneus
opp2 = sq(opp2);
distance2 = sq(distance2);
adj2 =sqrt(distance2-opp2);
distance2 = sqrt(distance2);
opp2 = sqrt(opp2);
if(adj1 > adj2)
{
adj3 = adj1-adj2;
opp3 = opp1+opp2;
adj3 = sq(adj3);
opp3 = sq(opp3);
hyp = sqrt(adj3+opp3);
}
else
{
adj3 = adj2-adj1;
opp3 = opp1+opp2;
adj3 = sq(adj3);
opp3 = sq(opp3);
hyp = sqrt(adj3+opp3);
}
speed = hyp / delT;
}
else
{
delT = time1 - time2;
delT = delT*3600000; //converting it to seconds
opp1 = distance1/2; //opposite side, distance1, is hypoteneus
opp1 = sq(opp1);
distance1 = sq(distance1);
adj1 =sqrt(distance1-opp1);
distance1 = sqrt(distance1);
opp1 = sqrt(opp1);
opp2 = distance2/2; //opposite side, distance1, is hypoteneus
opp2 = sq(opp2);
distance2 = sq(distance2);
adj2 =sqrt(distance2-opp2);
distance2 = sqrt(distance2);
opp2 = sqrt(opp2);
if(adj1>adj2)
{
adj3 = adj1-adj2;
opp3 = opp1+opp2;
adj3 = sq(adj3);
opp3 = sq(opp3);
hyp = sqrt(adj3+opp3);
}
else
{
adj3 = adj2-adj1;
opp3 = opp1+opp2;
adj3 = sq(adj3);
opp3 = sq(opp3);
hyp = sqrt(adj3+opp3);
}
}
speed = hyp/delT;
if(speed > speedLimit)
{
tone(buzzer,261);
delay(300);
tone(buzzer,392);
delay(300);
digitalWrite(led, HIGH); // turn the LED on (HIGH is the voltage level)
delay(300); // wait for a second
digitalWrite(led, LOW); // turn the LED off by making the voltage LOW
delay(300);
}
else
{
noTone(buzzer);
digitalWrite(led, LOW)
}
Serial.print("Speed Limit: ");
Serial.println(speedLimit);
Serial.print("Speed: ");
Serial.println(speed);
}
What is the problem with this code?
please help