Guest User

Untitled

a guest
Apr 25th, 2018
72
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.08 KB | None | 0 0
  1. // Adafruit Motor shield library
  2. // copyright Adafruit Industries LLC, 2009
  3. // this code is public domain, enjoy!
  4.  
  5. #ifndef _AFMotor_h_
  6. #define _AFMotor_h_
  7.  
  8. #include <inttypes.h>
  9. #include <avr/io.h>
  10.  
  11. //#define MOTORDEBUG 1
  12.  
  13. #define MICROSTEPS 16 // 8 or 16
  14.  
  15. #define MOTOR12_64KHZ _BV(CS20) // no prescale
  16. #define MOTOR12_8KHZ _BV(CS21) // divide by 8
  17. #define MOTOR12_2KHZ _BV(CS21) | _BV(CS20) // divide by 32
  18. #define MOTOR12_1KHZ _BV(CS22) // divide by 64
  19.  
  20. #define MOTOR34_64KHZ _BV(CS00) // no prescale
  21. #define MOTOR34_8KHZ _BV(CS01) // divide by 8
  22. #define MOTOR34_1KHZ _BV(CS01) | _BV(CS00) // divide by 64
  23.  
  24. #define MOTOR1_A 2
  25. #define MOTOR1_B 3
  26. #define MOTOR2_A 1
  27. #define MOTOR2_B 4
  28. #define MOTOR4_A 0
  29. #define MOTOR4_B 6
  30. #define MOTOR3_A 5
  31. #define MOTOR3_B 7
  32.  
  33. #define FORWARD 1
  34. #define BACKWARD 2
  35. #define BRAKE 3
  36. #define RELEASE 4
  37.  
  38. #define SINGLE 1
  39. #define DOUBLE 2
  40. #define INTERLEAVE 3
  41. #define MICROSTEP 4
  42.  
  43. /*
  44. #define LATCH 4
  45. #define LATCH_DDR DDRB
  46. #define LATCH_PORT PORTB
  47.  
  48. #define CLK_PORT PORTD
  49. #define CLK_DDR DDRD
  50. #define CLK 4
  51.  
  52. #define ENABLE_PORT PORTD
  53. #define ENABLE_DDR DDRD
  54. #define ENABLE 7
  55.  
  56. #define SER 0
  57. #define SER_DDR DDRB
  58. #define SER_PORT PORTB
  59. */
  60.  
  61. // Arduino pin names
  62. #define MOTORLATCH 12
  63. #define MOTORCLK 4
  64. #define MOTORENABLE 7
  65. #define MOTORDATA 8
  66.  
  67. class AFMotorController
  68. {
  69. public:
  70. AFMotorController(void);
  71. void enable(void);
  72. friend class AF_DCMotor;
  73. void latch_tx(void);
  74. };
  75.  
  76. class AF_DCMotor
  77. {
  78. public:
  79. AF_DCMotor(uint8_t motornum, uint8_t freq = MOTOR34_8KHZ);
  80. void run(uint8_t);
  81. void setSpeed(uint8_t);
  82.  
  83. private:
  84. uint8_t motornum, pwmfreq;
  85. };
  86.  
  87. class AF_Stepper {
  88. public:
  89. AF_Stepper(uint16_t, uint8_t);
  90. void step(uint16_t steps, uint8_t dir, uint8_t style = SINGLE);
  91. void setSpeed(uint16_t);
  92. uint8_t onestep(uint8_t dir, uint8_t style);
  93. void release(void);
  94. uint16_t revsteps; // # steps per revolution
  95. uint8_t steppernum;
  96. uint32_t usperstep, steppingcounter;
  97. private:
  98. uint8_t currentstep;
  99.  
  100. };
  101.  
  102. uint8_t getlatchstate(void);
  103.  
  104. #endif
Add Comment
Please, Sign In to add comment