本教程是的一部分: Elegoo智能汽车套件教程
本文下方有其他视频的链接。
Elegoo Robot Car Video #3: How to move forward, reverse and turn left and right
264-Elegoo Smart Car Code: Left wheel rotation of the car
语言: C++
// Provided by Robojax.com on Nov 25, 2019
// See video instructions for this video: https://youtu.be/JDgOYKo_zQ8
// www.elegoo.com
// Left motor truth table
// Here are some handy tables to show the various modes of operation.
// ENA IN1 IN2 Description
// LOW Not Applicable Not Applicable Motor is off
// HIGH LOW LOW Motor is stopped (brakes)
// HIGH HIGH LOW Motor is on and turning forwards
// HIGH LOW HIGH Motor is on and turning backwards
// HIGH HIGH HIGH Motor is stopped (brakes)
// define IO pin
#define ENA 5
#define IN1 7
#define IN2 8
// Initialize the car
void setup() {
pinMode(IN1, OUTPUT); // Set IO pin mode OUTPUT
pinMode(IN2, OUTPUT);
pinMode(ENA, OUTPUT);
digitalWrite(ENA, HIGH);// Enable left motor
}
// Main loop
void loop() {
digitalWrite(IN1, HIGH);
digitalWrite(IN2, LOW); // Right wheel turning forwards
delay(500); // Delay 500ms
digitalWrite(IN1, LOW);
digitalWrite(IN2, LOW); // Right wheel stopped
delay(500);
digitalWrite(IN1, LOW);
digitalWrite(IN2, HIGH);// Right wheel turning backwards
delay(500);
digitalWrite(IN1, HIGH);
digitalWrite(IN2, HIGH); // Right wheel stopped
delay(500);
}
资源与参考
尚无可用资源。
文件📁
没有可用的文件。