diff --git a/KEYWORDS.txt b/KEYWORDS.txt new file mode 100644 index 0000000..961726b --- /dev/null +++ b/KEYWORDS.txt @@ -0,0 +1,2 @@ +Ret_M KEYWORD1 +ret KEYWORD2 diff --git a/README.md b/README.md new file mode 100644 index 0000000..68f6be1 --- /dev/null +++ b/README.md @@ -0,0 +1,9 @@ +Ret_M Arduino Library +=========================================== +Small simple library to simplify applying delays utilizing the millis() function. +Ideal for time sensitive projects, debouncing, or for those who want to avoid utilizing delay(), delayMicroseconds(), or other of the kind that halts the program. + +### Usage +- Include Ret_M.h: #include "Ret_M.h" +- Initialize a delay: Ret_M name(interval) +- name.ret() returns true if the interval has passed. \ No newline at end of file diff --git a/Ret_M.cpp b/Ret_M.cpp new file mode 100644 index 0000000..d0dbb0c --- /dev/null +++ b/Ret_M.cpp @@ -0,0 +1,27 @@ +/* + Ret_M.cpp - Version 1.0 + Library for a delay method without + the delay() function and no actual delays. + Created by Carlos Joaquin Villalba, October 18, 2018. + Released under GNU GPLv3. +*/ + +#include "Arduino.h" +#include "Ret_M.h" + +Ret_M::Ret_M(long intervalo) +{ + _intervalo = intervalo; +} + +bool Ret_M::ret() +{ + if ((millis() - _millis_ant) >= _intervalo) + { + _millis_ant = millis(); + return true; + } + else{ + return false; + } +} \ No newline at end of file diff --git a/Ret_M.h b/Ret_M.h new file mode 100644 index 0000000..53f83ae --- /dev/null +++ b/Ret_M.h @@ -0,0 +1,24 @@ +/* + Ret_M.h - Version 1.0 + Library for a delay method without + the delay() function and no actual delays. + Created by Carlos Joaquin Villalba, October 18, 2018. + Released under GNU GPLv3. +*/ + +#ifndef Ret_M_h +#define Ret_M_h + +#include "Arduino.h" + +class Ret_M +{ + public: + Ret_M(long intervalo); + bool ret(); + + private: + unsigned long _millis_ant; + long _intervalo; +}; +#endif \ No newline at end of file diff --git a/examples/blinking/blinking.ino b/examples/blinking/blinking.ino new file mode 100644 index 0000000..56879e4 --- /dev/null +++ b/examples/blinking/blinking.ino @@ -0,0 +1,23 @@ +// Example demonstrating the capabilities of using Ret_M instead of regular delays +// By Carlos Joaquin Villalba, 18 October 2018 +// Makes the built-in led blink in intervals of 500 miliseconds +#include "Ret_M.h" //We include the library + +//We declare the delay (miliseconds): +Ret_M d1(500); // 500 miliseconds + +bool state; // Variable used to change the state of the LED + +void setup() { + pinMode(LED_BUILTIN, OUTPUT); // Built-in LED pin as output +} + +void loop() { + // If the interval has passed, + // invert the value of "state" + // and use its value to light the LED + if (d1.ret() == true){ + state = !state; + digitalWrite(13,state); + } +} diff --git a/library.properties b/library.properties new file mode 100644 index 0000000..3207ac0 --- /dev/null +++ b/library.properties @@ -0,0 +1,9 @@ +name=Ret_M delay millis library +version=1.0 +author=Carlos Joaquin Villalba +maintainer=https://github.com/Dragonop +sentence=Arduino library for easy implementation of delays without pauses +paragraph= Delays utilizing the millis function, for use in time sensitive programs or to avoid pauses in the program +category=Timing +url=https://github.com/Dragonop/Ret_M +architectures=* \ No newline at end of file