Make your robot walk around a square pattern.
// Square Pattern // 6/6/19 // Arduino 1.8.5 // Set up pins const int OnBoardLED = 13; int Dlay = 500; void setup() { pinMode(9,OUTPUT); // set the pin modes to output pinMode(10, OUTPUT); pinMode(11,OUTPUT); pinMode(12,OUTPUT); pinMode(OnBoardLED,OUTPUT); } void loop() { blinky(); // blink the light forward(1000); // move forward stopBot(1000); // briefly pause turnRight(1); // turn at a right angle } void blinky() { digitalWrite(OnBoardLED, LOW); // flash on board LED delay(Dlay); digitalWrite(OnBoardLED, HIGH); delay(Dlay); } void forward(int amt) { digitalWrite(9,HIGH); // make left motor move forward digitalWrite(10,LOW); digitalWrite(11,HIGH); // make right motor move forward digitalWrite(12,LOW); delay(amt); } void stopBot(int pause) { digitalWrite(9,LOW); // stop both motors digitalWrite(10,LOW); digitalWrite(11,LOW); digitalWrite(12,LOW); } void turnRight(double dlay) { digitalWrite(9,HIGH); // make the left motor move forward digitalWrite(10,LOW); digitalWrite(11,LOW); // stop the right motor digitalWrite(12,LOW); delay(dlay); }