Skip to content

Instantly share code, notes, and snippets.

@benrules2
Created January 24, 2019 01:32
Show Gist options
  • Save benrules2/f9268a320d99863fe9dbd330351af56a to your computer and use it in GitHub Desktop.
Save benrules2/f9268a320d99863fe9dbd330351af56a to your computer and use it in GitHub Desktop.
Billy Bass Motor Diagnostic
#include <AFMotor.h>
#define NUM_MOTORS 3
AF_DCMotor head(1, MOTOR12_1KHZ);
AF_DCMotor mouth(2, MOTOR12_1KHZ);
AF_DCMotor tail(3, MOTOR34_1KHZ);
AF_DCMotor motors[NUM_MOTORS] = {head, mouth, tail};
void setup() {
Serial.begin(9600); // set up Serial library at 9600 bps
Serial.println("Motor test!");
for (int i = 0; i < NUM_MOTORS; i++) {
motors[i].setSpeed(255);
}
}
void runMotorOnOff(AF_DCMotor motor, int animationDelay = 500) {
motor.run(FORWARD);
delay(animationDelay);
motor.run(BACKWARD);
delay(5);
motor.run(RELEASE);
delay(animationDelay / 2);
}
void loop() {
runMotorOnOff(head, 1000);
runMotorOnOff(mouth, 500);
runMotorOnOff(tail, 1000);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment