Create library

Files at this revision

API Documentation at this revision

Comitter:
qynx
Date:
Mon Dec 07 21:02:16 2020 +0000
Commit message:
Create library

Changed in this revision

toggle.cpp Show annotated file Show diff for this revision Revisions of this file
toggle.h Show annotated file Show diff for this revision Revisions of this file
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/toggle.cpp	Mon Dec 07 21:02:16 2020 +0000
@@ -0,0 +1,16 @@
+#include "toggle.h"
+
+
+
+Toggle::Toggle(PinName pin) : _p(pin)
+{
+    _p = 0;
+}
+
+void Toggle::toggle(int n)
+{
+    for(int i=0; i<n*2; i++) {
+        _p = !_p;
+        wait(0.2);
+    }
+}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/toggle.h	Mon Dec 07 21:02:16 2020 +0000
@@ -0,0 +1,62 @@
+#ifndef TOGGLE_H
+#define TOGGLE_H
+
+#include "mbed.h"
+
+
+/** Toggle pin for debugging purposes
+*
+* Example:
+* @code
+* #include "mbed.h"
+* #include "toggle.h"
+*
+* Toggle pin(P1_24);
+* Toggle led(P1_25);
+*
+* main()
+* {
+*
+*    while(1) {
+*        pin.toggle(5);  // toggle pin 5 times
+*        wait(1);
+*        led.toggle(3);  // toggle led 3 times
+*        wait(0.5);
+*    }
+*    
+* }
+* @endcode
+*/
+
+
+class Toggle
+{
+public:
+
+    /**
+      * toggle constructor
+      *
+      * @param pin  "pin" to toggle
+      */
+    Toggle(PinName pin);
+
+
+    /**
+    * Command to n times toggle the pin
+    */
+
+    void toggle(int n);
+
+
+
+
+private:
+
+    /**
+     * Set the Digital out pin
+     */
+
+    DigitalOut _p;
+};
+
+#endif