Advertisement
gabbyshimoni

nema17withL298n

Jul 30th, 2019
223
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.89 KB | None | 0 0
  1. // Include the Arduino Stepper Library
  2. #include <Stepper.h>
  3.  
  4. // Define Constants
  5.  
  6. // Number of steps per output rotation
  7. const int STEPS_PER_REV = 200;
  8. const int SPEED_CONTROL = A0;
  9.  
  10. // Create Instance of Stepper Class
  11. // Specify Pins used for motor coils
  12. // The pins used are 8,9,10,11
  13. // Connected to L298N Motor Driver In1, In2, In3, In4
  14. // Pins entered in sequence 1-2-3-4 for proper step sequencing
  15.  
  16. Stepper stepper_NEMA17(STEPS_PER_REV, 8, 9, 10, 11);
  17.  
  18. void setup() {
  19.   // nothing to do inside the setup
  20. }
  21.  
  22. void loop() {
  23.   // read the sensor value:
  24.   int sensorReading = analogRead(SPEED_CONTROL);
  25.   // map it to a range from 0 to 100:
  26.   int motorSpeed = map(sensorReading, 0, 1023, 0, 100);
  27.   // set the motor speed:
  28.   if (motorSpeed > 0) {
  29.     stepper_NEMA17.setSpeed(motorSpeed);
  30.     // step 1/100 of a revolution:
  31.     stepper_NEMA17.step(STEPS_PER_REV / 100);
  32.   }
  33. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement