Neues Problem:
Erstmal der aktuelle Code:
// 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 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
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 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:
if (ledState == LOW)
ledState = HIGH;
else
ledState = LOW;
// set the LED with the ledState of the variable:
digitalWrite(led1, ledState);
digitalWrite(led2, ledState);
if (interval == 59)
interval = 100;
else if (interval == 100)
interval = 61;
else if (interval == 61)
interval = 800;
else
interval = 59;
}
}
void flashlight()
{
analogFade();
frontflash();
}
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()
{
Serial.begin(9600); //serial library start
pinMode(PPMin1, INPUT); //Pin 2 as input
pinMode(led1, OUTPUT);
pinMode(led2, OUTPUT);
}
void loop()
{
RCpuls1 = pulseIn(PPMin1, HIGH); //read RC channel 1
adj_puls1 = map(RCpuls1, 1000, 2000, 2000, 1000); // 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
Serial.print ("puls1: ");
Serial.print (RCpuls1); // if you turn on your serial monitor you can see the readings.
Serial.print (" ");
Serial.print ("adjusted: ");
Serial.print (adj_puls1);
Serial.println (" ");
}
vorlage für das ganze ist dies hier: Arduino RC car - adafruit industries
So, Probleme:
- Wozu brauch man 4 stellen bei map? die ersten beiden sind die range, also von bis und die beiden dahinter?
- es funktioniert soweit recht gut, aber das analogfade und das frontflash wird vieeel zu langsam ausgeführt. wieso? und wie kann ich das lösen?