//************************************************************************** // SakuraMotor.cpp = run the Digilent Robot in a square several times // by James Conrad, Nov. 13, 2012 // for ENGR1202 //************************************************************************** #include #define directionA 0 //Port 0 - motor A direction #define enableA 1 //Port 1 - motor A on/off #define directionB 2 //Port 2 - motor B direction #define enableB 3 //Port 3 - motor B on/off #define Aforward 1 #define Abackward 0 #define Bforward 0 #define Bbackward 1 #define PAUSE 5 //Pulse width modulation - not full on #define FORWARDLOOP 200 //Timing of how many times to //loop to go forward #define TURNLOOP 60 //Timing of how many times to //loop to turn #define ON 1 #define OFF 0 int i, j; //counter variables //************************************************************************** // setup input/output pins // //************************************************************************** void setup(){ pinMode(directionA,OUTPUT); pinMode(enableA,OUTPUT); pinMode(directionB,OUTPUT); pinMode(enableB,OUTPUT); pinMode(PIN_SW,INPUT); } //************************************************************************** // main loop - run the motors // // //************************************************************************** void loop() { //Start with getting ready to move forward, but disables digitalWrite(enableA, OFF); digitalWrite(enableB, OFF); digitalWrite(directionA, Aforward); digitalWrite(directionB, Bforward); // spin waiting until the button is pressed while (digitalRead(PIN_SW) == HIGH); // do a square 5 times, which means 20 straights and 20 turns for (i=0; i<20; i++) { // Start by moving forward // then turn counter clockwise } //end loop i=0 to 19 - do square 5 times } //end loop()