The Freetronics Tutorial 6 replaces the LED and Resistor connection on pin 11 of the Freetronics 11 with the data connection to a simple servo.
The ATTiny85 version does the same thing … not really much sense reinventing the wheel, huh?
As we learn with Tutorial 7, there are three PWM pins on the ATTiny85 to choose from. I went with the easiest and most convenient … our old friend, pin 0.
If you use the sketch from Tutorial 5 in the Freetronics Tutorial with a servo instead of an LED, then this sketch works admirably.
// Tutorial 6: Making things move with servos
int led = 0;
int brightness = 0;
int delayTime = 10;
void setup()
{
pinMode(led, OUTPUT);
}
void loop()
{
while(brightness < 255)
{
analogWrite(led, brightness);
delay(delayTime);
brightness++;
}
while(brightness > 0)
{
analogWrite(led, brightness);
delay(delayTime);
brightness--;
}
}
Of course, I’m using the ++ and – incrementing function rather than brightness = brightness + 1; and brightness = brightness –1; because I think that it looks better, but that’s just me. Let the spirit guide you in your decision …
The green jumper connects from ATTiny85 pin 0 to the yellow connector on the servo, Red connects to Orange on the Servo from the 5V rail and the black jumper connects the brown servo connection to GND.
Here’s a short video of the action.
Check out the rest of the tutorials here.
No comments:
Post a Comment