Mit dieser (einfache) schaltung:
http://moppe.dk/levhusel/Attiny45_w_regulator.png
und dieser programm klappt alles.
/*
Blinking light with fading in and out. Build from the Arduino example "Fading"
Can be used for grade crossings in model railroad.
Variable timing for fade time, time output is full on and time output is off.
Created by Moppe
*/
// Configuration variables
int ledPin1 = 0; // LED connected to digital pin 5
int ledPin2 = 1 ; // LED connected to digital pin 6
int dt = 3; // fading time
int ont = 600; // delay time, one light on
int oft = 200; // delay time, both lights off
void setup() {
// nothing happens in setup
}
void loop()
{
if ((millis()<=(ont+oft))) //Both lights on when powered up
{
// both outputs fade in from min to max in increments of 5 points:
for(int fadeValue = 0 ; fadeValue <= 255; fadeValue +=5) {
// sets the value (range from 0 to 255):
analogWrite(ledPin1, fadeValue);
analogWrite(ledPin2, fadeValue);
// wait for (dt) milliseconds to see the dimming effect
delay(dt);
}
delay(ont);
//Delay for (ont) milliseconds, where the light is on, on the first output
// output 1 fade out from max to min in increments of 5 points:
for(int fadeValue = 255 ; fadeValue >= 0; fadeValue -=5) {
// sets the value (range from 0 to 255):
analogWrite(ledPin1, fadeValue);
analogWrite(ledPin2, fadeValue);
// wait for (dt) milliseconds to see the dimming effect
delay(dt);
}
delay(oft);
//Delay for (oft) milliseconds, where the light is off on both outputs
}
else
{
// output 1 fade in from min to max in increments of 5 points:
for(int fadeValue = 0 ; fadeValue <= 255; fadeValue +=5) {
// sets the value (range from 0 to 255):
analogWrite(ledPin1, fadeValue);
// wait for (dt) milliseconds to see the dimming effect
delay(dt);
}
delay(ont);
//Delay for (ont) milliseconds, where the light is on, on the first output
// output 1 fade out from max to min in increments of 5 points:
for(int fadeValue = 255 ; fadeValue >= 0; fadeValue -=5) {
// sets the value (range from 0 to 255):
analogWrite(ledPin1, fadeValue);
// wait for (dt) milliseconds to see the dimming effect
delay(dt);
}
delay(oft);
//Delay for (oft) milliseconds, where the light is off on both outputs
// output 2 fade in from min to max in increments of 5 points:
for(int fadeValue = 0 ; fadeValue <= 255; fadeValue +=5) {
// sets the value (range from 0 to 255):
analogWrite(ledPin2, fadeValue);
// wait for (dt) milliseconds to see the dimming effect
delay(dt);
}
delay(ont);
//Delay for (ont) milliseconds, where the light is on, on the second output
// output 2 fade out from max to min in increments of 5 points:
for(int fadeValue = 255 ; fadeValue >= 0; fadeValue -=5) {
// sets the value (range from 0 to 255):
analogWrite(ledPin2, fadeValue);
// wait for (dt) milliseconds to see the dimming effect
delay(dt);
}
delay(oft);
//Delay for (oft) milliseconds, where the light is off on both outputs
}
}