Oz Step Counter

Hardware Required

  • Arduino MEGA Board

  • Arduino

    #include <OzIDManager.h>
    #include <OzStepCounter.h>
    
    //define global pointers
    OzIDManager* manager;
    OzStepCounter* counter;
    
    void setup()
    {
    	Serial.begin(115200);
    	while (!Serial) {}
    
    	manager = new OzIDManager;
      	manager->_sendACK = true;
      	manager->_checksum = true;
    
    	OzCommunication::setIDManager(manager);
    
    	//define the number of axes:
    	counter = new OzStepCounter(4);
    	//STEPX: pin 21; DIRX: pin 11;
    	//STEPY: 20; DIRY: 10;
    	//STEPZ: 19; DIRZ: 9;
    	//STEPA: 18; DIRA: 8;
    	//STEPB: 2; DIRB: 7;
    	//STEPC: 3; DIRC: 6;
    	manager->PrintWelcomeLine(manager, 1);
    	manager->PrintWelcomeLine(counter, 2);
    }
    
    void loop()
    {
    	OzCommunication::communicate();
    	counter->ownLoop();
    }
    
    ISR(INT0_vect) { //X motor
    	counter->_counted_steps[0]++;
    	counter->time_of_last_step = millis();
    	if (counter->_stepping[0] == false) { //It needs for the 'went' event
    		counter->_stepping[0] = true;
    		counter->went_event_sent = false;
    		counter->_motordir[0] = counter->_DIRX_pin->read();
    	}
    }
    
    ISR(INT1_vect) { //Y motor
    	counter->_counted_steps[1]++;
    	counter->time_of_last_step = millis();
    	if (counter->_stepping[1] == false) { //It needs for the 'went' event
    		counter->_stepping[1] = true;
    		counter->went_event_sent = false;
    		counter->_motordir[1] = counter->_DIRY_pin->read();
    	}
    }
    
    ISR(INT2_vect) { //Z motor
    	counter->_counted_steps[2]++;
    	counter->time_of_last_step = millis();
    	if (counter->_stepping[2] == false) { //It needs for the 'went' event
    		counter->_stepping[2] = true;
    		counter->went_event_sent = false;
    		counter->_motordir[2] = counter->_DIRZ_pin->read();
    	}
    }
    
    ISR(INT3_vect) { //A motor
    	counter->_counted_steps[3]++;
    	counter->time_of_last_step = millis();
    	if (counter->_stepping[3] == false) { //It needs for the 'went' event
    		counter->_stepping[3] = true;
    		counter->went_event_sent = false;
    		counter->_motordir[3] = counter->_DIRA_pin->read();
    	}
    }
    
    ISR(INT4_vect) { //B motor
    	counter->_counted_steps[4]++;
    	counter->time_of_last_step = millis();
    	if (counter->_stepping[4] == false) { //It needs for the 'went' event
    		counter->_stepping[4] = true;
    		counter->went_event_sent = false;
    		counter->_motordir[4] = counter->_DIRB_pin->read();
    	}
    }
    
    ISR(INT5_vect) { //C motor
    	counter->_counted_steps[5]++;
    	counter->time_of_last_step = millis();
    	if (counter->_stepping[5] == false) { //It needs for the 'went' event
    		counter->_stepping[5] = true;
    		counter->went_event_sent = false;
    		counter->_motordir[5] = counter->_DIRC_pin->read();
    	}
    }
    

    Necessary Libaries