Due friday for school

need help. Its a line tracker from a tank using black to turn the servo wheel at the front. I stole this entire code and tried to merge it but my knowledge is basic if you could call it that. Can someone help. I'm using a uno and a shield.

#define servoPin 10

#define L_pin 6

#define M_pin 7

#define R_pin 8

#define procedure

int L_val;

int M_val;

int R_val;

int pos;

int pulsewidth;

int myangle;

void setup(){

  pinMode(servoPin, OUTPUT);

  procedure(0);

  Serial.begin(9600);

  pinMode(L_pin, INPUT);

  pinMode(M_pin, INPUT);

  pinMode(R_pin, INPUT);

}

void loop(){

  for (pos = 0; pos <=180; pos += 1){

  procedure(pos);

  delay(15);

  L_val = digitalRead(L_pin);

  M_val = digitalRead(M_pin);

  R_val = digitalRead(R_pin);

  Serial.print(L_val);

  Serial.print("");

   Serial.print(M_val);

  Serial.print("");

  Serial.print(R_val);

  Serial.print("");

delay(100);

}
{
if (L_val = 1);

for(pos = 45;pos>=0; pos -= 1){

  procedure(pos);

  delay (15);

}
if (M_val = 1);

for(pos = 45;pos>=0; pos -= 1){

  procedure(pos);

  delay (15);
}

}
if (R_val = 1);

for(pos = 45;pos>=0; pos -= 1){

  procedure(pos);

  delay (15);
}
}
void procedure(int myangle);
{

  pulsewidth = myangle * 11 + 500;

  digitalWrite(servoPin, HIGH);

  delayMicroseconds(pulsewidth);

  digitalWrite(servoPin, LOW);

  delay((20 - pulsewidth / 1000));

}

}

Yes... I can. Your function is written incorrectly. You have three stray close braces. You have a type typeo. You have a needless #define.

Read your homework and listen to your instructor. Using someone else's code is standard practice in software (so says a college prof friend of mine), but if you steal code, you should at least have some knowledge of it, and learn why it works, to make it do what you need.

  • One line of code, 2 errors :roll_eyes:

if (M_val = 1);

  • Also here:

if (L_val = 1);

What do I need to do to fix it?

It's Monday, so you have plenty of time to study and practice basic programming skills.

Please read How to get the best out of this forum (again).

Please edit your post, select all code and click the <CODE/> button; next save the post.

This will apply code tags to the code which makes it easier to read and copy and the forum software will display it correctly.

Next time, please post the full error message, also using code tags.


void procedure(int myangle);
Declares a function prototype, it's not the beginning of a function definition.

if (L_val = 1);

  1. = for assigments, == for compare
  2. The semi-colon ends the if; anything after that is exeuted unconditionally.

#define procedure
What is this?

I suggest that you learn a little bit of the basics of C/C++.

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.