The project is an Arduino controlled led lighting system for rc plane.
I am trying to create an led strip that can be be controlled by an external remote (flysky ai6) in order to give an afterburner effect above 60% throttle, Also included in the code is 0 delay led flashes for strobe and beacon lights.
I have taken the receiver, by monitoring ch3 and getting the PWM input I am then applying the PWM (through a map()) to send the scaled PWM signal to the led strip.
The problem is after 10s or so of running the program the led strip will flicker very visibly at a low frequency, at any PWM duty cycle(brightness level) I input through the remote. The only solution is to reboot the board.
Is this to do with the code? hardware? (I doubt its to do with the standard led strip flicker due to a 50hz power supply as it only occurs after a period of time has past) code is posted below.
//this is strobe
const char ledPinstrobe = 7;
bool blinkingstrobe = true;
byte blinksstrobe = 0;
//fade beacon
int value = 2;
int ledpin = 6;
long time=0;
int periode = 2000;
//afterburner
int ch1; // create a value to keep the rc values
int valueab = 0;
int previoustime = 0;
int eventinterval = 50;
void setup() {
// put your setup code here, to run once:
pinMode(2,OUTPUT);
pinMode(3,OUTPUT);
pinMode(4,OUTPUT);
pinMode(5,OUTPUT);
pinMode(6,OUTPUT);
pinMode(7,OUTPUT);
pinMode(8,OUTPUT);
digitalWrite(4,HIGH);
digitalWrite(2,HIGH);
digitalWrite(8,HIGH);
//afterburner
pinMode(2,INPUT); // set what mode the pin is in
Serial.begin(9600); // what does this do?
}
void loop() {
//strobe
static unsigned long lastEventstrobe;
unsigned long topLoopstrobe = millis();
if (blinkingstrobe) {
if (topLoopstrobe - lastEventstrobe >= 50) {
lastEventstrobe = topLoopstrobe;
digitalWrite(ledPinstrobe, !digitalRead(ledPinstrobe));//short for "if (digitalRead(ledPin) == HIGH) {
// digitalWrite(ledPin, LOW);
//} else {
// digitalWrite(ledPin, HIGH);
// }
if (++blinksstrobe >= 4) {//if the last event was the top loop-850ms (off) it will blink on(50)-off(50)-on(50)-off(50)
blinkingstrobe = false;
blinksstrobe = 0;
//reset millis()
}
}
} else if (topLoopstrobe - lastEventstrobe >= 800) {//this 800 +4x50 =1000
blinkingstrobe = true;
}
//beacon fade
time = millis();
value = 128+127*cos(2*PI/periode*time);
analogWrite(ledpin, value); // sets the value (range from 0 to 255)
//afterburner
unsigned long currenttime = millis();
ch1 = pulseIn(2, HIGH ,25000); //read the width of each channel
if(currenttime - previoustime >= eventinterval){
Serial.print("Channel 1:"); //tells the board to print the rc input value in the serial viewer
Serial.print(ch1);
if (ch1>=1600){
valueab = ch1;
valueab = map(valueab, 1600,2000,0,255);
analogWrite(5,valueab); //sets pwm value from 0 to 255 //led afterburner
previoustime = currenttime;
}else{
analogWrite(5,0);
previoustime = currenttime;}
}
}
Thank you for any help in advance.
