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.
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
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?
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?
#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 }