arduino stuffs
Diffstat (limited to 'libraries/AFMotor/AFMotor.h')
| -rwxr-xr-x | libraries/AFMotor/AFMotor.h | 134 |
1 files changed, 134 insertions, 0 deletions
diff --git a/libraries/AFMotor/AFMotor.h b/libraries/AFMotor/AFMotor.h new file mode 100755 index 0000000..290d282 --- /dev/null +++ b/libraries/AFMotor/AFMotor.h @@ -0,0 +1,134 @@ +// Adafruit Motor shield library +// copyright Adafruit Industries LLC, 2009 +// this code is public domain, enjoy! + +// updated for Arduino 1.0.2 by mem 22 Nov 2012 + +#ifndef _AFMotor_h_ +#define _AFMotor_h_ + +#include <inttypes.h> +#include <avr/io.h> + +//#define MOTORDEBUG 1 + +#define MICROSTEPS 16 // 8 or 16 + +#if defined(__AVR_ATmega8__) || \ + defined(__AVR_ATmega48__) || \ + defined(__AVR_ATmega88__) || \ + defined(__AVR_ATmega168__) || \ + defined(__AVR_ATmega328P__) +#define MOTOR12_64KHZ _BV(CS20) // no prescale +#define MOTOR12_8KHZ _BV(CS21) // divide by 8 +#define MOTOR12_2KHZ _BV(CS21) | _BV(CS20) // divide by 32 +#define MOTOR12_1KHZ _BV(CS22) // divide by 64 + +#elif defined(__AVR_ATmega1280__) || defined(__AVR_ATmega2560__) +#define MOTOR12_64KHZ _BV(CS10) // no prescale +#define MOTOR12_8KHZ _BV(CS11) // divide by 8 +#define MOTOR12_2KHZ _BV(CS11) | _BV(CS20) // divide by 32 +#define MOTOR12_1KHZ _BV(CS12) // divide by 64 + +#elif defined(__AVR_ATmega32U4__) // Leonardo (mem 22 Nov 2012) +#define MOTOR12_64KHZ _BV(CS00) // no prescale +#define MOTOR12_8KHZ _BV(CS01) // divide by 8 +#define MOTOR12_2KHZ _BV(CS01) | _BV(CS20) // divide by 32 +#define MOTOR12_1KHZ _BV(CS02) // divide by 64 +#endif + +#if defined(__AVR_ATmega8__) || \ + defined(__AVR_ATmega48__) || \ + defined(__AVR_ATmega88__) || \ + defined(__AVR_ATmega168__) || \ + defined(__AVR_ATmega328P__) +#define MOTOR34_64KHZ _BV(CS00) // no prescale +#define MOTOR34_8KHZ _BV(CS01) // divide by 8 +#define MOTOR34_1KHZ _BV(CS01) | _BV(CS00) // divide by 64 +#else +#define MOTOR34_64KHZ _BV(CS40) // no prescale +#define MOTOR34_8KHZ _BV(CS41) // divide by 8 +#define MOTOR34_1KHZ _BV(CS41) | _BV(CS40) // divide by 64 +#endif + +#define MOTOR1_A 2 +#define MOTOR1_B 3 +#define MOTOR2_A 1 +#define MOTOR2_B 4 +#define MOTOR4_A 0 +#define MOTOR4_B 6 +#define MOTOR3_A 5 +#define MOTOR3_B 7 + +#define FORWARD 1 +#define BACKWARD 2 +#define BRAKE 3 +#define RELEASE 4 + +#define SINGLE 1 +#define DOUBLE 2 +#define INTERLEAVE 3 +#define MICROSTEP 4 + +/* +#define LATCH 4 +#define LATCH_DDR DDRB +#define LATCH_PORT PORTB + +#define CLK_PORT PORTD +#define CLK_DDR DDRD +#define CLK 4 + +#define ENABLE_PORT PORTD +#define ENABLE_DDR DDRD +#define ENABLE 7 + +#define SER 0 +#define SER_DDR DDRB +#define SER_PORT PORTB +*/ + +// Arduino pin names +#define MOTORLATCH 12 +#define MOTORCLK 4 +#define MOTORENABLE 7 +#define MOTORDATA 8 + +class AFMotorController +{ + public: + AFMotorController(void); + void enable(void); + friend class AF_DCMotor; + void latch_tx(void); +}; + +class AF_DCMotor +{ + public: + AF_DCMotor(uint8_t motornum, uint8_t freq = MOTOR34_8KHZ); + void run(uint8_t); + void setSpeed(uint8_t); + + private: + uint8_t motornum, pwmfreq; +}; + +class AF_Stepper { + public: + AF_Stepper(uint16_t, uint8_t); + void step(uint16_t steps, uint8_t dir, uint8_t style = SINGLE); + void setSpeed(uint16_t); + uint8_t onestep(uint8_t dir, uint8_t style); + void release(void); + uint16_t revsteps; // # steps per revolution + uint8_t steppernum; + uint32_t usperstep, steppingcounter; + private: + uint8_t currentstep; + +}; + +uint8_t getlatchstate(void); + +#endif |