Advertisement
birdmun

roboMove()

Jun 30th, 2014
475
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.96 KB | None | 0 0
  1. // Call roboMove() with +/- 100 for left and right motors to denote speed and direction
  2. // Also include a delay value to control run time of the motors
  3. // For the code here, leftMotorDir, rightMotorDir, leftMotorPWM, rightMotorPWM are global
  4. // pin definitions and maxSpeed is a global define
  5. void roboMove(int right, int left, long dlay) {
  6.   boolean rightDir, leftDir;
  7.   int rightPWM, leftPWM;
  8.   if (right > 0) {
  9.     rightDir = 1; //forward
  10.   }  else {
  11.     rightDir = 0; //reverse
  12.   }
  13.   if (right == 0) {
  14.     rightPWM = 0;
  15.   } else {
  16.     rightPWM = map(ABS(right), 1, 100, 1, maxSpeed);
  17.   }
  18.   if (left > 0) {
  19.     leftDir = 1; //forward
  20.   }  else {
  21.     leftDir = 0; //reverse
  22.   }
  23.   if (left == 0) {
  24.     leftPWM = 0;
  25.   } else {
  26.     leftPWM = map(ABS(left), 1, 100, 1, maxSpeed);
  27.   }
  28.   digitalWrite(rightMotorDir, rightDir);
  29.   digitalWrite(leftMotorDir, leftDir);
  30.   analogWrite(rightMotorPWM, rightPWM);
  31.   analogWrite(leftMotorPWM, leftPWM);
  32.   delay(dlay);
  33. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement