Skip to content

Instantly share code, notes, and snippets.

@liz-miller
Created May 6, 2018 23:32
Show Gist options
  • Save liz-miller/22f768ce943b01479ce24ece0ce83366 to your computer and use it in GitHub Desktop.
Save liz-miller/22f768ce943b01479ce24ece0ce83366 to your computer and use it in GitHub Desktop.
Move Method | Beginner Bots Tutorial Lesson #3
/*
* Move Method - READY TO TEST
* Controls how our robot moves.
* Developed for the Beginner Bots lesson series on www.learnrobotics.org/blog
* Written by Liz Miller
* 5/6/2018
*/
/** Global Variables **/
//Left Motor
 int enableA = 10;
 int motorA1 = 9;
 int motorA2 = 8;
//Right Motor
 int enableB = 5;
 int motorB3 = 7;
 int motorB4 = 6;
//move two motors for a set duration and speed
void move(int motor1, int motor2, int enable, int speed, int duration){
// code goes here
   // 1. turn on motor
   digitalWrite(motor1, HIGH);  
   digitalWrite(motor2, LOW);  
   // 2. set speed (to 200 out of possible range 0~255)
   analogWrite(enable, speed);
   
   // 3. run for specified time
   delay(duration);   
}
// -- WRITE the stop() method --
void stop(int motor1, int motor2, int enable, int speed, int duration){
// WRITE THIS CODE... Hint there are many ways to do this!
}
// -- NEW CODE STARTS HERE --
/** loop method - required method **/
void loop(){    
   // move motor A at speed of 200 for 5 seconds    
   move(motorA1, motorA2, enableA, 200, 5000);   
 
   // move motor B at speed of 200 for 5 seconds    
   move(motorB3, motorB4, enableB, 200, 5000); 
   
   // stop motor A for 5 seconds    
   stop(motorA1, motorA2, enableA, 5000);  
     
   // stop motor B for 5 seconds    
   stop(motorB3, motorB4, enableB, 5000); 
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment