This tutorial is a very simple conversion from ATMEGA328P to ATTiny85, there is only one pin involved in producing output, so we only need to change from pin 11 to pin 0. On the ATTiny85, there are three hardware PWM pins … pin 0, pin 1 and pin2 , so it’s simply a matter of switching over to Pin 0 and away we go.
I’ve changed the sketch for personal taste (and I think, efficiency), you’re free to use the Freetronics version of the code if you like … it’s no great shakes on something this small.
/* project 5: Controlling LED brightness with PWM */
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--;
}
}
As you will see from the following image, there isn’t much to the wiring for this project.
And here’s the circuit running through it’s light/dim wizardry.
Once again, I’m using my ATTiny85 ICSP to program the ATTiny85 using the Arduino UNO and my 9V to 5V power regulator to supply 5V to the circuit.
Check out the rest of the tutorials here.
No comments:
Post a Comment