TVZ2020 / Mbed OS Upravljanje_motorom

Dependencies:   TextLCD

Files at this revision

API Documentation at this revision

Comitter:
fsamardzi
Date:
Mon Mar 01 17:58:32 2021 +0000
Commit message:
123

Changed in this revision

.gitignore Show annotated file Show diff for this revision Revisions of this file
TextLCD.lib 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
mbed-os.lib Show annotated file Show diff for this revision Revisions of this file
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/.gitignore	Mon Mar 01 17:58:32 2021 +0000
@@ -0,0 +1,4 @@
+.build
+.mbed
+projectfiles
+*.py*
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/TextLCD.lib	Mon Mar 01 17:58:32 2021 +0000
@@ -0,0 +1,1 @@
+https://os.mbed.com/users/simon/code/TextLCD/#308d188a2d3a
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/main.cpp	Mon Mar 01 17:58:32 2021 +0000
@@ -0,0 +1,78 @@
+#include "mbed.h"
+#include "TextLCD.h"
+
+InterruptIn Tipkalo(PB_3); //Tipkalo za uključivanje i iskjučivanje sustava
+DigitalOut Stanje_Sustava(PA_10); //Crvena LED-ica koja svijetli kada je sustav uključen
+DigitalOut Motor_U_Radu(PA_7); //Zelena LED-ica koja svijetli kada je motor u radu
+PwmOut Pokreni_Motor(PA_6); //PWM izlaz kojim reguliramo brzinu vrtnje motora
+
+Timer Debounce_Timer; //Timer za debounce tipkala
+Ticker Refresh; //Ticker koji poziva funkciju za signalizaciju
+
+TextLCD lcd(PB_4, PB_10, PA_8, PA_9, PC_7, PB_6); //Inicijalizacija LCD-a
+Serial pc(USBTX, USBRX); //Inicijalizacija serijske komunikacije sa PC-em
+
+void Ukljuci_Iskljuci_Sustav(void);
+void Racunanje_Brzine_Motora(void);
+void Signalizacija_Rada(void);
+
+float Brzina_Motora = 0.0; //Globalna varijabla brzine motora
+
+int main() {
+    
+    Tipkalo.mode(PullUp);
+    
+    Debounce_Timer.start();
+    Tipkalo.fall(&Ukljuci_Iskljuci_Sustav);
+    Refresh.attach(&Signalizacija_Rada, 0.5);
+    
+    Pokreni_Motor.period(0.01);
+    Pokreni_Motor = 0.0;
+    
+    while(1){
+        
+        Racunanje_Brzine_Motora();
+        
+        if(Stanje_Sustava==1){
+            Pokreni_Motor = Brzina_Motora;
+        }
+        
+        lcd.cls();
+        lcd.printf("Brzina: %2.2f ", Brzina_Motora);
+        
+    }
+}
+
+void Ukljuci_Iskljuci_Sustav() {
+    if (Debounce_Timer.read_ms()>200){
+        Stanje_Sustava=!Stanje_Sustava;
+        Debounce_Timer.reset();
+        
+        if(Stanje_Sustava==1){
+            Pokreni_Motor = Brzina_Motora;
+        }
+        else{
+            Pokreni_Motor = 0.0;
+        }
+    }
+}
+
+void Racunanje_Brzine_Motora() {
+    char c = pc.getc();
+    wait(0.001);
+    if((c == '+') && (Brzina_Motora < 1.0)) {
+        Brzina_Motora += 0.1;
+    }
+    if((c == '-') && (Brzina_Motora > 0.0)) {
+        Brzina_Motora -= 0.1;
+    }
+}
+
+void Signalizacija_Rada() {
+    if(Pokreni_Motor > 0.0){
+        Motor_U_Radu = 1;
+    }
+    else{
+        Motor_U_Radu = 0;
+    }
+}
\ No newline at end of file
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/mbed-os.lib	Mon Mar 01 17:58:32 2021 +0000
@@ -0,0 +1,1 @@
+https://github.com/ARMmbed/mbed-os/#cf4f12a123c05fcae83fc56d76442015cb8a39e9