Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // Call roboMove() with +/- 100 for left and right motors to denote speed and direction
- // Also include a delay value to control run time of the motors
- // For the code here, leftMotorDir, rightMotorDir, leftMotorPWM, rightMotorPWM are global
- // pin definitions and maxSpeed is a global define
- void roboMove(int right, int left, long dlay) {
- boolean rightDir, leftDir;
- int rightPWM, leftPWM;
- if (right > 0) {
- rightDir = 1; //forward
- } else {
- rightDir = 0; //reverse
- }
- if (right == 0) {
- rightPWM = 0;
- } else {
- rightPWM = map(ABS(right), 1, 100, 1, maxSpeed);
- }
- if (left > 0) {
- leftDir = 1; //forward
- } else {
- leftDir = 0; //reverse
- }
- if (left == 0) {
- leftPWM = 0;
- } else {
- leftPWM = map(ABS(left), 1, 100, 1, maxSpeed);
- }
- digitalWrite(rightMotorDir, rightDir);
- digitalWrite(leftMotorDir, leftDir);
- analogWrite(rightMotorPWM, rightPWM);
- analogWrite(leftMotorPWM, leftPWM);
- delay(dlay);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement