TINF_MyPwm

Dependents:   TINF_MyPwm

Files at this revision

API Documentation at this revision

Comitter:
martwerl
Date:
Fri Jun 22 11:04:29 2018 +0000
Commit message:
TINF_MyPwm

Changed in this revision

MyPwm.cpp Show annotated file Show diff for this revision Revisions of this file
MyPwm.h Show annotated file Show diff for this revision Revisions of this file
main.cpp Show annotated file Show diff for this revision Revisions of this file
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/MyPwm.cpp	Fri Jun 22 11:04:29 2018 +0000
@@ -0,0 +1,25 @@
+#include "mbed.h"
+#include "MyPwm.h"
+
+void MyPwm::dimUp(void)
+{
+    while(_pin != 1)
+    {
+        _pin = _pin + 0.1;
+        printStatus();
+        wait_ms(500);
+    }
+}
+void MyPwm::dimDown(void)
+{
+    while (_pin != 0)
+    {
+        _pin = _pin - 0.1;
+        printStatus();
+        wait_ms(500);
+    }
+}
+void MyPwm::printStatus(void)
+{
+    printf("Led-Wert: %1.1f \n", (float)_pin);
+}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/MyPwm.h	Fri Jun 22 11:04:29 2018 +0000
@@ -0,0 +1,20 @@
+#include "mbed.h"
+#ifndef MYPWM_H
+#define MYPWM_H
+
+class MyPwm
+{
+private:
+    PwmOut _pin;
+ 
+public:
+    MyPwm(PinName pin) : _pin(pin)
+    {
+        _pin = 0;
+    }
+    void dimUp(void);
+    void dimDown(void);
+    void printStatus(void);
+};
+
+#endif
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/main.cpp	Fri Jun 22 11:04:29 2018 +0000
@@ -0,0 +1,13 @@
+#include "mbed.h"
+#include "MyPwm.h"
+
+MyPwm Pwm(LED1);
+int main()
+{
+    while (1)
+    {
+        Pwm.dimUp();
+        Pwm.dimDown();
+        break;
+    }
+}
\ No newline at end of file