Library for stepper motor.

Dependents:   Nucleo_ZCP_v2 Nucleo_ZCP_1mb Nucleo_ZCP_pis

Committer:
dkrajacic
Date:
Sat Nov 16 11:01:17 2019 +0000
Revision:
2:e1500f54f6a4
Parent:
0:8a14924886c4
Changed  removed relax moveForward and moveRevers.

Who changed what in which revision?

UserRevisionLine numberNew contents of line
fbcosentino 0:8a14924886c4 1 /**
fbcosentino 0:8a14924886c4 2 * @file ULN2003.h
fbcosentino 0:8a14924886c4 3 * Library to control 4 phase stepper motors using ULN2003
fbcosentino 0:8a14924886c4 4 *
fbcosentino 0:8a14924886c4 5 * @author Fernando Cosentino
fbcosentino 0:8a14924886c4 6 */
fbcosentino 0:8a14924886c4 7
fbcosentino 0:8a14924886c4 8 #ifndef __ULN2003
fbcosentino 0:8a14924886c4 9 #define __ULN2003
fbcosentino 0:8a14924886c4 10
fbcosentino 0:8a14924886c4 11 #include "mbed.h"
fbcosentino 0:8a14924886c4 12
fbcosentino 0:8a14924886c4 13 /**
fbcosentino 0:8a14924886c4 14 * ULN2003 Class
fbcosentino 0:8a14924886c4 15 *
fbcosentino 0:8a14924886c4 16 * @author Fernando Cosentino
fbcosentino 0:8a14924886c4 17 */
fbcosentino 0:8a14924886c4 18 class ULN2003 {
fbcosentino 0:8a14924886c4 19 public:
fbcosentino 0:8a14924886c4 20 /**
fbcosentino 0:8a14924886c4 21 * Creates an instance.
fbcosentino 0:8a14924886c4 22 *
fbcosentino 0:8a14924886c4 23 * @param pinOut1 Pin connected to IN1 in ULN2003 board
fbcosentino 0:8a14924886c4 24 * @param pinOut2 Pin connected to IN2 in ULN2003 board
fbcosentino 0:8a14924886c4 25 * @param pinOut3 Pin connected to IN3 in ULN2003 board
fbcosentino 0:8a14924886c4 26 * @param pinOut4 Pin connected to IN4 in ULN2003 board
fbcosentino 0:8a14924886c4 27 * @param full_turn_steps Amount of steps for a complete turn (4096 for 28BYJ-48)
fbcosentino 0:8a14924886c4 28 */
fbcosentino 0:8a14924886c4 29 ULN2003(PinName pinOut1, PinName pinOut2, PinName pinOut3, PinName pinOut4, int full_turn_steps = 4096);
fbcosentino 0:8a14924886c4 30
fbcosentino 0:8a14924886c4 31 /**
fbcosentino 0:8a14924886c4 32 * Moves the motor one step clockwise, and leaves the motor powered.
fbcosentino 0:8a14924886c4 33 */
fbcosentino 0:8a14924886c4 34 void stepForward();
fbcosentino 0:8a14924886c4 35
fbcosentino 0:8a14924886c4 36 /**
fbcosentino 0:8a14924886c4 37 * Moves the motor one step counter-clockwise, and leaves the motor powered.
fbcosentino 0:8a14924886c4 38 */
fbcosentino 0:8a14924886c4 39 void stepReverse();
fbcosentino 0:8a14924886c4 40
fbcosentino 0:8a14924886c4 41 /**
fbcosentino 0:8a14924886c4 42 * Moves the motor a number of steps clockwise, in the given speed. Leaves
fbcosentino 0:8a14924886c4 43 * the motor in relaxed state (no power in any coil).
fbcosentino 0:8a14924886c4 44 *
fbcosentino 0:8a14924886c4 45 * @param steps Number of steps to move
fbcosentino 0:8a14924886c4 46 * @param speed Speed in steps per second
fbcosentino 0:8a14924886c4 47 * @note 28BYJ-48 can't handle speeds higher than 833 steps per second
fbcosentino 0:8a14924886c4 48 */
fbcosentino 0:8a14924886c4 49 void moveForward(int steps, float speed = 500);
fbcosentino 0:8a14924886c4 50
fbcosentino 0:8a14924886c4 51 /**
fbcosentino 0:8a14924886c4 52 * Moves the motor a number of steps counter-clockwise, in the given speed.
fbcosentino 0:8a14924886c4 53 * Leaves the motor in relaxed state (no power in any coil).
fbcosentino 0:8a14924886c4 54 *
fbcosentino 0:8a14924886c4 55 * @param steps Number of steps to move
fbcosentino 0:8a14924886c4 56 * @param speed Speed in steps per second
fbcosentino 0:8a14924886c4 57 * @note 28BYJ-48 can't handle speeds higher than 833 steps per second
fbcosentino 0:8a14924886c4 58 */
fbcosentino 0:8a14924886c4 59 void moveReverse(int steps, float speed = 500);
fbcosentino 0:8a14924886c4 60
fbcosentino 0:8a14924886c4 61 /**
fbcosentino 0:8a14924886c4 62 * Moves the motor a number of turns clockwise, in the given speed.
fbcosentino 0:8a14924886c4 63 * Leaves the motor in relaxed state (no power in any coil).
fbcosentino 0:8a14924886c4 64 *
fbcosentino 0:8a14924886c4 65 * @param turns Number of complete turns to move (can be fractional)
fbcosentino 0:8a14924886c4 66 * @param speed Speed in complete turns per second
fbcosentino 0:8a14924886c4 67 * @note 28BYJ-48 can't handle speeds higher than 0.2 turns per second
fbcosentino 0:8a14924886c4 68 */
fbcosentino 0:8a14924886c4 69 void turnForward(float turns, float speed = 0.2);
fbcosentino 0:8a14924886c4 70
fbcosentino 0:8a14924886c4 71 /**
fbcosentino 0:8a14924886c4 72 * Moves the motor a number of turns counter-clockwise, in the given speed.
fbcosentino 0:8a14924886c4 73 * Leaves the motor in relaxed state (no power in any coil).
fbcosentino 0:8a14924886c4 74 *
fbcosentino 0:8a14924886c4 75 * @param turns Number of complete turns to move (can be fractional)
fbcosentino 0:8a14924886c4 76 * @param speed Speed in complete turns per second
fbcosentino 0:8a14924886c4 77 * @note 28BYJ-48 can't handle speeds higher than 0.2 turns per second
fbcosentino 0:8a14924886c4 78 */
fbcosentino 0:8a14924886c4 79 void turnReverse(float turns, float speed = 0.2);
fbcosentino 0:8a14924886c4 80
fbcosentino 0:8a14924886c4 81
fbcosentino 0:8a14924886c4 82 /**
fbcosentino 0:8a14924886c4 83 * Removes power from all coils, so no energy is spent and the motor is
fbcosentino 0:8a14924886c4 84 * free to be moved passively.
fbcosentino 0:8a14924886c4 85 */
fbcosentino 0:8a14924886c4 86 void relax();
fbcosentino 0:8a14924886c4 87
fbcosentino 0:8a14924886c4 88 private:
fbcosentino 0:8a14924886c4 89 void _set_output();
fbcosentino 0:8a14924886c4 90 DigitalOut _out1;
fbcosentino 0:8a14924886c4 91 DigitalOut _out2;
fbcosentino 0:8a14924886c4 92 DigitalOut _out3;
fbcosentino 0:8a14924886c4 93 DigitalOut _out4;
fbcosentino 0:8a14924886c4 94 int _pos;
fbcosentino 0:8a14924886c4 95 int _full_turn_steps;
fbcosentino 0:8a14924886c4 96 };
fbcosentino 0:8a14924886c4 97
fbcosentino 0:8a14924886c4 98 #endif