Biblioteka LEDController.

Files at this revision

API Documentation at this revision

Comitter:
mpistelek
Date:
Thu Dec 02 21:07:04 2021 +0000
Commit message:
Pistelek_Gasenje-Paljenje_Svjetla_Pljeskanjem

Changed in this revision

LEDController.cpp Show annotated file Show diff for this revision Revisions of this file
LEDController.h Show annotated file Show diff for this revision Revisions of this file
diff -r 000000000000 -r 4001e6959177 LEDController.cpp
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/LEDController.cpp	Thu Dec 02 21:07:04 2021 +0000
@@ -0,0 +1,34 @@
+#include "LEDController.h"
+#include "mbed.h"
+
+LEDController::LEDController(PinName pin, float flashPeriodCon, bool blinkingModeCon, bool shouldBeOnCon):Dout(pin){
+    flashPeriod = flashPeriodCon;
+    blinkingMode = blinkingModeCon;
+    shouldBeOn = shouldBeOnCon;
+    flipper.attach(callback(this, &LEDController::flipperFunction), flashPeriod);
+}
+
+void LEDController::toggleBlinkingMode(){
+    blinkingMode = !blinkingMode;
+}
+
+void LEDController::toggleShouldBeOn(){
+    shouldBeOn = !shouldBeOn;
+}
+
+bool LEDController::getBlinkingMode(){
+    return blinkingMode;
+}
+
+void LEDController::checkOnOffState(){
+    if (shouldBeOn && !blinkingMode) {
+        Dout = 1;
+    } 
+    if (!shouldBeOn) {
+        Dout = 0;
+    }
+}
+
+void LEDController::flipperFunction(){
+    if (shouldBeOn && blinkingMode) Dout = !Dout;
+}
\ No newline at end of file
diff -r 000000000000 -r 4001e6959177 LEDController.h
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/LEDController.h	Thu Dec 02 21:07:04 2021 +0000
@@ -0,0 +1,24 @@
+#ifndef MBED_LEDCONTROLLER_H
+#define MBED_LEDCONTROLLER_H
+
+#include "mbed.h"
+
+class LEDController{
+    private:
+        DigitalOut Dout;
+        Ticker flipper;
+        float flashPeriod;
+        bool blinkingMode;
+        bool shouldBeOn;
+        
+    public:
+        LEDController(PinName pin, float flashPeriod, bool blinkingMode, bool shouldBeOn);
+    
+        void toggleBlinkingMode();
+        void toggleShouldBeOn();
+        bool getBlinkingMode();
+        void checkOnOffState();
+        void flipperFunction();
+};
+
+#endif
\ No newline at end of file