/* Robot 1 : Documentation This is the first program for running the simple robot. We just want to make sure the motors spin the right way and the robot moves forward.
Note the use of the ena, enb. In the old version of l298, there were 6 inputs. ena and enb are set to HIGH. these can be set by hardware and hence are commented out.
Depending on your driver, you can compile these commands or not. Use find and replace to remove the comment out directive if you wish. */
// int ena = 4; int int1 = 5; int int2 = 6;
// int enb = 8; int int3 =9; int int4 = 10;
int timex = 3000; //runs for 3 seconds boolean run;
void setup() { //pinMode (ena,OUTPUT); pinMode (int1,OUTPUT); pinMode (int2,OUTPUT);
//pinMode (enb,OUTPUT); pinMode (int3,OUTPUT); pinMode (int4,OUTPUT);
run = true; }
void loop() { if (run) { forward(); // sets the robot forward. // check motors are spinning in same direction delay(timex); halt(); // stops the code running run = false; } }
void forward() // forward sub procedure { //digitalWrite(ena,HIGH); digitalWrite(int1,HIGH); digitalWrite(int2,LOW);
//digitalWrite(enb, HIGH); digitalWrite(int3,HIGH); digitalWrite(int4,LOW);
}
void halt() // halt sub procedure { //digitalWrite(ena,HIGH); digitalWrite(int1,LOW); digitalWrite(int2,LOW);
//digitalWrite(enb,HIGH); digitalWrite(int3,LOW); digitalWrite(int4,LOW);
}
|