3, Module test.copying the following code to the IDE compiler environment (you can also open the
program directly in the CD), downloading it to the development board, opening the serial port monitor (baud
rate is 9600) and observing the changes of data when there is a obstacle (Figure 3.2.11) and no obstacle (Figure
3.2.12).
Note: Here we connect the infrared obstacle avoidance signal output port to the analog port on Arduino
(A0-A5), so the serial port prints out analog value, you can connect it to digital port (2-13), and the serial port
will only print out "0" and "1".
const int
leftPin
const int
rightPin
int
dl;
int
dr;
void
setup()
{
Serial.begin(9600);
pinMode(leftPin, INPUT);
pinMode(rightPin, INPUT);
delay(1000);
}
void
loop()
{
dl
= analogRead(leftPin);
dr
= analogRead(rightPin);
Serial.print("left:");
Serial.print(dl);
Serial.print("
Serial.print("right:");
Serial.println(dr);
}
= A3;
= A4;
");
52
Need help?
Do you have a question about the Hummer-Bot and is the answer not in the manual?