Teste de passos
stepper.h@0:3c2829d3f80f, 2020-04-13 (annotated)
- Committer:
- MatteusCarr
- Date:
- Mon Apr 13 14:07:16 2020 +0000
- Revision:
- 0:3c2829d3f80f
Teste da biblioteca de passos
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
MatteusCarr | 0:3c2829d3f80f | 1 | /* mbed Stepper Library |
MatteusCarr | 0:3c2829d3f80f | 2 | * Copyright (c) 2010 fachatz |
MatteusCarr | 0:3c2829d3f80f | 3 | * |
MatteusCarr | 0:3c2829d3f80f | 4 | * Permission is hereby granted, free of charge, to any person obtaining a copy |
MatteusCarr | 0:3c2829d3f80f | 5 | * of this software and associated documentation files (the "Software"), to deal |
MatteusCarr | 0:3c2829d3f80f | 6 | * in the Software without restriction, including without limitation the rights |
MatteusCarr | 0:3c2829d3f80f | 7 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell |
MatteusCarr | 0:3c2829d3f80f | 8 | * copies of the Software, and to permit persons to whom the Software is |
MatteusCarr | 0:3c2829d3f80f | 9 | * furnished to do so, subject to the following conditions: |
MatteusCarr | 0:3c2829d3f80f | 10 | * |
MatteusCarr | 0:3c2829d3f80f | 11 | * The above copyright notice and this permission notice shall be included in |
MatteusCarr | 0:3c2829d3f80f | 12 | * all copies or substantial portions of the Software. |
MatteusCarr | 0:3c2829d3f80f | 13 | * |
MatteusCarr | 0:3c2829d3f80f | 14 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR |
MatteusCarr | 0:3c2829d3f80f | 15 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, |
MatteusCarr | 0:3c2829d3f80f | 16 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE |
MatteusCarr | 0:3c2829d3f80f | 17 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER |
MatteusCarr | 0:3c2829d3f80f | 18 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, |
MatteusCarr | 0:3c2829d3f80f | 19 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN |
MatteusCarr | 0:3c2829d3f80f | 20 | * THE SOFTWARE. |
MatteusCarr | 0:3c2829d3f80f | 21 | */ |
MatteusCarr | 0:3c2829d3f80f | 22 | #ifndef MBED_STEPPER_H |
MatteusCarr | 0:3c2829d3f80f | 23 | #define MBED_STEPPER_H |
MatteusCarr | 0:3c2829d3f80f | 24 | |
MatteusCarr | 0:3c2829d3f80f | 25 | #include "mbed.h" |
MatteusCarr | 0:3c2829d3f80f | 26 | |
MatteusCarr | 0:3c2829d3f80f | 27 | /** Stepper control class |
MatteusCarr | 0:3c2829d3f80f | 28 | * |
MatteusCarr | 0:3c2829d3f80f | 29 | * Example: |
MatteusCarr | 0:3c2829d3f80f | 30 | * @code |
MatteusCarr | 0:3c2829d3f80f | 31 | * // apply number of steps, direction, speed and |
MatteusCarr | 0:3c2829d3f80f | 32 | * // a linear acceleration/deceleration to a Stepper Motor Controller |
MatteusCarr | 0:3c2829d3f80f | 33 | * #include "mbed.h" |
MatteusCarr | 0:3c2829d3f80f | 34 | * #include "stepper.h" |
MatteusCarr | 0:3c2829d3f80f | 35 | * |
MatteusCarr | 0:3c2829d3f80f | 36 | * #define ACCEL_ON 1 |
MatteusCarr | 0:3c2829d3f80f | 37 | * #define ACCEL_OFF 0 |
MatteusCarr | 0:3c2829d3f80f | 38 | * #define SPEED 100 |
MatteusCarr | 0:3c2829d3f80f | 39 | * |
MatteusCarr | 0:3c2829d3f80f | 40 | * stepper x(P18,P21); |
MatteusCarr | 0:3c2829d3f80f | 41 | * stepper y(P19,P22); |
MatteusCarr | 0:3c2829d3f80f | 42 | * stepper z(P20,P23); |
MatteusCarr | 0:3c2829d3f80f | 43 | * |
MatteusCarr | 0:3c2829d3f80f | 44 | * int main() |
MatteusCarr | 0:3c2829d3f80f | 45 | * { |
MatteusCarr | 0:3c2829d3f80f | 46 | * x.step(1000,1,SPEED,ACCEL_ON); |
MatteusCarr | 0:3c2829d3f80f | 47 | * y.step(5000,0,SPEED,ACCEL_ON); |
MatteusCarr | 0:3c2829d3f80f | 48 | * z.step(2000,1,SPEED,ACCEL_ON); |
MatteusCarr | 0:3c2829d3f80f | 49 | * |
MatteusCarr | 0:3c2829d3f80f | 50 | * } |
MatteusCarr | 0:3c2829d3f80f | 51 | * @endcode |
MatteusCarr | 0:3c2829d3f80f | 52 | */ |
MatteusCarr | 0:3c2829d3f80f | 53 | class stepper { |
MatteusCarr | 0:3c2829d3f80f | 54 | |
MatteusCarr | 0:3c2829d3f80f | 55 | public: |
MatteusCarr | 0:3c2829d3f80f | 56 | |
MatteusCarr | 0:3c2829d3f80f | 57 | /** Create a stepper object connected to the specified clk pin and dir pin |
MatteusCarr | 0:3c2829d3f80f | 58 | * |
MatteusCarr | 0:3c2829d3f80f | 59 | * @param pin clk pin to connect to |
MatteusCarr | 0:3c2829d3f80f | 60 | * @param pin dir pin to connect to |
MatteusCarr | 0:3c2829d3f80f | 61 | */ |
MatteusCarr | 0:3c2829d3f80f | 62 | stepper(PinName clk, PinName dir); |
MatteusCarr | 0:3c2829d3f80f | 63 | |
MatteusCarr | 0:3c2829d3f80f | 64 | /** Set number of steps to direction with speed and |
MatteusCarr | 0:3c2829d3f80f | 65 | * a linear acceleration/deceleration [on/off] |
MatteusCarr | 0:3c2829d3f80f | 66 | * to a Stepper Motor Controller |
MatteusCarr | 0:3c2829d3f80f | 67 | * |
MatteusCarr | 0:3c2829d3f80f | 68 | * @param n_steps number of steps to go |
MatteusCarr | 0:3c2829d3f80f | 69 | * @param direction 1 or 0 |
MatteusCarr | 0:3c2829d3f80f | 70 | * @param time value for value in us |
MatteusCarr | 0:3c2829d3f80f | 71 | * @param accel 1 or 0 for accel/decel [on/off] |
MatteusCarr | 0:3c2829d3f80f | 72 | */ |
MatteusCarr | 0:3c2829d3f80f | 73 | void step(int n_steps, bool direction, int speed, bool accel); |
MatteusCarr | 0:3c2829d3f80f | 74 | |
MatteusCarr | 0:3c2829d3f80f | 75 | /** get version number |
MatteusCarr | 0:3c2829d3f80f | 76 | * |
MatteusCarr | 0:3c2829d3f80f | 77 | * @param returns Library version number |
MatteusCarr | 0:3c2829d3f80f | 78 | */ |
MatteusCarr | 0:3c2829d3f80f | 79 | float version(void); |
MatteusCarr | 0:3c2829d3f80f | 80 | |
MatteusCarr | 0:3c2829d3f80f | 81 | private: |
MatteusCarr | 0:3c2829d3f80f | 82 | DigitalOut _clk; |
MatteusCarr | 0:3c2829d3f80f | 83 | DigitalOut _dir; |
MatteusCarr | 0:3c2829d3f80f | 84 | |
MatteusCarr | 0:3c2829d3f80f | 85 | }; |
MatteusCarr | 0:3c2829d3f80f | 86 | |
MatteusCarr | 0:3c2829d3f80f | 87 | #endif |