извините) int IN3 = 5; // Input3 подключен к выводу 5 int IN4 = 4; int IN2 = 6; int IN1 = 7; int IN1a = 2; int IN2a = 3; int IN3a = 8; int IN4a = 9; int ENB = 11; int ENBa = 13; int ENA = 10; int ENAa = 12; boolean buttonPin = 1; boolean lastButton = LOW; boolean currentButton = LOW; int i; #include <Servo.h> Servo myservo; void setup() { pinMode(ENA, OUTPUT); pinMode(ENB, OUTPUT); pinMode (buttonPin,INPUT); pinMode (IN4, OUTPUT); pinMode (IN3, OUTPUT); pinMode (IN2, OUTPUT); pinMode (IN1, OUTPUT); pinMode (IN1a,OUTPUT); pinMode (IN2a,OUTPUT); pinMode (IN3a,OUTPUT); pinMode (IN4a,OUTPUT); myservo.attach(0); } boolean debounce(boolean last) { boolean current = digitalRead(buttonPin); if (last != current) { delay (100); current = digitalRead(buttonPin); } return current; } void loop () { currentButton = debounce(lastButton); if (currentButton == HIGH && lastButton == LOW) { digitalWrite (IN1, HIGH); digitalWrite (IN2, LOW); digitalWrite (IN3,LOW); digitalWrite (IN4,HIGH); digitalWrite (IN1a,HIGH); digitalWrite (IN2a,LOW); digitalWrite (IN3a,HIGH); digitalWrite (IN4a,LOW); for (i=50; i<=150; ++i) { analogWrite(ENA,i); analogWrite(ENB,i); analogWrite(ENAa,i); analogWrite (ENBa,i); delay(1); } delay(1270); analogWrite(ENAa,0); analogWrite(ENBa,0); analogWrite(ENA,0); analogWrite(ENB,0); digitalWrite (IN3, LOW); digitalWrite (IN1, LOW); digitalWrite (IN1a,LOW); digitalWrite (IN3a,LOW); delay(2000); myservo.write(180); delay(700); myservo.write(90); delay(5000); myservo.write(0); delay(850); myservo.write(90); digitalWrite (IN4, LOW);//обратно digitalWrite (IN3,LOW); digitalWrite (IN1,LOW); digitalWrite (IN2,LOW); digitalWrite (IN1a,LOW); digitalWrite (IN2a,LOW); digitalWrite (IN3a,LOW); digitalWrite (IN4a,LOW); for (i=50; i<=150; ++i) { analogWrite(ENA,i); analogWrite(ENB,i); analogWrite(ENAa,i); analogWrite (ENBa,i); delay(1); } delay(2000); digitalWrite (IN4, LOW);//обратно digitalWrite (IN3,LOW); digitalWrite (IN1,LOW); digitalWrite (IN2,LOW); digitalWrite (IN1a,HIGH); digitalWrite (IN2a,LOW); digitalWrite (IN3a,LOW); digitalWrite (IN4a,HIGH); for (i=50; i<=150; ++i) { analogWrite(ENA,i); analogWrite(ENB,i); analogWrite(ENAa,i); analogWrite (ENBa,i); delay(1); } delay(2178); digitalWrite (IN4, LOW);//обратно digitalWrite (IN3,LOW); digitalWrite (IN1,LOW); digitalWrite (IN2,LOW); digitalWrite (IN1a,LOW); digitalWrite (IN2a,LOW); digitalWrite (IN3a,LOW); digitalWrite (IN4a,LOW); for (i=50; i<=150; ++i) { analogWrite(ENA,i); analogWrite(ENB,i); analogWrite(ENAa,i); analogWrite (ENBa,i); delay(1); } delay(2000); digitalWrite (IN1, HIGH); digitalWrite (IN2, LOW); digitalWrite (IN3,HIGH); digitalWrite (IN4,LOW); digitalWrite (IN1a,HIGH); digitalWrite (IN2a,LOW); digitalWrite (IN3a,HIGH); digitalWrite (IN4a,LOW); for (i=50; i<=150; ++i) { analogWrite(ENA,i); analogWrite(ENB,i); analogWrite(ENAa,i); analogWrite (ENBa,i); } delay(1270); digitalWrite (IN4, LOW);//обратно digitalWrite (IN3,LOW); digitalWrite (IN1,LOW); digitalWrite (IN2,LOW); digitalWrite (IN1a,LOW); digitalWrite (IN2a,LOW); digitalWrite (IN3a,LOW); digitalWrite (IN4a,LOW); for (i=50; i<=150; ++i) { analogWrite(ENA,i); analogWrite(ENB,i); analogWrite(ENAa,i); analogWrite (ENBa,i); delay(1); myservo.write(0); myservo.write(180); delay(700); myservo.write(90); delay(5000); myservo.write(0); delay(850); myservo.write(90); myservo.write(90); } } }
1.Некоторое время крутятся колеса. 2.Срабатывает захват. 3.Разворот. 4.Едет в другую сторону. 5.Срабатывает захват
analogWrite(ENA,i); analogWrite(ENB,i); analogWrite(ENAa,i); analogWrite (ENBa,i); int ENB = 11; int ENBa = 13; int ENA = 10; int ENAa = 12; Должны быть на пинах, которые поддерживают ШИМ (для уно 3,5,6,9,10,11) Серву повесь на 9 пин.