Hi misterbisson,
You are not using properly the <SoftRcPulseOut> library.
As reminded by Bluebie, most of the libraries for servo designed for ATtiny require to be refreshed periodically in the main loop (typically every 20 ms).
Thus, during your delay(2000) calls, the servo is not refreshed and can not reach the target angle: it is slow and shaky.
In <SoftRcPulseOut>, refresh() refreshes internally the servo pulse every 20 ms: you shall invoke it during long temporization and you cannot use delay() which is a blocking function. You shall use millis() instead.
/*
Blink
Turns on an LED on for one second, then off for one second, repeatedly.
This example code is in the public domain.
*/
#include <SoftRcPulseOut.h>
SoftRcPulseOut servo1;
// Pin 13 has an LED connected on most Arduino boards.
// give it a name:
int led = 1;
// the setup routine runs once when you press reset:
void setup() {
// initialize the digital pin as an output.
pinMode(led, OUTPUT);
servo1.attach(0);
servo1.setMaximumPulse(2200);
}
// the loop routine runs over and over again forever:
void loop() {
uint32_t StartMs;
digitalWrite(led, HIGH); // turn the LED on (HIGH is the voltage level)
servo1.write(30);
/* Refresh pos during 2 sec */
StartMs=millis();
while(millis() - StartMs < 2000UL)
{
SoftRcPulseOut::refresh(); //without argument, refresh occurs every 20 ms (internal to the lib)
}
digitalWrite(led, LOW); // turn the LED off by making the voltage LOW
servo1.write(130);
/* Refresh pos during 2 sec */
StartMs=millis();
while(millis() - StartMs < 2000UL)
{
SoftRcPulseOut::refresh(); //without argument, refresh occurs every 20 ms (internal to the lib)
}
}
Instead of millis(), you can also check the return value of refresh(), it returns 1 when the refresh is done. As refresh is performed every 20 ms, you can use a counter to count the 20ms occurences needed to make you delay. This is another improvement of the SoftwareServo library (SoftRcPulseOut lib is highly based on SoftwareServo lib)
/*
Blink
Turns on an LED on for one second, then off for one second, repeatedly.
This example code is in the public domain.
*/
#include <SoftRcPulseOut.h>
SoftRcPulseOut servo1;
#define REFRESH_NB_FOR_DELAY(MsToWait) ((MsToWait)/20UL)
// Pin 13 has an LED connected on most Arduino boards.
// give it a name:
int led = 1;
// the setup routine runs once when you press reset:
void setup() {
// initialize the digital pin as an output.
pinMode(led, OUTPUT);
servo1.attach(0);
servo1.setMaximumPulse(2200);
}
// the loop routine runs over and over again forever:
void loop() {
uint16_t Needed20msRefreshNb;
digitalWrite(led, HIGH); // turn the LED on (HIGH is the voltage level)
servo1.write(30);
/* Refresh pos during 2 sec */
Needed20msRefreshNb=REFRESH_NB_FOR_DELAY(2000UL);
do{
while(!SoftRcPulseOut::refresh()); //without argument, refresh occurs every 20 ms (internal to the lib), returns 1 once refresh performed
Needed20msRefreshNb--;
}while(Needed20msRefreshNb);
digitalWrite(led, LOW); // turn the LED off by making the voltage LOW
servo1.write(130);
/* Refresh pos during 2 sec */
Needed20msRefreshNb=REFRESH_NB_FOR_DELAY(2000UL);
do{
while(!SoftRcPulseOut::refresh()); //without argument, refresh occurs every 20 ms (internal to the lib), returns 1 once refresh performed
Needed20msRefreshNb--;
}while(Needed20msRefreshNb);
}
Both sketches tested OK with my Digispark and a Futaba S3003 servo.