WaffleMast3r

Untitled

Apr 3rd, 2020
89
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.43 KB | None | 0 0
  1. class Motor {
  2. private:
  3. int steps_per_revolution = 200 * 32;
  4. int DIR, STEP;
  5. int Frecventa, Cantitate = 4;
  6. boolean running = false, inAction = false, CW = true;
  7. long steps_per_pull = steps_per_revolution / Cantitate;//60 000 000 microsecunde = 1 min;
  8. long dela = ((60000000 / Frecventa) / 2) / steps_per_pull;
  9. long current_stage = 0;
  10.  
  11. public:
  12. void setup(int DIR_, int STEP_) {
  13. DIR = DIR_;
  14. STEP = STEP_;
  15. pinMode(DIR, OUTPUT);
  16. pinMode(STEP, OUTPUT);
  17. digitalWrite(DIR, HIGH);
  18. }
  19.  
  20. void toggle(int frecventa) {
  21. Frecventa = frecventa;
  22. running = !running;
  23. }
  24.  
  25. boolean isInAction() {
  26. return inAction;
  27. }
  28.  
  29. // Metoda care se apeleaza o singura data in functia loop();
  30. void loop() {
  31. Serial.println(running);
  32. Serial.println(inAction);
  33. if (running || inAction) {
  34. if (!inAction) {
  35. inAction = true;
  36. }
  37. if (CW) {
  38. if (++current_stage > steps_per_pull) {
  39. CW = false;
  40. digitalWrite(DIR, LOW);
  41. }
  42. } else {
  43. if (--current_stage < 0) {
  44. CW = true;
  45. digitalWrite(DIR, HIGH);
  46. inAction = false;
  47. }
  48. }
  49.  
  50. digitalWrite(STEP, HIGH);
  51. delayMicroseconds(dela);
  52. digitalWrite(STEP, LOW);
  53. delayMicroseconds(dela);
  54. }
  55. }
  56. };
  57. Motor motor;
Add Comment
Please, Sign In to add comment