TVZ2021 / Abramusic_upravljanje_servo_motorima

Files at this revision

API Documentation at this revision

Comitter:
racedom
Date:
Mon Dec 06 11:39:00 2021 +0000
Commit message:
Pomocu programa se upravlja servo motorima pomocu potenciometra ili tipkom koja automatski okrene motore

Changed in this revision

Motor.cpp Show annotated file Show diff for this revision Revisions of this file
Motor.h Show annotated file Show diff for this revision Revisions of this file
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/Motor.cpp	Mon Dec 06 11:39:00 2021 +0000
@@ -0,0 +1,15 @@
+#include "Motor.h"
+#include "mbed.h"
+
+Motor :: Motor(PinName pin1, PinName pin2) : A_pin(pin1),P_pin(pin2)
+{
+
+}                     // Deklaracija klase "Motor"
+int Motor::Control () // Deklaracija funkcije "Control"
+{
+    float Analog;     // Funkcija prima vrijednost sa pina i pretvara u "PWM"
+    float PWM;        // u rasponu od 900 us do 2100 us
+    Analog = A_pin;
+    PWM = 1200*Analog + 900;
+    return int(PWM);  // Vraća se "PWM signal" tipa integer
+}
\ No newline at end of file
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/Motor.h	Mon Dec 06 11:39:00 2021 +0000
@@ -0,0 +1,14 @@
+#ifndef MOTOR   // Provjera lib "MOTOR"
+#define MOTOR   // Definiranje lib "MOTOR"
+#include "mbed.h"
+
+class Motor     // Stvaranje klase Motor
+{
+public:
+    Motor(PinName pin1, PinName pin2); // Konstruktor klase Motor
+    int Control(); // Prototip funkcije "Control" za upravljanje motorom
+private:
+    AnalogIn A_pin; // Varijabla za prosljeđivanje Analog ulaza
+    PwmOut P_pin;   // Varijabla za prosljeđivanje PWM ulaza
+};
+#endif  // završava definiranje lib "MOTOR"
\ No newline at end of file