Using Actuator to Automate Open/Close of Computer Side Panel

haha if i dont release quickly then it bugs out back and forth and flashing led (from reducing the refresh or w/e you did) but same issue, the throw is limited.

I tried to run the arduino sweep (changed it for trinket) and I’m having an odd problem where it goes all the way left, and wont turn right. Then I manually can push it right (which i normally cant do, it normally doesnt budge, like when off), and repeat.

The connections are fine, but if i jiggle it, it’ll move like 1* over to the left. Keep jiggling, and it’ll move all the way over. It’ll do this even with input pin removed so it must be something to do with getting tiny bits of electricity or something when jiggled.

Maybe [this might help. It’s a servo with a linear actuator arm attached for a ridiculously cheap $8. If you get one, please post here so we know how it works out.](http://dynamic.focalprice.com/YO0367X/WLtoys_V92222_Replacement_Linear_Servo_of_New_Version_for_V922.html?Currency=GBP)

Belial88:
The connections are fine, but if i jiggle it, it’ll move like 1* over to the left. Keep jiggling, and it’ll move all the way over. It’ll do this even with input pin removed so it must be something to do with getting tiny bits of electricity or something when jiggled.

Hmmm ... sounds like some servo or connection problem but ...

I guess I’d like to definitively rule out the Trinket & coding. I assume you do not have access to an o-scope ? If you’ve got a spare LED and 100-500 ohm resistor then you could use the Trinket to verify the presence or absence of the “refresh” pulses. Perhaps just a simple envelope detector (1 diode, 1 R, 1 C) and a DVM be even simpler ? I’ll give it some thought.

Here’s the simplest test code I can image. Run this and see if the servo goes to 10 deg and then remains “stiff” (resists you trying to move horn). Try altering the variable servoCMD to 90 and/or 170 deg and repeating the test. The LED should come on and stay on. The switch does nothing in this code.

#include <Adafruit_SoftServo.h> // SoftwareServo (works on non PWM pins)

//declare the constants to be used
#define LEDPIN 1            //pin attached to led
#define servoPIN 2          //Servo control line (orange) on Trinket Pin #2


#define SRVOdelay 20        //loop time in ms 

Adafruit_SoftServo myServo; //create a servo object

byte servoCMD = 10;         //change this value for other servo commands

void setup() {

  //set the pins to be ins or outs
  pinMode(LEDPIN, OUTPUT);
  digitalWrite(LEDPIN, LOW);  //turn LED off
  pinMode(servoPIN, OUTPUT);

  //CMD the servo to move
  myServo.attach(servoPIN);   // Attach the servo on Trinket
  myServo.write(servoCMD);    // Tell servo to go to position
  delay(SRVOdelay);           // Wait 20 ms for the next servo cmd
}

void loop() {
  myServo.refresh();         //resend the servo pulse
  if(myServo.attached()){    //verify servo is still attached
    digitalWrite(LEDPIN, HIGH);
  } else {
    digitalWrite(LEDPIN, LOW);
  }
  // now wait 20 msec
  delay(SRVOdelay);           //wait 20 ms
}

I guess I’d like to definitively rule out the Trinket & coding. I assume you do not have access to an o-scope ? If you’ve got a spare LED and 100-500 ohm resistor then you could use the Trinket to verify the presence or absence of the “refresh” pulses. Perhaps just a simple envelope detector (1 diode, 1 R, 1 C) and a DVM be even simpler ? I’ll give it some thought.

I do not know what an o-scope is. I have spare LEDs, a bunch of just 3 and 5mm case LEDs, lots of 3528 stripping, etc. I have a DMM = digital multimeter, if that’s what you mean.

Here’s the simplest test code I can image. Run this and see if the servo goes to 10 deg and then remains “stiff” (resists you trying to move horn). Try altering the variable servoCMD to 90 and/or 170 deg and repeating the test. The LED should come on and stay on. The switch does nothing in this code.

I can hear it buzz. Funny, when the servo is off it’s just locked and I cna’t move it. But this mod, I can hear the engine when I push it and it’s resisting, rather than locking.

Anyways, at 10 it’s like at X*, and then at 170 it’s at -20*. The most movement I can get is ~20* of movement with this. LED stays on.

It sounds like the servo command pulses are being sent by the Trinket. It sounds like the pulsewidth (PW) is changing w/the change in commanded angle. You’re just not getting the 160 deg change being commanded. The question now is whether the PW and frequency are correct. It’s hard to image how they could be wrong unless the Trinket’s clock/timing is wrong. We can do a gross check of that using the onboard LED.

Where is the servo’s 5v power coming from ? A weak power supply can starve a servo of current (especially a high torque model) and cause odd crap. Bad connections can do the same. What servo are you using ?

I am leaning (barely) towards a bad servo …

o-scope is shorthand for [oscilloscope, a tool used to capture and display waveforms.](Oscilloscope - Wikipedia)

Here’s a simple sketch that turns the onboard LED on for 5 secs, off for 5 secs and repeats over and over. Time the LED w/your watch. If your timing measurements agree give or take 0.5 secs, the Trinket’s clock is OK. The problem must then be the servo or the power supply.

//declare the constants to be used
#define LEDPIN 1            //pin attached to led

void setup() {
  //set the pins to be ins or outs
  pinMode(LEDPIN, OUTPUT);
  digitalWrite(LEDPIN, LOW);  //turn LED off
}

void loop() {
  digitalWrite(LEDPIN, HIGH);
  delay(1000);           //wait 1 sec
  delay(1000);           //wait 1 sec
  delay(1000);           //wait 1 sec
  delay(1000);           //wait 1 sec
  delay(1000);           //wait 1 sec
  digitalWrite(LEDPIN, LOW);
  delay(1000);           //wait 1 sec
  delay(1000);           //wait 1 sec
  delay(1000);           //wait 1 sec
  delay(1000);           //wait 1 sec
  delay(1000);           //wait 1 sec
}

ps - You might try the prior servo test code w/commands of 70, 90 and 110 and see what happens … if the above test shows the timing to be OK.

^ Yea, led blinks about twice a second.

Anyways, I got another servo and it works with the button. However.

  1. Sweep doesn’t work with it, it just moves all the way clockwise and then buzzes. it’s almost as if it’s trying to keep going before hitting the bounce point but cant, but I’ve changed the 180s in the code to like 150 and nothing changes.

  2. I’d like to slow it down (the momentary push code). It opens/closes too quickly.

Here’s a simple sketch that turns the onboard LED on for 5 secs, off for 5 secs and repeats over and over.

That's 1 blink every 10 secs.

Belial88:
^ Yea, led blinks about twice a second.

I think you need to double check those results and then call Adafruit about getting a new Trinket.

Belial88:
I’d like to slow it down (the momentary push code). It opens/closes too quickly.

How long do you want the opening to take ? You could divide the difference in positions (deg), from open to close, and come up with a incrementing command vs time (perhaps a new position command every 200 msec ?) to open/close the door. Somewhat similar to the sweep.

Here’s code to do the above (I hope). It should take about 5 secs to move the servo from open to closed (or the opposite). That’s assuming the new servo is working. Of course you can alter the servo positions and door timing as needed.

#include <Adafruit_SoftServo.h> // SoftwareServo (works on non PWM pins)

//declare the constants to be used
#define LEDPIN 1            //pin attached to led
#define servoPIN 2          //Servo control line (orange) on Trinket Pin #2
#define SWitchPIN 3         //input from N.O. momentary switch

#define posOpenCMD 170      //command in deg to servo to open the door
#define posCloseCMD 10      //command in deg to servo to close the door
#define DBdelay 100         //delay in ms btw readings of the switch
#define doorTime 5000       //time in ms btw opening and closing of door
#define MAXcnt 3            //need this many same consecutive readings of button pressed

//declare the variables used
boolean doorOPEN = false;   //desired door state set to closed
boolean SWstate = true;     //state of switch, open = TRUE = not pushed
byte SWcnt = 0;             //counter of same consecutive switch readings w/button = pressed
int STEPcnt = 0;            //counter for stepping door command from open - closed
int STEPsize = 0;           //size of step for door command
int posCMD = 0;             //servo position command in deg

Adafruit_SoftServo myServo; //create a servo object

void setup() {
  // Set up the interrupt that will refresh the servo for us automagically
  OCR0A = 0xAF;               // any number is OK
  TIMSK |= _BV(OCIE0A);     // Turn on the compare interrupt (below!)

  //set the pins to be ins or outs
  pinMode(LEDPIN, OUTPUT);
  digitalWrite(LEDPIN, LOW);  //turn LED off
  pinMode(servoPIN, OUTPUT);
  pinMode(SWitchPIN, INPUT_PULLUP);
  myServo.attach(servoPIN);   // Attach the servo on Trinket
  
  //compute the step size used by the servo to open/close the door
  STEPsize = max(1,(posOpenCMD - posCloseCMD)/(doorTime/DBdelay));
}

void loop() {
  //read the switch
  if(digitalRead(SWitchPIN) == LOW){   //see if switch is being pushed
    SWcnt ++;                //SW reads low = pushed, increment debounce counter
    if(SWcnt >= MAXcnt){     //test if switch is really being pushed AND done bouncing
      SWcnt = 0;             //done bouncing, reset counter for next push
      doorOPEN = !doorOPEN;  //reverse desired door state
      STEPcnt = 0;           //zero out position step counter
    }
  } 
  else {
    SWcnt = 0;              //switch is released or bouncing
  }
  //now compute servo command based on desired door state
  if(doorOPEN == true){
    digitalWrite(LEDPIN, HIGH);      //turn LED on
    posCMD = max(0,(posCloseCMD + STEPcnt*STEPsize));   //compute position, prevent rollover
    posCMD = min(posOpenCMD, posCMD); //limit max command to door open value
    myServo.write(posCMD);       //tell servo to go to open position, step by step
  } 
  else {
    digitalWrite(LEDPIN, LOW);       //turn LED off
    posCMD = max(0,(posOpenCMD - STEPcnt*STEPsize));   //compute position, prevent rollunder
    posCMD = max(posCloseCMD, posCMD); //limit min command to door closed value
    myServo.write(posCMD);      //tell servo to go to closed position, step by step
  }
  STEPcnt = min(10000, STEPcnt++);   //increment step count but prevent rollover
  delay(DBdelay);           //wait for next read of switch
}

// We'll take advantage of the built in millis() timer that goes off
// to keep track of time, and refresh the servo every 20 milliseconds
// The SIGNAL(TIMER0_COMPA_vect) function is the interrupt that will be
// Called by the microcontroller every 2 milliseconds
volatile uint8_t counter = 0;
SIGNAL(TIMER0_COMPA_vect) {
  // this gets called every 2 milliseconds
  counter += 2;
  // every 20 milliseconds, refresh the servos!
  if (counter >= 20) {
    counter = 0;
    myServo.refresh();
  }
}

Nice! However, if I press the button during an open/close, it acts oddly. So if I go to open, it’ll stutter over, and if I hit the button again, it’ll quickly complete the motion like before, but then it thinks it needs to go to close. So I need to either program a way to not interrupt an open/close process, or if the button is hit again, it’ll move the opposite direction at a slow pace. I think the latter is ‘better’.

I figured out where in the code to change how fast/slow it is, that was cool.

My 2nd servo, unfortunately, is wacked out at the moment too though. I think the pot is messed up or something, because when it’s plugged in, it just wigs out and screams/clicks at the end of a cycle. So… guess I gotta get another cycle.

I think I’ll take the code you gave me, and go to a local hobby shop and ask to mess with their servos before buying or something.

You’re really awesome man, thanks a lot. If you need any help picking out computer components or overclocking, let me know, because I know more than most people on that.

Also, could I run the trinket off an internal USB header, and battery pack? I dont know if I’d have to wire the servo ~5v line to both usb and battery at same time, or just battery and it’ll know to go usb when it’s on, assuming this could be done. That would be really awesome, that’d be the whole Battery Pack as back-up power solution without having to buy anything! Really, I’d actually run it off the 5VSB line if this was possible (maybe voltage/grnd to 5vsb, and then data lines to internal usb headers!).

myself:

Belial88:
Nice! However, if I press the button during an open/close, it acts oddly. So if I go to open, it’ll stutter over, and if I hit the button again, it’ll quickly complete the motion like before, but then it thinks it needs to go to close. So I need to either program a way to not interrupt an open/close process, or if the button is hit again, it’ll move the opposite direction at a slow pace. I think the latter is ‘better’.

I suspect that's because the code ASSumes the door is fully opened or closed in the incremental position calculations. Hmmm, I have a fix in mind as I type this.
And here is that fix. It should stop and reverse motion from that point, at the same speed, for a button push while in motion.
#include <Adafruit_SoftServo.h> // SoftwareServo (works on non PWM pins)

//declare the constants to be used
#define LEDPIN 1            //pin attached to led
#define servoPIN 2          //Servo control line (orange) on Trinket Pin #2
#define SWitchPIN 3         //input from N.O. momentary switch

#define posOpenCMD 170      //command in deg to servo to open the door
#define posCloseCMD 10      //command in deg to servo to close the door
#define DBdelay 100         //delay in ms btw readings of the switch
#define doorTime 5000       //time in ms btw opening and closing of door
#define MAXcnt 3            //need this many same consecutive readings of button pressed

//declare the variables used
boolean doorOPEN = false;   //desired door state set to closed
boolean SWstate = true;     //state of switch, open = TRUE = not pushed
byte SWcnt = 0;             //counter of same consecutive switch readings w/button = pressed
int STEPcnt = 0;            //counter for stepping door command from open - closed
int STEPsize = 0;           //size of step for door command
int posCMD = posCloseCMD;   //servo position command in deg

Adafruit_SoftServo myServo; //create a servo object

void setup() {
  // Set up the interrupt that will refresh the servo for us automagically
  OCR0A = 0xAF;               // any number is OK
  TIMSK |= _BV(OCIE0A);     // Turn on the compare interrupt (below!)

  //set the pins to be ins or outs
  pinMode(LEDPIN, OUTPUT);
  digitalWrite(LEDPIN, LOW);  //turn LED off
  pinMode(servoPIN, OUTPUT);
  pinMode(SWitchPIN, INPUT_PULLUP);
  myServo.attach(servoPIN);   // Attach the servo on Trinket

  //compute the step size used by the servo to open/close the door
  STEPsize = max(1,(posOpenCMD - posCloseCMD)/(doorTime/DBdelay));
}

void loop() {
  //read the switch
  if(digitalRead(SWitchPIN) == LOW){   //see if switch is being pushed
    SWcnt ++;                //SW reads low = pushed, increment debounce counter
    if(SWcnt >= MAXcnt){     //test if switch is really being pushed AND done bouncing
      SWcnt = 0;             //done bouncing, reset counter for next push
      doorOPEN = !doorOPEN;  //reverse desired door state
      STEPcnt = 0;           //zero out position step counter
    }
  }
  else {
    SWcnt = 0;              //switch is released or bouncing
  }
  //now compute servo command based on desired door state
  if(doorOPEN == true){
    digitalWrite(LEDPIN, HIGH);      //turn LED on
    posCMD = max(posCloseCMD,(posCMD + STEPcnt*STEPsize));   //compute position, prevent rollover
    posCMD = min(posOpenCMD, posCMD); //limit max command to door open value
    myServo.write(posCMD);       //tell servo to go to open position, step by step
  }
  else {
    digitalWrite(LEDPIN, LOW);       //turn LED off
    posCMD = min(posOpenCMD,(posCMD - STEPcnt*STEPsize));   //compute position, prevent rollunder
    posCMD = max(posCloseCMD, posCMD); //limit min command to door closed value
    myServo.write(posCMD);      //tell servo to go to closed position, step by step
  }
  STEPcnt = min(10000, STEPcnt++);   //increment step count but prevent rollover
  delay(DBdelay);           //wait for next read of switch
}

// We'll take advantage of the built in millis() timer that goes off
// to keep track of time, and refresh the servo every 20 milliseconds
// The SIGNAL(TIMER0_COMPA_vect) function is the interrupt that will be
// Called by the microcontroller every 2 milliseconds
volatile uint8_t counter = 0;
SIGNAL(TIMER0_COMPA_vect) {
  // this gets called every 2 milliseconds
  counter += 2;
  // every 20 milliseconds, refresh the servos!
  if (counter >= 20) {
    counter = 0;
    myServo.refresh();
  }
}

FYI if you have to install the servo “upside down”, so that the max servo command means door closed instead of open (as assumed by the code) … just reverse the initialization of the doorOPEN variable from

//declare the variables used
boolean doorOPEN = false;

to

//declare the variables used
boolean doorOPEN = true;

so that the door actually closes upon power up or Trinket reset.

BTW have given any thought to a safety mechanism to be able to open the door in case of servo failure ?

I went and bought an hs65hb, more motion again, yay!

I think I need some sort of servo mount. Or I guess I’ll just glue or tape it down ;/

As for a safety mechanism to open the door in case of servo failure, I haven’t thought of it. I have no idea what to do in that event. It would be pretty easy to just brute it open though.

I can only get about 120* of motion from the servo (as 0 to 250 in code). Which is great, but it says I can get 180:

http://www.servocity.com/html/hs-65hb_m … ather.html

This servo can operate 180° when given a pulse signal ranging from 600usec to 2400usec. Since most R/C controllers cannot generate this wide of signal range, you will need to use our servo stretcher for 180° operation.

I mean I can manually turn it 180 easily. I feel like this page is relevant http://playground.arduino.cc/ComponentLib/Servo

ie SetMinimumPulse but everywhere and how I put it, doesn’t work.

Finally, 2 questions:

  1. Is there a way to make it in the code so that, instead of when you hold the switch (or when the trinket thinks you are holding it) that the states constnatly change back and forth, it will only do one action per press-unpress? So if i push it, it opens/coses, and no matter how long my finger is on it or the refresh is set, it won’t do the opposite suddenly?

  2. Would my battery pack be a UPS of sorts, if I hooked up the trinket to the internal USB header on my mobo? How exactly would the battery wiring go if I did that? Or is the trinket too stupid to know to only use the battery pack when no usb power?

myself:

Belial88:

  1. Is there a way to make it in the code so that, instead of when you hold the switch (or when the trinket thinks you are holding it) that the states constnatly change back and forth, it will only do one action per press-unpress? So if i push it, it opens/coses, and no matter how long my finger is on it or the refresh is set, it won’t do the opposite suddenly?
Yes there can be. Simple matter of inhibiting another button read until the door motion has completed it's prior command. Think about it and give it a try. :wink:
No peeking until you've tried to fix it yourself. Again I can't check this ahead of time since I don't have a Trinket.
#include <Adafruit_SoftServo.h> // SoftwareServo (works on non PWM pins)

//declare the constants to be used
#define LEDPIN 1            //pin attached to led
#define servoPIN 2          //Servo control line (orange) on Trinket Pin #2
#define SWitchPIN 3         //input from N.O. momentary switch

#define posOpenCMD 170      //command in deg to servo to open the door
#define posCloseCMD 10      //command in deg to servo to close the door
#define DBdelay 100         //delay in ms btw readings of the switch
#define doorTime 5000       //time in ms btw opening and closing of door
#define MAXcnt 3            //need this many same consecutive readings of button pressed

//declare the variables used
boolean inMotion = false;   //door is moving, or not
boolean doorOPEN = false;   //desired door state set to closed
boolean SWstate = true;     //state of switch, open = TRUE = not pushed
byte SWcnt = 0;             //counter of same consecutive switch readings w/button = pressed
int STEPcnt = 0;            //counter for stepping door command from open - closed
int STEPsize = 0;           //size of step for door command
int posCMD = posCloseCMD;   //servo position command in deg

Adafruit_SoftServo myServo; //create a servo object

void setup() {
  // Set up the interrupt that will refresh the servo for us automagically
  OCR0A = 0xAF;               // any number is OK
  TIMSK |= _BV(OCIE0A);     // Turn on the compare interrupt (below!)

  //set the pins to be ins or outs
  pinMode(LEDPIN, OUTPUT);
  digitalWrite(LEDPIN, LOW);  //turn LED off
  pinMode(servoPIN, OUTPUT);
  pinMode(SWitchPIN, INPUT_PULLUP);
  myServo.attach(servoPIN);   // Attach the servo on Trinket

  //compute the step size used by the servo to open/close the door
  STEPsize = max(1,(posOpenCMD - posCloseCMD)/(doorTime/DBdelay));
}

void loop() {
  //read the switch if the door is not moving
  if(digitalRead(SWitchPIN) == LOW && !inMotion){   //see if switch is being pushed
    SWcnt ++;                //SW reads low = pushed, increment debounce counter
    if(SWcnt >= MAXcnt){     //test if switch is really being pushed AND done bouncing
      SWcnt = 0;             //done bouncing, reset counter for next push
      doorOPEN = !doorOPEN;  //reverse desired door state
      inMotion = true;       //set door in motion flag
      STEPcnt = 0;           //zero out position step counter
    }
  }
  else {
    SWcnt = 0;              //switch is released or bouncing
  }
  //now compute servo command based on desired door state
  if(doorOPEN == true){
    digitalWrite(LEDPIN, HIGH);       //turn LED on
    posCMD = max(posCloseCMD,(posCMD + STEPcnt*STEPsize));   //compute position, prevent rollover
    posCMD = min(posOpenCMD, posCMD); //limit max command to door open value
    myServo.write(posCMD);            //tell servo to go to open position, step by step
    if(posOpenCMD - posCMD < 2){      //close enough to done
      inMotion = false;               //reset door in motion flag
    }
  }
  else {
    digitalWrite(LEDPIN, LOW);         //turn LED off
    posCMD = min(posOpenCMD,(posCMD - STEPcnt*STEPsize));   //compute position, prevent rollunder
    posCMD = max(posCloseCMD, posCMD); //limit min command to door closed value
    myServo.write(posCMD);             //tell servo to go to closed position, step by step
    if(posCMD - posCloseCMD < 2){      //close enough to done
      inMotion = false;                //reset door in motion flag
    }
  }
  STEPcnt = min(10000, STEPcnt++);   //increment step count but prevent rollover
  delay(DBdelay);           //wait for next read of switch
}

// We'll take advantage of the built in millis() timer that goes off
// to keep track of time, and refresh the servo every 20 milliseconds
// The SIGNAL(TIMER0_COMPA_vect) function is the interrupt that will be
// Called by the microcontroller every 2 milliseconds
volatile uint8_t counter = 0;
SIGNAL(TIMER0_COMPA_vect) {
  // this gets called every 2 milliseconds
  counter += 2;
  // every 20 milliseconds, refresh the servos!
  if (counter >= 20) {
    counter = 0;
    myServo.refresh();
  }
}

You have a file, Adafruit_SoftServo.cpp, on your PC in some library folder. Make a copy of it, change the name too so as to save the original code. Now modify the Adafruit_SoftServo.cpp as shown below.

Original code :

// This is an ultra simple software servo driver. For best
// results, use with a timer0 interrupt to refresh() all
// your servos once every 20 milliseconds!
// Written by Limor Fried for Adafruit Industries, BSD license

#if ARDUINO >= 100
 #include "Arduino.h"
#else
 #include "WProgram.h"
#endif
 
#include "Adafruit_SoftServo.h"

Adafruit_SoftServo::Adafruit_SoftServo(void) {
  isAttached = false;
  servoPin = 255;
  angle = 90;
}

void Adafruit_SoftServo::attach(uint8_t pin) {
  servoPin = pin;
  angle = 90;
  isAttached = true;
  pinMode(servoPin, OUTPUT);
}

void Adafruit_SoftServo::detach(void) {
  isAttached = false;
  pinMode(servoPin, INPUT);
}

boolean  Adafruit_SoftServo::attached(void) {
  return isAttached;
}

void Adafruit_SoftServo::write(uint8_t a) {
  angle = a;

  if (! isAttached) return;
  micros = map(a, 0, 180, 600, 2400);  
}

void Adafruit_SoftServo::refresh(void) {
  digitalWrite(servoPin, HIGH);
  delayMicroseconds(micros);
  digitalWrite(servoPin, LOW);
}

Mod’ed code for more servo travel

// This is an ultra simple software servo driver. For best
// results, use with a timer0 interrupt to refresh() all
// your servos once every 20 milliseconds!
// Written by Limor Fried for Adafruit Industries, BSD license

#if ARDUINO >= 100
 #include "Arduino.h"
#else
 #include "WProgram.h"
#endif
 
#include "Adafruit_SoftServo.h"

Adafruit_SoftServo::Adafruit_SoftServo(void) {
  isAttached = false;
  servoPin = 255;
  angle = 90;
}

void Adafruit_SoftServo::attach(uint8_t pin) {
  servoPin = pin;
  angle = 90;
  isAttached = true;
  pinMode(servoPin, OUTPUT);
}

void Adafruit_SoftServo::detach(void) {
  isAttached = false;
  pinMode(servoPin, INPUT);
}

boolean  Adafruit_SoftServo::attached(void) {
  return isAttached;
}

void Adafruit_SoftServo::write(uint8_t a) {
  angle = a;

  if (! isAttached) return;
  micros = map(a, 0, 180, 600, 2400);  
}

void Adafruit_SoftServo::refresh(void) {
  digitalWrite(servoPin, HIGH);
  delayMicroseconds(micros);
  digitalWrite(servoPin, LOW);
}

What’s changed was 1 function that was;

micros = map(a, 0, 180, 1000, 2000)

it’s now;

micros = map(a, 0, 180, 600, 2400)

You should be able to grok why. Not even 10 minutes.

Time for a beer.

Belial88:
2. Would my battery pack be a UPS of sorts, if I hooked up the trinket to the internal USB header on my mobo? How exactly would the battery wiring go if I did that? Or is the trinket too stupid to know to only use the battery pack when no usb power?

Hmmm I thought I was quoting my earlier reply above but I ended up editting it instead and losing this part. So here it is again.

If you’re using 4 AA NiMH batteries then there maybe an IC that ties a 5v source, the batteries and Trinket all together in a smart ‘UPS-like’ manner. I know they exist for LiPo batteries. Otherwise I’m unsure what’s the proper way to recharge NiMH batteries. Just connecting everything together at 5v may not be wise.

No peeking until you’ve tried to fix it yourself. Again I can’t check this ahead of time since I don’t have a Trinket.

I haven’t. Give me a hint so I can try to work this myself.

Belial88:

No peeking until you’ve tried to fix it yourself. Again I can’t check this ahead of time since I don’t have a Trinket.

I haven't. Give me a hint so I can try to work this myself.
To be accurate my latest code didn't detect the press and subsequent unpress. Instead when a press is detected a 'flag' (a single bit variable) is set. When this flag is set, the switch is not read. When the door gets to it's destination, the flag is reset.

If you wanted to you could apply the same technique to the press/unpress. Now, instead of inhibiting the reading of the switch, the flag would stop any action (after the first action/door position) based on the press. Then, only after a good unpress, would the flag be reset. You would need to extend the switch debounce logic to debounce the unpress.

Ah, I got the towerpro working right by messing with that .cpp too! 0,180,500,2400 (so 0 and 180 is placeholders of some kind to tell arduino that Min = X, Max = Y, and therefore 90* is half that, etc, and then next two numbers are min and max pulse definitions).

So thanks! You not only figured out a lot of this code, which I’ve learned a lot of, but made me go from 3 broken servos to 3 working ones lol. You can have one if you’d like. I’m not sure which I’ll go with - towerpro is rated higher but I’d imagine the hitec actually is stronger.

I’ll probably mount these guys in my pc via bolts through the mounting holes, just get some thin bolts from ace hardware, paint them black, drill appropriate holes. I’ll need to do some testing for optimal placement but the hard part is done!

However, I still am unable to figure out your code. Trying to google-fu button inhibition.