//Author: mcapurso.Tested on attiny 85 with servo towerpro microservo 90 SG90
// 08/jan/2014 servo data on www.servodatabase.com 25
int servoPin = 0; // servo connected to digital pin 0
// ************** The following pin is NOT really used in WOKWI !!!! *******************
int MOSPWR = 1; //Sends power to MOS gate to turn on servo, add a slight delay
void setup()
{
pinMode(servoPin, OUTPUT); // sets the servoPin to be an output
pinMode(MOSPWR, OUTPUT); //sets the MOSPWR to be an output
/*
servowrite(servoPin, 0, 500, 2400); //changed middle 500 to 2000 to see what happend "it shortens the swing"
servowrite(servoPin, 90, 500, 2400); //for each independantly
servowrite(servoPin, 180, 500, 2400); //changed 2400 to 5000 to see what happens "nothing"
*/
servotest();
}
void loop() // run over and over again
{
}
void servowrite(int pin, int angle, int microzero, int micro180)
{
// pin for servo, angle to move, microseconds for zero degrees, microseconds for 180 degrees
int microvalue = map(angle, 0, 180, microzero, micro180); //map angle to microseconds
int i;
for (i = 0; i < 50; i++) //Send 50 pwm pulses with width microvalue uS . (DELAY BETWEEN SWEEPS GLOBAL/FIXED)
{ //changed 50 to 1000 to see what happens "delays the time between swings"BUT MAKES THE SERVO BUZZ
analogWrite(servoPin, 255); //Pulse high for microvalue uS
delayMicroseconds(microvalue);
analogWrite(servoPin, 0); //Pulse low for 15mS
delay(15);
}
delay(10); //Pause
}
void servotest()
// test servo
{
int i;
for (i = 0; i < 50; i++) //Send 50 pulses with width 500 uS - changed all to 1000 to see what happens
{
analogWrite(servoPin, 255); //Pulse high for 500uS
delayMicroseconds(2000); //changed 500 to 2000 to see what happens "nothing noticable"
// changed 500 to 50 to see what happens "nothing noticable"
analogWrite(servoPin, 0); //Pulse low for 15mS
delay(15);
}
delay(1000);
for (i = 0; i < 50; i++) //Send 50 pulses with width 1.25mS
{
analogWrite(servoPin, 255); // changed 255 to (147) to see what happens "servo FREAKS OUT"
//Pulse high for 1.4 mS
delayMicroseconds(1400);
analogWrite(servoPin, 0);
delay(15);
}
delay(1000);
for (i = 0; i < 50; i++) //Send 50 pulses with width 2.4ms
{
analogWrite(servoPin, 255);
delayMicroseconds(2400);
analogWrite(servoPin, 0);
delay(15);
}
delay(1000);
}