Hello
I'm new with programming and with dwenguino.
I have a problem with programming my dwenguino v2.0 in Arduino.It is supposed to be a car with two dcmotors in the back and 2 sensors in the front.
I'm trying to get te car to follow a black line.
the detection of a black line is above 300.
I have a "zero part" and a "one part".
for sensor 1 and 2
If we place part one beneath part zero only part one works . and if we place it the other way around only the zero part works.
//zero part
if (nul > white_min) {
dcMotor1.setSpeed(100);
dcMotor2.setSpeed(0);
} else {
dcMotor1.setSpeed(100);
dcMotor2.setSpeed(100);
}
//one part
if (een > white_min) {
dcMotor1.setSpeed(0);
dcMotor2.setSpeed(100);
} else {
dcMotor1.setSpeed(100);
dcMotor2.setSpeed(100);
}
Thanks in advance
volg_zwarte_lijn.ino (1012 Bytes)
Both parts of your code set the state of the two motors so whichever part is last in loop() will execute if the conditions are true but the motors will be affected only by the last code executed.
What does the LCD show the values of een and nul to be ?
It is a car.
UKHeliBob:
Both parts of your code set the state of the two motors so whichever part is last in loop() will execute if the conditions are true but the motors will be affected only by the last code executed.
What does the LCD show the values of een and nul to be ?
The LCD shows the value. I'm using a white board with a black line.
if the sensors are above the white board the values are somewhere below 100. The black line values somewhere above 300. And both the sensor display there value on the LCD screen.
I understand what you mean with the loop thing. But I don't know how to code that propperly.
I understand what you mean with the loop thing. But I don't know how to code that propperly.
Are nul and ein ever both greater than white_min at the same time ? They should be most of the time.
What you probably should be doing is something like this
if the left sensor is over a black area
turn left
else if the right sensor is over a black area
turn right
else
run both motors forward
end if