AUTO_RAMPA_SAMBOLEK

Dependencies:   mbed HCSR04 TextLCD

Revision:
0:83ddf858b8ae
Child:
1:d4075ab93f44
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/main.cpp	Tue Sep 21 12:47:26 2021 +0000
@@ -0,0 +1,90 @@
+#include "mbed.h"
+#include "TextLCD.h"
+#include "HCSR04.h"
+
+TextLCD lcd(PB_10, PA_8, PA_10, PB_3, PB_5, PB_4); //inicijacija 20x4 LCD-a
+HCSR04 hcsr(PA_6, PA_7);
+DigitalOut Stop(PB_9);
+DigitalOut Kreni(PB_8);
+
+float d;
+
+InterruptIn Tipka(PA_5);
+Timer debounce;
+void proces(void);
+
+PwmOut SM(PB_0);
+float  pwmScale;
+
+Ticker provjera;
+
+Timer ZatRamp;
+
+void mjerenje()
+{
+    hcsr.startMeasurement();
+    if( hcsr.getDistance_mm()<90 && Kreni==1)
+    {   
+        SM=0.105;
+        }
+    if( hcsr.getDistance_mm()>90 && Kreni == 1)
+    {
+        ZatRamp.start();
+        Stop=1;
+        Kreni=0;
+        lcd.cls();
+        lcd.locate(4,1);
+        lcd.printf("Dobro dosli!\n");
+        lcd.locate(1,2);
+        lcd.printf("Pritisnite tipku !");
+        }
+    }
+
+
+int main()
+{
+
+    provjera.attach(&mjerenje,0.1);
+    SM=0.0534;
+    Stop = 1;
+    Kreni=0;
+    Tipka.mode(PullUp);
+    SM.period(0.020);
+    lcd.cls();
+    lcd.locate(4,1);
+    lcd.printf("Dobro dosli!\n");
+    lcd.locate(1,2);
+    lcd.printf("Pritisnite tipku !");
+    
+    
+    while(1)
+    { 
+        debounce.start();
+        Tipka.fall(&proces);
+        if(ZatRamp.read_ms()>5000)
+        {
+            SM=0.0534;
+            ZatRamp.reset();
+            Kreni=0;
+            }
+        
+    }
+}
+
+void proces(){
+   if (debounce.read_ms()>200)
+   {
+        hcsr.startMeasurement();
+        if(hcsr.getDistance_mm()<90 && Kreni==0){
+        lcd.cls();
+        lcd.locate(4,1);
+        lcd.printf("Dovidjenja!\n");
+        lcd.locate(4,2);
+        lcd.printf("Sretan put!");
+       Stop=!Stop;
+       Kreni=!Kreni;
+       SM=0.105;
+       }
+       } 
+       debounce.reset();
+    }
\ No newline at end of file