Stap 13: Testen van de Robot
Test ik de Track Bot met behulp van de schets hieronder. Track Bot zal doen sommige eenvoudige bewegingen wordt voorwaarts verplaatst, draait links, naar het vorige, draait rechts, stop, vooruit, achteruit, en stop.
#define LEFT_EN 6 #define LEFT_A1 4 // Motor A1 #define LEFT_A2 5 // Motor A2 #define RIGHT_EN 9 #define RIGHT_A1 7 // Motor B1 #define RIGHT_A2 8 // Motor B2 void setup(){ pinMode(LEFT_EN, OUTPUT); pinMode(LEFT_A1, OUTPUT); pinMode(LEFT_A2, OUTPUT); pinMode(RIGHT_EN, OUTPUT); pinMode(RIGHT_A1, OUTPUT); pinMode(RIGHT_A2, OUTPUT); digitalWrite(LEFT_EN, LOW); digitalWrite(RIGHT_EN, LOW); } void Forward(){ //Go Forward digitalWrite(LEFT_EN, HIGH); digitalWrite(LEFT_A1, HIGH); digitalWrite(LEFT_A2,LOW); digitalWrite(RIGHT_EN,HIGH); digitalWrite(RIGHT_A1, HIGH); digitalWrite(RIGHT_A2, LOW); } void Left() { digitalWrite(LEFT_EN, HIGH); digitalWrite(LEFT_A1, HIGH); digitalWrite(LEFT_A2,LOW); digitalWrite(RIGHT_EN, HIGH); digitalWrite(RIGHT_A1, LOW); digitalWrite(RIGHT_A2, LOW); } void Right() { digitalWrite(LEFT_EN, HIGH); digitalWrite(LEFT_A1, LOW); digitalWrite(LEFT_A2, LOW); digitalWrite(RIGHT_EN, HIGH); digitalWrite(RIGHT_A1, HIGH); digitalWrite(RIGHT_A2, LOW); } //Go Backward void Backward(){ digitalWrite(LEFT_EN, HIGH); digitalWrite(LEFT_A1, LOW); digitalWrite(LEFT_A2, HIGH); digitalWrite(RIGHT_EN,HIGH); digitalWrite(RIGHT_A1, LOW); digitalWrite(RIGHT_A2, HIGH); } // Stop void Stop(){ digitalWrite(LEFT_EN, LOW); digitalWrite(LEFT_A1, LOW); digitalWrite(LEFT_A2, LOW); digitalWrite(RIGHT_EN, LOW); digitalWrite(RIGHT_A1, LOW); digitalWrite(RIGHT_A2, LOW); } void loop(){ Forward(); delay(3000); Left(); delay(4000); Backward(); delay(2000); Right(); delay(4000); Stop(); delay(1500); Forward(); delay(3000); Backward(); delay(2000); Stop(); delay(2000); }