FantomXR Posted November 8, 2018 Report Share Posted November 8, 2018 Hey people, I don't have a question but I want to share this code. I searched for a way to get a blinking LED within NG. Here is what it looks like: EVENT_BUTTON id=1 type=meta meta=runsection:2 button_mode=Toggle EVENT_LED id=1 dimmed=1 EVENT_LED id=2000 And this is the NGR-part: if ^section == 2 if BUTTON:1 == 127 set LED:2000 127 endif if BUTTON:1 == 0 set LED:2000 0 endif if LED:2000 == 127 set LED:1 64 delay_ms 150 set LED:1 20 delay_ms 150 exec_meta RunSection:2 endif if LED:2000 == 0 set LED:1 20 endif endif What it does is: It checks the status of the button 1. Please note that the button is set to "toggle"-mode. If it's 127, LED:2000 which just acts as a value-storage is set to 127 and if that LED is 127, the loop is started. At the beginning of that loop the button-status is checked and as soon as it's 0, the loop stops. Best, Chris Quote Link to comment Share on other sites More sharing options...
FantomXR Posted November 8, 2018 Author Report Share Posted November 8, 2018 You could also do a "fade": if ^section == 2 if BUTTON:1 == 127 set LED:2000 127 endif if BUTTON:1 == 0 set LED:2000 0 endif if LED:2000 == 127 set LED:1 20 set LED:1 20 delay_ms 20 set LED:1 25 delay_ms 20 set LED:1 30 delay_ms 20 set LED:1 35 delay_ms 20 set LED:1 40 delay_ms 20 set LED:1 45 delay_ms 20 set LED:1 50 delay_ms 20 set LED:1 55 delay_ms 20 set LED:1 60 delay_ms 20 set LED:1 64 delay_ms 20 set LED:1 60 delay_ms 20 set LED:1 55 delay_ms 20 set LED:1 50 delay_ms 20 set LED:1 45 delay_ms 20 set LED:1 40 delay_ms 20 set LED:1 35 delay_ms 20 set LED:1 30 delay_ms 20 set LED:1 25 delay_ms 20 set LED:1 20 delay_ms 20 exec_meta RunSection:2 endif if LED:2000 == 0 set LED:1 20 endif endif Quote Link to comment Share on other sites More sharing options...
Zam Posted November 8, 2018 Report Share Posted November 8, 2018 Hello Chris That's a nice way to have blinking LED, I use this kind of strategy in my NG The drawback is that you can't run another script and keep the blinking. I start a topic/request long time ago to have a blinking mode at lower code level in mios, like a dynamic dimmed= mode Hopefully one day Best Zam Quote Link to comment Share on other sites More sharing options...
FantomXR Posted November 8, 2018 Author Report Share Posted November 8, 2018 Hm, good point! I tried to implement such thing via RTOS... but this seems to be above my skills. Quote Link to comment Share on other sites More sharing options...
Antichambre Posted November 9, 2018 Report Share Posted November 9, 2018 If you need help writing a new RTOS task(or something else, there's some others ways to add a non-blocking delay), this is not a problem but in regular code only, and I really don't know how to link it with the NG scripting syntax. But maybe one of you knows? Quote Link to comment Share on other sites More sharing options...
FantomXR Posted November 9, 2018 Author Report Share Posted November 9, 2018 Hm... I know how to create a meta-command. But I don't know how to refer to a timer within a meta-command. Maybe you could explain how to set up a simple timer and I'll see if I can implement that? Thanks, Chris Quote Link to comment Share on other sites More sharing options...
Antichambre Posted November 9, 2018 Report Share Posted November 9, 2018 In your App.c #define RESOLUTION 1000 // in uS #define TIMER_NUM 1 // TIM3 #define TIMER_PRIO MIOS32_IRQ_PRIO_MID static void TIMER_TIck(void); ///////////////////////////////////////////////////////////////////////////// // This hook is called after startup to initialize the application ///////////////////////////////////////////////////////////////////////////// void APP_Init(void) { MIOS32_TIMER_Init(TIMER_NUM, RESOLUTION, TIMER_TIck, TIMER_PRIO); } // This function will be called every ms static void TIMER_TIck(void) { // Your function here } This is MIOS32 ready to use Timer function. 1 Quote Link to comment Share on other sites More sharing options...
Zam Posted November 9, 2018 Report Share Posted November 9, 2018 following with interest... can be merged with this: best Zam Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.