// Implements steps according to the current speed
 // You must call this at least once per step
 // returns true if a step occurred
 boolean EightAccelStepper::runSpeed()
 {
     unsigned long time = millis();
     
     if (time > getLastStepTime() + getStepInterval())
     {
         if (getSpeed() > 0)
         {
             // Clockwise
             setCurrentPos(getCurrentPos() + 1);
         }
         else if (getSpeed() < 0)
         {
             // Anticlockwise
             setCurrentPos(getCurrentPos() - 1);            
         }
         if (getPins() == 8) {
             step(getCurrentPos() & 0x7); // Bottom 3 bits (same as mod 8, but works with + and - numbers)                 
         } else {
             step(getCurrentPos() & 0x3); // Bottom 2 bits (same as mod 4, but works with + and - numbers) 
         }
         
         setLastStepTime(time);
         return true;
     }
     else
         return false;
 }
Example #2
0
bool Servo::removeChannel(ServoChannel* channel)
{
	if (channels.removeElement(channel)) {
		ETS_INTR_LOCK();
		getPins();
		calcTiming();
		ETS_INTR_UNLOCK();
		if (channels.size() == 0) {
			started = false;
			hardwareTimer.stop();
		}
		return true;
	}
	return false;
}
Example #3
0
bool Servo::addChannel(ServoChannel* channel)
{
	uint8 channel_count = channels.size();
	if (channel_count > SERVO_CHANNEL_NUM_MAX) return false;
	channels.add(channel);

	ETS_INTR_LOCK();
	getPins();
	calcTiming();
	ETS_INTR_UNLOCK();

	if (!started) {
		started = true;
		hardwareTimer.initializeUs(100000,ServoTimerInt);
		hardwareTimer.startOnce();
	}
	return true;
}
 // Subclasses can override
 void EightAccelStepper::step(uint8_t step)
 {
     switch (getPins())
     {
         case 0:
             step0();
             break;
         case 1:
             step1(step);
             break;
             
         case 2:
             step2(step);
             break;
             
         case 4:
             step4(step);
             break; 
             
         case 8:
             step8(step);
             break;   
     }
 }