telos dein fade funktioniert bei mir irgendwie überhaupt nicht. :~
Er spuckt aber auch keinen Fehler beim compilieren aus.
aktueller code (den ich vllt mal aufräumen sollte):
// 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)
int brightness = 10; // how bright the LED is
#define led1 3
#define led2 5
#define led3 6
#define led4 9
#define fled1 10 //Led on digital pin 10
#define fled2 11 //Led on digital pin 11
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
const unsigned long fadeTime = 375; //375ms
void analogFade(){
static unsigned long fadeStartMillis = 0;
static boolean fadeUp = true;
if (fadeStartMillis == 0) {
fadeStartMillis = millis(); //der Fade beginnt
} else {
unsigned long actualMillis = millis();
if (fadeStartMillis + fadeTime > actualMillis) {
fadeStartMillis = 0; //der Fade ist fertig, jetzt umkehren und neu anfangen
fadeUp != fadeUp;
} else {
int fadeDuration = actualMillis - fadeStartMillis;
int fadeValue = 0;
if (fadeUp) {
fadeValue = map(fadeDuration, 0, fadeTime, 0, 255);
} else {
fadeValue = map(fadeDuration, fadeTime, 0, 0, 255);
}
analogWrite(fled1, fadeValue);
analogWrite(fled2, fadeValue);
}
}
}
//STOP
void normallight()
{
analogWrite(6, brightness);
analogWrite(9, brightness);
}
void frontflash()
{
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:
ledState = 1-ledState;
// set the LED with the ledState of the variable:
digitalWrite(led1, ledState);
digitalWrite(led2, ledState);
if (interval == 39)
interval = 80;
else if (interval == 80)
interval = 41;
else if (interval == 41)
interval = 780;
else
interval = 39;
}
}
void flashlight()
{
analogFade();
frontflash();
normallight();
}
int PPMin1 = 2; // connect the desired channel (PPM signal) from your RC receiver to analog pin2 on Arduino.
int RCpuls1; // store RC signal pulse length
int adj_puls1;
void setup()
{
pinMode(led1, OUTPUT);
pinMode(led2, OUTPUT);
pinMode(led3, OUTPUT);
pinMode(led4, OUTPUT);
}
void loop()
{
RCpuls1 = pulseIn(PPMin1, HIGH); //read RC channel 1
adj_puls1= 3000-RCpuls1; // my observed RC values are between 1000 and 2000.. these might need to be changed, depending on your RC system.
//light1
if (adj_puls1 > 1700) {
//write here what to do
flashlight();
}
else
flashlight();
}