Mario Simaremare
/
g3_waterplay
Salinity and temperature sensors are implemented in classes.
DRV8825.cpp@15:e112bab9aa2f, 2016-06-28 (annotated)
- Committer:
- mariosimaremare
- Date:
- Tue Jun 28 12:30:40 2016 +0000
- Revision:
- 15:e112bab9aa2f
- Parent:
- 2:ed17e258da0d
Using new boxes.
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
mariosimaremare | 2:ed17e258da0d | 1 | #include "DRV8825.h" |
mariosimaremare | 2:ed17e258da0d | 2 | #include "mbed.h" |
mariosimaremare | 2:ed17e258da0d | 3 | |
mariosimaremare | 2:ed17e258da0d | 4 | DigitalOut myled(LED1); |
mariosimaremare | 2:ed17e258da0d | 5 | |
mariosimaremare | 2:ed17e258da0d | 6 | DRV8825::DRV8825(PinName _en, PinName m0, PinName m1, PinName m2, PinName _stepPin, PinName dir):en(_en), |
mariosimaremare | 2:ed17e258da0d | 7 | microstepping(m0, m1, m2), |
mariosimaremare | 2:ed17e258da0d | 8 | stepPin(_stepPin), |
mariosimaremare | 2:ed17e258da0d | 9 | direction(dir) |
mariosimaremare | 2:ed17e258da0d | 10 | { |
mariosimaremare | 2:ed17e258da0d | 11 | } |
mariosimaremare | 2:ed17e258da0d | 12 | |
mariosimaremare | 2:ed17e258da0d | 13 | void DRV8825::settings(float microstep, int dir, float speed) |
mariosimaremare | 2:ed17e258da0d | 14 | { |
mariosimaremare | 2:ed17e258da0d | 15 | //Microsteppiing settings |
mariosimaremare | 2:ed17e258da0d | 16 | if (microstep == 1) microstepping = 0; |
mariosimaremare | 2:ed17e258da0d | 17 | else if (microstep == 1/2) microstepping = 1; |
mariosimaremare | 2:ed17e258da0d | 18 | else if (microstep == 1/4) microstepping = 2; |
mariosimaremare | 2:ed17e258da0d | 19 | else if (microstep == 1/8) microstepping = 3; |
mariosimaremare | 2:ed17e258da0d | 20 | else if (microstep == 1/16) microstepping = 4; |
mariosimaremare | 2:ed17e258da0d | 21 | else if (microstep == 1/32) microstepping = 5; |
mariosimaremare | 2:ed17e258da0d | 22 | |
mariosimaremare | 2:ed17e258da0d | 23 | if (dir == 1) { |
mariosimaremare | 2:ed17e258da0d | 24 | direction = 0; |
mariosimaremare | 2:ed17e258da0d | 25 | } else if (dir == 0) { |
mariosimaremare | 2:ed17e258da0d | 26 | direction = 1; |
mariosimaremare | 2:ed17e258da0d | 27 | } |
mariosimaremare | 2:ed17e258da0d | 28 | |
mariosimaremare | 2:ed17e258da0d | 29 | // Speeed or times per second |
mariosimaremare | 2:ed17e258da0d | 30 | if(stepPin == 1) { |
mariosimaremare | 2:ed17e258da0d | 31 | stepPin = 0; |
mariosimaremare | 2:ed17e258da0d | 32 | wait(1/speed); |
mariosimaremare | 2:ed17e258da0d | 33 | } else { |
mariosimaremare | 2:ed17e258da0d | 34 | stepPin = 1; |
mariosimaremare | 2:ed17e258da0d | 35 | wait(1/speed); |
mariosimaremare | 2:ed17e258da0d | 36 | } |
mariosimaremare | 2:ed17e258da0d | 37 | myled = stepPin; |
mariosimaremare | 2:ed17e258da0d | 38 | |
mariosimaremare | 2:ed17e258da0d | 39 | |
mariosimaremare | 2:ed17e258da0d | 40 | } |
mariosimaremare | 2:ed17e258da0d | 41 | |
mariosimaremare | 2:ed17e258da0d | 42 | void DRV8825::enable() |
mariosimaremare | 2:ed17e258da0d | 43 | { |
mariosimaremare | 2:ed17e258da0d | 44 | en = 0; |
mariosimaremare | 2:ed17e258da0d | 45 | } |
mariosimaremare | 2:ed17e258da0d | 46 | |
mariosimaremare | 2:ed17e258da0d | 47 | void DRV8825::disable() |
mariosimaremare | 2:ed17e258da0d | 48 | { |
mariosimaremare | 2:ed17e258da0d | 49 | en = 1; |
mariosimaremare | 2:ed17e258da0d | 50 | } |