DC motors are controlled by 4 PWM output pins, the 4 PWM pins let you control speed and direction. And we'll use our seesaw_Motor library to help us manage the throttle (speed) and direction for us, making it very easy to control motors
Note that each DC motor is a little different, so just because you have two at the same throttle does not mean they'll rotate at the exact same speed! Some tweaking may be required
The two wires of the DC motor can be plugged in either way into each Crickit Motor port. If the motor spins the opposite way from what you want to call 'forward', just flip the wires!
#include "Adafruit_Crickit.h" #include "seesaw_motor.h" Adafruit_Crickit crickit; seesaw_Motor motor_a(&crickit); seesaw_Motor motor_b(&crickit); void setup() { Serial.begin(115200); Serial.println("Dual motor demo!"); if(!crickit.begin()){ Serial.println("ERROR!"); while(1) delay(1); } else Serial.println("Crickit started"); //attach motor a motor_a.attach(CRICKIT_MOTOR_A1, CRICKIT_MOTOR_A2); //attach motor b motor_b.attach(CRICKIT_MOTOR_B1, CRICKIT_MOTOR_B2); } void loop() { motor_a.throttle(1); motor_b.throttle(-1); delay(1000); motor_a.throttle(.5); motor_b.throttle(-.5); delay(1000); motor_a.throttle(0); motor_b.throttle(0); delay(1000); motor_a.throttle(-.5); motor_b.throttle(.5); delay(1000); motor_a.throttle(-1); motor_b.throttle(1); delay(1000); motor_a.throttle(0); motor_b.throttle(0); delay(500); }
Page last edited January 22, 2025
Text editor powered by tinymce.