Robar Zangana / Mbed 2 deprecated LEDLIB

Dependencies:   mbed

Files at this revision

API Documentation at this revision

Comitter:
robarzangana
Date:
Wed Jul 08 10:59:04 2020 +0000
Commit message:
laboration 3

Changed in this revision

ledlib.cpp Show annotated file Show diff for this revision Revisions of this file
ledlib.h Show annotated file Show diff for this revision Revisions of this file
mbed.bld Show annotated file Show diff for this revision Revisions of this file
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/ledlib.cpp	Wed Jul 08 10:59:04 2020 +0000
@@ -0,0 +1,23 @@
+#include "ledlib.h"
+ 
+LED::LED(PinName pin): LED0(pin){
+    LED0 = false;  
+};
+ 
+void LED::on(){
+    LED0 = true;
+};
+ 
+void LED::off(){
+    LED0 = false;
+};
+ 
+void LED::toggle(){
+    LED0 = !LED0;
+};
+ 
+void LED::blink(float sec){
+    LED0 = !LED0;
+    wait(sec);
+    LED0 = !LED0;
+}
\ No newline at end of file
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/ledlib.h	Wed Jul 08 10:59:04 2020 +0000
@@ -0,0 +1,60 @@
+#ifndef LEDLIB_H
+#define LEDLIB_H
+ 
+#include "mbed.h"
+ 
+/** LED class.
+ *  Collection of supporrt functions for the second lab in the course ET095G at Mittuniversitetet.
+ *
+ *  To use the library, its header file needs to be included and an object of the LED class created.
+ *
+ *  Example:
+ *  @code
+ * #include "mbed.h"
+ * #include "Led.h"
+ *
+ * LED myled(PF4);
+ *
+ * int main(){
+ *  while(1){
+ *  wait(5);
+ *  myled.on();   //Turns the led on
+ *  wait(5);
+ *  myled.blink(1); //Blinks the led for 0.2 seconds
+ *  wait(5);
+ *  myled.toggle();   //Toggles the state of the led (turns it off)
+ *  }
+ *  @endcode
+ */
+ 
+class LED {
+    public:
+        /** The constructor creates an instance of the LED class. It is automatically called when a new object is declared.
+        * @param PinName pin = (The pin that is used).
+        */    
+        LED(PinName pin);
+        
+        /** This function sets LED0(i.e., turns it on).
+         */
+        void on();
+        
+        /** This function clears LED0 (i.e., turns it off).
+         */
+        void off();
+        
+        /** This function toggles LED0 (i.e., it inverts its current state).
+         */
+        void toggle();
+        
+        /** This function toggles LED0 on and off in an intervall set by the user.
+        * @param sec intervall time for led blink in seconds.
+        */        
+        void blink(float sec);
+        
+    private:
+        /** LED0 is the lamp on the board
+        */
+        DigitalOut LED0;
+};
+ 
+#endif
\ No newline at end of file
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/mbed.bld	Wed Jul 08 10:59:04 2020 +0000
@@ -0,0 +1,1 @@
+https://os.mbed.com/users/mbed_official/code/mbed/builds/65be27845400
\ No newline at end of file