123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135 |
- #include "Atm_stepper.h"
- Atm_stepper& Atm_stepper::begin(int stepPin, int dirPin) {
-
- const static state_t state_table[] PROGMEM = {
-
- ENT_IDLE, -1, -1, -1, -1, RUNNING, -1,
- ENT_READY, -1, -1, IDLE, -1, RUNNING, -1,
- ENT_RUNNING, LP_RUNNING, -1, -1, STOPPING, RUNNING, -1,
- ENT_STOPPING, -1, EXT_STOPPING, -1, READY, -1, -1,
- };
-
- Machine::begin( state_table, ELSE );
- AccelStepper _motor (1, stepPin, dirPin);
-
-
-
-
-
- pinMode(0, OUTPUT);
- digitalWrite(0, HIGH);
- return *this;
- }
- int Atm_stepper::event( int id ) {
- switch ( id ) {
- case EVT_IDLE_TIMER:
- return 0;
- case EVT_ON_TARGET:
- return _motor.distanceToGo()== 0 ;
- }
- return 0;
- }
- void Atm_stepper::action( int id ) {
- switch ( id ) {
- case ENT_IDLE:
- digitalWrite(0, LOW);
- return;
- case ENT_READY:
- digitalWrite(0, HIGH);
- return;
- case ENT_RUNNING:
- digitalWrite(0, HIGH);
-
- return;
- case LP_RUNNING:
- _motor.run();
- Serial.println(_motor.currentPosition());
- return;
- case ENT_STOPPING:
- return;
- case EXT_STOPPING:
- return;
- }
- }
- Atm_stepper& Atm_stepper::trigger( int event ) {
- Machine::trigger( event );
- return *this;
- }
- int Atm_stepper::state( void ) {
- return Machine::state();
- }
- Atm_stepper& Atm_stepper::gotoStep(long int targetStep ) {
-
- _motor.move(targetStep);
- _motor.run();
- Serial.println(_motor.distanceToGo());
- _motor.setMaxSpeed(5000);
- _motor.setAcceleration(6000);
- trigger( EVT_GOTO );
- return *this;
- }
- Atm_stepper& Atm_stepper::onOnchange( Machine& machine, int event ) {
- onPush( connectors, ON_ONCHANGE, 0, 1, 1, machine, event );
- return *this;
- }
- Atm_stepper& Atm_stepper::onOnchange( atm_cb_push_t callback, int idx ) {
- onPush( connectors, ON_ONCHANGE, 0, 1, 1, callback, idx );
- return *this;
- }
- Atm_stepper& Atm_stepper::trace( Stream & stream ) {
- Machine::setTrace( &stream, atm_serial_debug::trace,
- "STEPPER\0EVT_IDLE_TIMER\0EVT_ON_TARGET\0EVT_GOTO\0ELSE\0IDLE\0READY\0RUNNING\0STOPPING" );
- return *this;
- }
|