Knjižnica za motor ograde

Files at this revision

API Documentation at this revision

Comitter:
mbuhin
Date:
Tue May 04 08:02:27 2021 +0000
Commit message:

Changed in this revision

Ograda.cpp Show annotated file Show diff for this revision Revisions of this file
Ograda.h Show annotated file Show diff for this revision Revisions of this file
diff -r 000000000000 -r 40c364a17882 Ograda.cpp
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/Ograda.cpp	Tue May 04 08:02:27 2021 +0000
@@ -0,0 +1,54 @@
+#include "Ograda.h"
+#include "mbed.h"
+
+
+Ograda::Ograda(PinName pin1, PinName pin2, PinName pin3, PinName pin4) : motor_open(pin1), motor_close(pin2), warn_light(pin3), brake(pin4) // Konstruktor, inicijalizacija varijabli
+{
+    motor_open=0;
+    motor_close=0;
+    warn_light=0;
+    brake=1;
+
+    wait_ms(50);
+}
+
+
+void Ograda::start(int dir, float time) //Funkcija za pokretanje motora u željenom smjeru s željenim čekanjem prije otvaranja
+{
+    
+    signal_blink.attach(callback(this, &Ograda::signalizacija), 1.0 );
+    
+    
+    if(time>0.0) // provjera ima li cekanja
+    {
+    wait(time);
+    }
+    
+    if(dir==0) { //0 - zatvaranje ograde
+        brake=0;
+        motor_open=0;
+        motor_close=1;
+    }
+    
+    if(dir==1) { // 1 - otvaranje ograde
+        brake=0;
+        motor_open=1;
+        motor_close=0;
+    }
+}
+
+
+void Ograda::signalizacija()
+{
+    warn_light=!warn_light;
+}
+
+
+void Ograda::stop() // procedura za zaustavljanje motora
+{
+    motor_open=0;
+    motor_close=0;
+    brake=1;
+    signal_blink.detach();
+    warn_light=0;  
+}
\ No newline at end of file
diff -r 000000000000 -r 40c364a17882 Ograda.h
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/Ograda.h	Tue May 04 08:02:27 2021 +0000
@@ -0,0 +1,24 @@
+#ifndef ograda_h
+#define ograda_h
+
+#include "mbed.h"
+
+
+class Ograda
+{
+public:
+
+    Ograda(PinName pin1, PinName pin2, PinName pin3, PinName pin4);
+
+    void start(int dir, float time);
+    void signalizacija(); // treperenje ledice
+    void stop();  //zaustavljanje motora
+
+private:
+
+    DigitalOut motor_open, motor_close, warn_light, brake;
+    Ticker signal_blink;
+    
+};
+
+#endif
\ No newline at end of file