hi
can me problem/error in code. error message says:
test.ino: in function 'void loop()':
test:60: error: expected '(' before 'scan'
expected '(' before 'scan'
thank you
michael (148dino)
can me problem/error in code. error message says:
test.ino: in function 'void loop()':
test:60: error: expected '(' before 'scan'
expected '(' before 'scan'
thank you
michael (148dino)
code: [select]
#include <newping.h>
#define motorh1 2
#define motorh2 3
#define motorv1 4
#define motorv2 5
#define triggerpin 6
#define echopin 7
#define maxdistance 100
newping sonar(triggerpin, echopin, maxdistance);
int distance;
int triggerdistance = 30;
int fdistance;
int vdistance;
int hdistance;
unsigned int time;
void setup() {
serial.begin(9600);
pinmode(triggerpin, output);
pinmode(echopin, input);
pinmode(motorh1, output);
pinmode(motorh2, output);
pinmode(motorv1, output);
pinmode(motorv2, output);
serial.println("det virker!");
}
void loop() {
if (serial.available() > 0)
{
int data = serial.read();
switch(data)
{
case 'w' :
frem();
break;
case 's' :
tilbage();
break;
case 'a' :
venstre();
break;
case 'd' :
hojre();
break;
case 'e' :
stands();
break;
case 'q' :
dans();
default :
break;
}
}
else if
scan(); //the program says error lays here.
fdistance = distance;
if (fdistance < triggerdistance)
{
tilbage();
delay(1000);
hojre();
delay(500);
stands();
scan();
hdistance = distance;
venstre();
delay(1000);
stands();
scan();
vdistance = distance;
if (vdistance < hdistance)
{
hojre();
delay(200);
frem();
}
else {
frem();
}
}
else {
frem();
}
}
void frem()
{
serial.println("kører fre,");
digitalwrite(motorh1, high);
digitalwrite(motorh2, low);
digitalwrite(motorv1, high);
digitalwrite(motorv2, low);
}
void tilbage()
{
serial.println("kørere tilbage");
digitalwrite(motorh1, low);
digitalwrite(motorh2, high);
digitalwrite(motorv1, low);
digitalwrite(motorv2, high);
}
void venstre()
{
serial.println("kører venstre");
digitalwrite(motorh1, low);
digitalwrite(motorh2, high);
digitalwrite(motorv1, high);
digitalwrite(motorv2, low);
}
void hojre()
{
serial.println("kører venstre");
digitalwrite(motorh1, high);
digitalwrite(motorh2, low);
digitalwrite(motorv1, low);
digitalwrite(motorv2, high);
}
void stands()
{
serial.println("standser");
digitalwrite(motorh1, low);
digitalwrite(motorh2, low);
digitalwrite(motorv1, low);
digitalwrite(motorv2, low);
}
void scan(){
time = sonar.ping();
distance = time / us_roundtrip_cm;
if (distance == 0)
{
distance = 100;
}
serial.print(distance);
serial.println("cm");
delay(10);
}
void dans()
{
serial.println("danser");
digitalwrite(motorh1, high);
digitalwrite(motorh2, low);
digitalwrite(motorv1, low);
digitalwrite(motorv2, high);
delay(1000);
digitalwrite(motorh1, low);
digitalwrite(motorh2, high);
digitalwrite(motorv1, high);
digitalwrite(motorv2, low);
delay(1000);
digitalwrite(motorh1, high);
digitalwrite(motorh2, low);
digitalwrite(motorv1, high);
digitalwrite(motorv2, low);
delay(500);
digitalwrite(motorh1, low);
digitalwrite(motorh2, high);
digitalwrite(motorv1, low);
digitalwrite(motorv2, high);
delay(500);
digitalwrite(motorh1, low);
digitalwrite(motorh2, low);
digitalwrite(motorv1, low);
digitalwrite(motorv2, low);
delay(100);
}
code: [select]
else if // <---- lookup if syntax/usage
scan(); //the compiler detected error here.
Arduino Forum > Using Arduino > Programming Questions > expected '(' before 'scan'
arduino
Comments
Post a Comment