Pokretna vrata library
Fork of libVrata by
shema sklopa
Revision 0:bcdd86b76a57, committed 2021-11-30
- Comitter:
- styropore
- Date:
- Tue Nov 30 22:15:03 2021 +0000
- Commit message:
- Pokretna vrata
Changed in this revision
libVrata.cpp | Show annotated file Show diff for this revision Revisions of this file |
libVrata.h | Show annotated file Show diff for this revision Revisions of this file |
diff -r 000000000000 -r bcdd86b76a57 libVrata.cpp --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/libVrata.cpp Tue Nov 30 22:15:03 2021 +0000 @@ -0,0 +1,38 @@ +#include "libVrata.h" +#include "mbed.h" + +Vrata::Vrata(PinName pinServo): servo(pinServo) +{ + pulsOtvorena = 0.112; //0.11 + pulsZatvorena = 0.069; //0.07 + polozaj = 0.09; // pocetni polozaj vrata - sredina + brzina = 0.0007; // brzina kretanja vrata (0.0007) + rucno = true; + servo.period(0.020); // 50Hz +} + +void Vrata::otvori() +{ + rad = 1; + while(polozaj < pulsOtvorena) { + polozaj = polozaj + brzina; + servo = polozaj; + wait_ms(5); + } + rad = 2; +} +void Vrata::zatvori() +{ + rad = -1; + while(polozaj > pulsZatvorena) { + polozaj = polozaj - brzina; + servo = polozaj; + wait_ms(5); + } + rad = -2; +} + + + + +
diff -r 000000000000 -r bcdd86b76a57 libVrata.h --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/libVrata.h Tue Nov 30 22:15:03 2021 +0000 @@ -0,0 +1,20 @@ +#ifndef libVrata_h +#define libVrata_h + +#include "mbed.h" + +class Vrata +{ +public: + Vrata(PinName pinServo); // pwm izlaz za upravljanje servom + bool rucno; // odabir rada: rucno ili automatski + int rad; // stanje vrata: -2 zatvorena, -1 u zatvaranju, 1 u otvaranju, 2 otvorena + void otvori(); // otvaranje vrata + void zatvori(); // zatvaranje vrata +private: + float pulsOtvorena, pulsZatvorena; // granične vrijednosti za servo motor + float polozaj; // polozaj motora + float brzina; // brzina kretanja motora + PwmOut servo; +}; +#endif \ No newline at end of file