9857| 5
|
[求助] Arduino goto语句求解 |
最近编了一个小车的程序 利用碰撞传感器实现避障 但是小车后退转弯了以后就不能向前走了 只能不停的转圈圈 所以我想在最后的if语句上加上goto语句但是不知道怎么用 求大神帮忙让小车能再动起来!!! 程序如下: #include <IRremote.h> int RECV_PIN = 10; int potpin = 0; IRrecv irrecv(RECV_PIN); decode_results results; void setRomeoMotor(int motorId, int speed) { int speedPin, directionPin; if (motorId == 1) { speedPin = 5; directionPin = 4; } else { if (motorId == 2) { speedPin = 6; directionPin = 7; } else { return; } } if (speed == 0) { digitalWrite(speedPin, LOW); } if (speed > 0) { digitalWrite(directionPin, HIGH); analogWrite(speedPin, speed); } else { digitalWrite(directionPin, LOW); analogWrite(speedPin, -speed); } } void setup() { Serial.begin(9600); irrecv.enableIRIn(); pinMode( 11, INPUT); pinMode( 12, INPUT); pinMode( 4, OUTPUT); pinMode( 5, OUTPUT); pinMode( 6, OUTPUT); pinMode( 7, OUTPUT); digitalWrite(4, LOW); digitalWrite(5, LOW); digitalWrite(6, LOW); digitalWrite(7, LOW); } void loop() { int sensorValue = analogRead(potpin); int outputValue = map(sensorValue, 0, 1023, 50, 150); if (irrecv.decode(&results)) { Serial.println(results.value, HEX); irrecv.resume(); if (results.value == 0xFD00FF) { setRomeoMotor(1, -outputValue); setRomeoMotor(2, -outputValue); } if (results.value == 0xFD40BF) { setRomeoMotor(1, 0); setRomeoMotor(2, 0); } } if (!( digitalRead(11) )) { setRomeoMotor(1, 50); setRomeoMotor(2, 50); delay( 1000 ); setRomeoMotor(1, -30); setRomeoMotor(2, -100); delay( 400 ); } if (!( digitalRead(12) )) { setRomeoMotor(1, 50); setRomeoMotor(2, 50); delay( 1000 ); setRomeoMotor(1, -100); setRomeoMotor(2, -30); delay( 400 ); } } |
© 2013-2025 Comsenz Inc. Powered by Discuz! X3.4 Licensed