diff --git a/README.md b/README.md index 0bd7a07..1d09f05 100644 --- a/README.md +++ b/README.md @@ -129,6 +129,31 @@ put where you want (here example of 2 functions put into queue): ```cpp F5.tick(); // execute for 'ticks' in timer so the queue class instance will know then to initiate execution ``` + + ### Delayed functions with parameters +Do you need just to delay some function from execution? Do not wait any more! +Initialize: +```cpp + del_fQP F6(8); // // maximum 8 'delayed' functions pointers with parameters in queue + + ``` +put where you want (here example of 2 functions put into queue): +```cpp + F6.push_delayed(your_func_1, 3.14, 1000); // function your_func_1(3.14) will be delayed for 1000 'ticks' + F6.push_delayed(your_func_2, 3.15, 2000); // function your_func_2(3.15) will be delayed for 2000 'ticks' + ``` + + in main loop (or other periodic loop) just need to: + ```cpp + void loop() { + ....... + F6.pull(); //execute in loop just this super fast function; + } + ``` + in some timer or periodic function: + ```cpp + F6.tick(); // execute for 'ticks' in timer so the queue class instance will know then to initiate execution + ``` That's it. Enjoy! diff --git a/examples/ARDUINO_NANO_delayed_with_parameters/ARDUINO_NANO_delayed_with_parameters.ino b/examples/ARDUINO_NANO_delayed_with_parameters/ARDUINO_NANO_delayed_with_parameters.ino new file mode 100644 index 0000000..df150e8 --- /dev/null +++ b/examples/ARDUINO_NANO_delayed_with_parameters/ARDUINO_NANO_delayed_with_parameters.ino @@ -0,0 +1,48 @@ +#include + +typedef +struct pinOut{ // structure (index - pin number, logic - 1/0 = ON/OFF) + int index; + bool logic; +} pinout ; + +del_fQP Q1(8); // maximum 8 function pointers with parameters in queue + +void writePin(pinout cmd){ // write a pin true =- ON + + digitalWrite(cmd.index, cmd.logic); + +} + +void setup() { + // put your setup code here, to run once: + pinMode(13, OUTPUT); + pinMode(12, OUTPUT); + + TCCR1A = 0x00; //Normal Mode + TCCR1B = 0x00; //TC1 is OFF + TCNT1 = 0; + OCR1A = 6250; //0.1s delay; prescaler 256 + bitSet(TIMSK1, OCIE1A); //local intterupt is active + TCCR1B |= bit(CS12); //Start TC1 with prescale 256 + + Q1.push_delayed(writePin,{12,true},20); //yellow led ON after 2 sec. (0.1*20 = 2 seconds) + Q1.push_delayed(writePin,{12,false},30); //yellow led OFF after 3 sec. + Q1.push_delayed(writePin,{13,true},50); //red led ON after 5 sec. + Q1.push_delayed(writePin,{13,false},80); //red led OFF after 8 sec. + +} + +void loop() { + // put your main code here, to run repeatedly: + Q1.pull(); // pull from the queue + +} + +ISR(TIMER1_COMPA_vect) // timer interrupt ticks one per 0.1 sec +{ + TCNT1 = 0; + OCR1A = 6250; + Q1.tick(); // execute tick method for make delayed functionality works +} + diff --git a/keywords.txt b/keywords.txt index ffb5bc8..bddf569 100644 --- a/keywords.txt +++ b/keywords.txt @@ -5,6 +5,7 @@ ANTIRTOS KEYWORD1 fQ KEYWORD1 fQP KEYWORD1 del_fQ KEYWORD1 +del_fQP KEYWORD1 ####################################### # Methods and Functions (KEYWORD2) @@ -26,5 +27,14 @@ pull KEYWORD2 # Class del_fQ ################################### push_delayed KEYWORD2 +push KEYWORD2 +pull KEYWORD2 +tick KEYWORD2 + +################################### +# Class del_fQP +################################### +push_delayed KEYWORD2 +push KEYWORD2 pull KEYWORD2 tick KEYWORD2 diff --git a/library.properties b/library.properties index 5de09d7..98fcd63 100644 --- a/library.properties +++ b/library.properties @@ -1,5 +1,5 @@ name=ANTIRTOS -version=0.2.1 +version=1.0.0 author=Aleksei Tertychnyi maintainer=Aleksei Tertychnyi sentence= No any RTOS needed, you will see...