Elegant Strobe Lights & Performence Impact

So, I would like to add strobe lights controlled by the APM.
I would like to control a led, using PWM to create smooth strobe light.

It is my first go with AP code, and the easiest way was to connect the led to RC5(unused on quad),
and use hal.rcout->write();
However, it MADE EVERYTHONG SLOW and LAGGY. The copter took 20 seconds to arm, wouldn’t dare flying it !
Any Ideas what causes this performence impact? I’m not sure what is taking so many resources.
is there a more “cheap” way of achieving this?

Code looks like this:

`#ifdef USERHOOK_FASTLOOP
void USERHOOK_FASTLOOP()
{
if(pwm==max_pwm || pwm==min_pwm)
{
inc = -inc;
}
if(pwm==min_pwm)
{
hal.scheduler->delay(1500);
}

pwm += inc;
uint8_t _channel=5;
hal.rcout->enable_ch(_channel-1);
hal.rcout->write(_channel-1, pwm);

hal.scheduler->delay(15);
}
#endif`

Depending on what you’re after, you might be better off using a Pixhawk auxiliary channel and radio switches to achieve this. Not sure what you want done though.

You mean connecting to rc channel from the remote? (like most do)
Well - it’ll create 2 problems:

#1 - Sacrifice a channel just so i could turn it on. (via telemetry it’s “free”)
#2 - The remote maintain a constant value, rather than the smooth blinking pattern i want.
So unless there’s a way to create a pattern with the remote control, there isn’t a way to acheive this.

a safer approach would be using a seperate MCU for the leds(and mosfets for 5v->12v), and just issue a one-time “ON” / “OFF” from the apm. I Ordered an ATTiny for that purpose.

However, i still would like to find out why my the APM 2.5.2(essentially arduino mega) couldn’t handle it.
Maybe it’s because i do “rcout->enable_ch” over and over in a loop? maybe because “rcout->write()” is a “heavy” function?