Board: "ATtiny25/45/85"
Processor: "ATtiny85"
Clock: "Internal 1 MHz"
Programmer: "Arduino as ISP"
I want to run a servo forwards and backwards on an ATtiny85. The servo library is not compatible with the ATtiny85 so I had to write code from scratch. At this point, the code that makes the servo go forwards (clockwise) is:
void setup() {
pinMode(PB1, OUTPUT);
}
void loop() {
digitalWrite(PB1, HIGH);
delayMicroseconds(1000);
// 1 millisecond determines the servo going forwards
digitalWrite(PB1, LOW);
delay(19);
}
And the code that makes the servo go backwards (anti-clockwise) is simply by changing the amount of microseconds to:
delayMicroseconds(2000);
I want to have the servo motor go forwards one cycle for a few seconds and then go backwards for a few. I want this to keep looping. At this point my code is:
void setup() {
pinMode(PB1, OUTPUT);
}
void loop() {
digitalWrite(PB1, HIGH);
delayMicroseconds(1000);
digitalWrite(PB1, LOW);
delay(19);
digitalWrite(PB1, HIGH);
delayMicroseconds(2000);
digitalWrite(PB1, LOW);
delay(19);
}
This however just makes the servo go back and forward at the same spot forever. I do realise I might need a for loop for this but I am confused as how I will do this.