NEUES PROBLEM WEITER UNTEN!
Hallöschen
Gleich am Anfang:
Ich bin Arduino Neuling, also wird mein Code alles andere als perfekt sein
Mein vorhaben:
Ich will 2 LEDs faden und gleichzeitig 2 LEDs als Doppelblitzer haben.
Da ein Delay ja den ganzen code sozusagen zerstört, hab ich mit Hilfe der tuts und google diesen Code geschrieben, um die LED erstmal blitzen zu lassen (das Doppeln wollte ich später einfügen, wenn das Blitzen funktioniert):
// constants won't change. Used here to
// set pin numbers:
const int ledPin1 = 3; // the number of the LED pin
const int ledPin2 = 5; // the number of the LED pin
// Variables will change:
int ledState = LOW; // ledState used to set the LED
long previousMillis = 0; // will store last time LED was updated
// the follow variables is a long because the time, measured in miliseconds,
// will quickly become a bigger number than can be stored in an int.
int interval = 0; // interval at which to blink (milliseconds)
#define led1 3
#define led2 5
#define fled1 10 //Led on digital pin 10
#define fled2 11 //Led on digital pin 10
unsigned long btnMillis = 0; //clock value to be stored at the time milli() is called
//Fade a led without delaying the rest of the code
//START
unsigned long fadeMillis = 0;
boolean fadeUp = true;
int fadeValue = 0;
void analogFade()
{
if (millis() - fadeMillis >= 2)
{
fadeMillis = millis();
if (fadeUp == true)
{
if (fadeValue < 255)
{
fadeValue++;
}
else
{
fadeUp = false;
fadeValue--;
}
}
else
{
if (fadeValue > 0)
{
fadeValue--;
}
else
{
fadeUp = true;
fadeValue++;
}
}
analogWrite(fled1, fadeValue);
analogWrite(fled2, fadeValue);
}
}
//STOP
void setup()
{
pinMode(led1, OUTPUT);
pinMode(led2, OUTPUT);
// set the digital pin as output:
pinMode(ledPin1, OUTPUT);
pinMode(ledPin2, OUTPUT);
}
void loop()
{
analogFade();
unsigned long currentMillis = millis();
if(currentMillis - previousMillis > interval) {
// save the last time you blinked the LED
previousMillis = currentMillis;
// if the LED is off turn it on and vice-versa:
if (ledState == LOW)
ledState = HIGH;
else
ledState = LOW;
// set the LED with the ledState of the variable:
digitalWrite(ledPin1, ledState);
digitalWrite(ledPin2, ledState);
if (interval == 100)
interval = 800;
else
interval = 100;
}
}
Das Problem:
er ändert zwar die variable "interval" in 800, aber nicht zurück.
Ich hätte aber gerne folgendes:
LED an
100ms warten
LED aus
800ms warten
...und wieder von vorne
Wie mach ich das?
Danke im voraus.
Gruß,
Daniel