Go Down

Topic: I need your help in checking my code.Urgent please. (Read 555 times) previous topic - next topic

wvmarle

Quote
Code: [Select]
  duration1 = pulseIn(echoPin, HIGH);
Add a timeout to pulseIn, a few milliseconds is probably enough - just see how long it takes for the round trip of a soundwave at a bit more than the maximum distance you will ever have to measure. That'll make your robot much more responsive, instead of waiting for 1 second(!) before the function times out if there's no echo coming back to the sensor.
Quality of answers is related to the quality of questions. Good questions will get good answers. Useless answers are a sign of a poor question.

Johan_Ha

@TomGeorge, I'm using my phone or tablet for reading this forum. The question is, why should I have to download anything, when anything of interest could be viewed in a browser window.
____________________

If you ask for help and write 'u' instead of 'you' because you think it's convenient, I will write 'no' instead of 'yes'. For same reasons.

TomGeorge

@TomGeorge, I'm using my phone or tablet for reading this forum. The question is, why should I have to download anything, when anything of interest could be viewed in a browser window.
Hi, fair enough, but there are so many different platforms out these days, who knows what the forum is being viewed on.
I use a Laptop, don't use a portable entertainment center, I have a galaxy IV pad, hardly use it except when V8 and F1 is on the TV.
As for the code, why isn't the NewPing library being used to take care of the UltraSonics?
Tom... :)
Everything runs on smoke, let the smoke out, it stops running....

Antony289

Code: [Select]
servo1.attach(3);
 ...
  pinMode(3, OUTPUT);
 ...
    analogWrite(3, shim1);
I see that as being a problem.
Yes, for sure, I forgot to change the pin)

Antony289

Code: [Select]
void RIGHT()
{
  analogWrite(3, HIGH);
  delay(260);
  analogWrite(3, LOW);
}

void LEFT()
{
  digitalWrite(11, HIGH);
  delay(220);
  digitalWrite(11, LOW);
}

analogWrite (3, HIGH) is a very, very low duty cycle.

Look at the differences between LEFT and RIGHT
Delay? I specifically picked up a certain time for my robot to turn to the right / left and the delays between these sides are different, because these are different motors (this already depends on the quality of the electric motor) and they have different PWMs, so the time for turning is different  (I tried to make a turn about 90 degrees). All the same thanks for the answer)

Antony289

[quote/]
 I'm guessing Russian.
The forum has a Russian section
[/quote]

Is there a Russian section? Hmm ... but I can not find it, can not you help me?

Antony289

Code: [Select]
 digitalWrite(trigPin, LOW);
  delayMicroseconds(2);
  digitalWrite(trigPin, HIGH);
  delayMicroseconds(10);
  digitalWrite(trigPin, LOW);
  duration1 = pulseIn(echoPin, HIGH);

This is crazy.
If you had initialised trigPin to LOW in setup(), then this code would simply be
Code: [Select]

  digitalWrite(trigPin, HIGH);
  delayMicroseconds(10);
  digitalWrite(trigPin, LOW);
  duration1 = pulseIn(echoPin, HIGH);


This repeated sequence should also be in a function, returning a range in centimetres.
Thank you very much, that's really good advice!

TolpuddleSartre

"I've gone off the idea of progress. It's overrated."
Arthur Dent

wvmarle

Yes, for sure, I forgot to change the pin)
Now you know why you should use variables with descriptive names for the pins, instead of the pin numbers themselves.
Quality of answers is related to the quality of questions. Good questions will get good answers. Useless answers are a sign of a poor question.

Antony289

Lack of time is not any of our concern.

You should have planned according.


.
"Lack of time" and "Strong loading" does not depend on me, and this should not bother you.

TolpuddleSartre

"Lack of time" and "Strong loading" does not depend on me, and this should not bother you.
OK. I'll wish you "good luck" then, and leave you to it.
"I've gone off the idea of progress. It's overrated."
Arthur Dent

Antony289

Now you know why you should use variables with descriptive names for the pins, instead of the pin numbers themselves.
Yes, I agree with you.

Antony289

Code: [Select]
  if ((duration1 + duration2 + duration3) <= 36)
My Russian isn't what it was, but I'm guessing that that line should read
Code: [Select]
  if ((left + line + right) <= 36)

Yes, you are right, but here I was faced with a small problem, the fact is that I needed to add lengths to the sides that measured the ultrasonic sensor, but I did not know how to write this side so that the program realized that it was the "Length of the measured side"  can you tell me how to do this?

Antony289

Add a timeout to pulseIn, a few milliseconds is probably enough - just see how long it takes for the round trip of a soundwave at a bit more than the maximum distance you will ever have to measure. That'll make your robot much more responsive, instead of waiting for 1 second(!) before the function times out if there's no echo coming back to the sensor.
Good idea, but please specify I just need to add a "delay"?

larryd

pulseIn(pin, value, timeout)
timeout (optional): the number of microseconds to wait for the pulse to start; default is one second (unsigned long)



No technical PMs.
The last thing you did is where you should start looking.

Go Up