Library koji sluzi za izvrsavanje simulacije kretanja unazad

Files at this revision

API Documentation at this revision

Comitter:
leleracic
Date:
Thu Nov 26 16:51:42 2020 +0000
Commit message:
Library koji u sebi sadrzi funkcije za simuliranje udaljenosti od straznjeg objekta.

Changed in this revision

potenciometar.cpp Show annotated file Show diff for this revision Revisions of this file
potenciometar.h Show annotated file Show diff for this revision Revisions of this file
diff -r 000000000000 -r 22d3ec372d97 potenciometar.cpp
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/potenciometar.cpp	Thu Nov 26 16:51:42 2020 +0000
@@ -0,0 +1,69 @@
+#include "potenciometar.h"
+#include "Citanjeznaka.h"
+
+PwmOut buzzer(PC_7);
+AnalogIn pot(PA_1);
+DigitalOut stop(PA_0);
+DigitalOut kreni(PB_0);
+
+float ADCdata;
+
+Timer timer1;
+Timer timer2;
+Timer debounce;
+
+
+void potenciometar(void){
+            debounce.start();
+            ADCdata=pot;
+            timer1.start();
+            timer2.start();
+            if(0.9<ADCdata && ADCdata<=1.0) {
+                buzzer.period(0.0015);
+                buzzer=0.5;
+                if (timer1.read_ms()>=600) { // read time in ms
+                    buzzer=0.0;
+                }
+                if (timer2.read_ms()>=1200) { // read time in ms
+                    timer1.reset(); // reset timer
+                    timer2.reset(); // reset timer
+                }
+            }
+            if(0.5<ADCdata && ADCdata<=0.9) {
+                buzzer.period(0.0015);
+                buzzer=0.5;
+                if (timer1.read_ms()>=300) { // read time in ms
+                    buzzer=0.0;
+                }
+                if (timer2.read_ms()>=600) { // read time in ms
+                    timer1.reset(); // reset timer
+                    timer2.reset(); // reset timer
+                }
+            }
+            if(0.2<ADCdata && ADCdata<=0.5) {
+                buzzer.period(0.0015);
+                buzzer=0.5;
+                if (timer1.read_ms()>=150) { // read time in ms
+                    buzzer=0.0;
+                }
+                if (timer2.read_ms()>=300) { // read time in ms
+                    timer1.reset(); // reset timer
+                    timer2.reset(); // reset timer
+                }
+            }
+            if(ADCdata<=0.2 && ADCdata>0.02) {
+                buzzer.period(0.0015);
+                buzzer=0.5;
+            }
+            kreni=0;
+            stop=1;
+}
+
+void Sudar(void){
+    if (ADCdata <= 0.02){
+            kreni=0;
+            start=0;
+            buzzer=0.0;
+            pc.printf("Sudarili ste se!\n\r");
+        }
+}
\ No newline at end of file
diff -r 000000000000 -r 22d3ec372d97 potenciometar.h
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/potenciometar.h	Thu Nov 26 16:51:42 2020 +0000
@@ -0,0 +1,12 @@
+#ifndef POTENCIOMETAR_H
+#define POTENCIOMETAR_H
+#include "mbed.h"
+extern DigitalOut stop;
+extern DigitalOut kreni;
+extern PwmOut buzzer;
+extern AnalogIn pot;
+
+void potenciometar(void);
+void Sudar(void);
+
+#endif
\ No newline at end of file