Go Down

Topic: Urgent : Help with Servo Activated Fire Extinguisher (Read 1 time) previous topic - next topic

EverRedRobot

Hello,
i am trying to write a code to control independently and simultaneously three servo. I use them to activate three fire extinguishers. I already made the mechanism and it works as i intended. The setup is a giant Scale Hitec HS 805-BB servo moving a 5:1 aluminium gear. That gear then pull a steel wire that press the lever of the fire extinguisher. The tricky part is that i need to made two type of activation:
the first one is a wave, three servo delayed one to another; and the second one is simply one servo moving but it should hold the 180 position for x time then return to 0 position. The single servo should change in turn.
An example of the rhythm could be:  Wave, 15000ms pause, First Servo for 4000ms, 10000ms pause,
Second Servo for 4000ms, 15000ms pause, Third Servo for 2000ms, 8000ms pause, again Third Servo for 2000ms, 6000ms pause, end of the loop.

At the moment I have something like that:

Code: [Select]
#include <Servo.h>

class Sweeper
{
  Servo myservo;
  int pos = 0;
  int increment;
  int updateInterval;              // interval between updates
  unsigned long lastUpdate;           // last update of position
 
public:
  Sweeper (int Interval)
  {
    updateInterval =Interval;
    increment = 1;
  }
void Attach (int pin)
{
  myservo.attach(pin);
}
void Detach (int pin)
{
  myservo.detach();
}
void Update ()
{
  if ((millis() - lastUpdate) > updateInterval)
  {
    lastUpdate = millis();
    pos += increment;
    myservo.write(pos);
    if ((pos >= 180) || (pos <= 0))
    {
      increment = -increment;
    }
   }
  }
 };
Sweeper sweeper1(15);
Sweeper sweeper2(25);


void setup()
{
 
  sweeper1.Attach(9);
  sweeper2.Attach(10);
}

void loop()
{
  sweeper1.Update();
 
  {
    sweeper2.Update();
  }
}
 


Thanks for your helping.

Go Up