💻 Arduino 代码实时预览
#include <Servo.h>
int motorSpeed = 50;
int avoidDistance = 50;
float turnSensitivity = 5.0;
bool autoAvoid = true;
void setup() {
Serial.begin(9600);
}
void loop() {
if (autoAvoid && getDistance() < avoidDistance) {
turnRight(turnSensitivity);
} else {
moveForward(motorSpeed);
}
}