Important changes to forums and questions
All forums and questions are now archived. To start a new conversation or read the latest updates go to forums.mbed.com.
10 years, 10 months ago.
Help with staggering off time LEDs with pwm on KL46Z
Hello,
I'm not too good when it comes to programming. What I'm trying to use the 2 on-board LEDs to turn off completely at staggered times. Right now both LEDS come on fade out at the same time and completely turn off at the same time. No matter what I try I cannot get them to stagger, I've tried separate for loops, embedded for loops and delays. Either they never turn off or the just blink for a lack of a better word.
Here is the code that I have now that works:
#include "mbed.h" #define ON 0 #define OFF 1 DigitalOut redled(LED_RED); DigitalOut greenled(LED_GREEN); DigitalIn sw3(PTC12); //DigitalIn sw1(PTC3); PwmOut r(LED_RED); PwmOut g(LED_GREEN); int main() { r = 1; g = 1; greenled = OFF; //green and red led are off redled = OFF; while(1) { // if (sw3 == 1) { // greenled = OFF; //green led is off // redled = OFF; // red led is on //} if (sw3== 0) { r.period(0.001); g.period(0.001); greenled = ON; redled = ON; for (float i = 0.0; i < 3.0 ; i += 0.001) { //i is duty cycle changes length of fade out float p = 3 * i; //r = 1.0 - ((p < 1.0) ? 1.0 - p : (p > 2.0) ? p - 2.0 : 0.0); r = 1.0 - ((p < 1.0) ? p : (p > 2.0) ? 0.0 : 2.0 - p); //this dims led off after button press but not completely off. wait (0.0025); g = 1.0 - ((p < 1.0) ? p : (p > 2.0) ? 0.0 : 2.0 - p); wait (0.0025); }//end of for loop } else{ r = 1; g = 1;} } }
I appreciate any help or clues to help me along.
Thanks,
Donato
1 Answer
10 years, 10 months ago.
Simple Donato,
To my limited knowledge, the K64F LEDs are not pwm_able, as they are not connected to a PWM pin. On-off mode only
...kevin
can you edit your question and use "
posted by Martin Kojtal 07 May 2014<<code>>" and "<</code>>
" for code snippets..I think I have it right
posted by Donato Evangelista 07 May 2014