Created
September 1, 2019 12:27
-
-
Save Andrew-rw/a1db5bad0fb6e644b3a0c4f22fc6cbce to your computer and use it in GitHub Desktop.
Sketch for 37Dx70L motor control. Without closed-loop control
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
* Simple code for the L298N motor controller | |
* and Metal Gearmotor 37Dx52L mm with 64 CPR Encoder | |
*/ | |
#include <L298N.h> | |
// motor pin definition | |
#define M_EN 9 | |
#define M_IN1 8 | |
#define M_IN2 7 | |
// create a motor instance | |
L298N motor(M_EN, M_IN1, M_IN2); | |
// PWM signal for the motor driver | |
unsigned short driverPwm = 0; | |
// variables for sending information frequency configuration | |
long previousMillis = 0; | |
long interval = 200; | |
void setup() { | |
Serial.begin(57600); | |
Serial.println("Basic Motor Test:"); | |
} | |
void loop() { | |
unsigned long currentMillis = millis(); | |
if(currentMillis - previousMillis > interval){ | |
Serial.print("PWM value: "); | |
Serial.println(driverPwm); | |
previousMillis = currentMillis; | |
} | |
// check if the data has been sent from the computer: | |
// to make this code work properly, select "No line ending" in monitor | |
if (Serial.available()) { | |
// Narrowing convertion without check! Don't do this in production:) | |
driverPwm = Serial.parseInt(); | |
} | |
motor.setSpeed(driverPwm); | |
motor.forward(); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment