Punjenje i pražnjenje spremnika vode

Dependencies:   mbed

Files at this revision

API Documentation at this revision

Comitter:
mrimac
Date:
Fri Sep 09 00:14:08 2022 +0000
Parent:
0:1a5027292b9a
Commit message:
Spremnik vode

Changed in this revision

main.cpp Show annotated file Show diff for this revision Revisions of this file
spremnikVode.h Show annotated file Show diff for this revision Revisions of this file
diff -r 1a5027292b9a -r 07c01a8966ae main.cpp
--- a/main.cpp	Thu Sep 08 11:15:30 2022 +0000
+++ b/main.cpp	Fri Sep 09 00:14:08 2022 +0000
@@ -5,19 +5,21 @@
     
     while (1) {
         
-        if (sw) {
+        sw.rise(&turnOn);
+        
+        if (on) {
                 
-            // razina vode ja pala ispod dopustene
+            // razina vode je pala ispod dopustene
             if (!sensor && !button) {
                 full = false;
                 flash(led, 1000);
                 } else { led = false; }
-                
+            
             // punjenje
             if (!sensor && button) {
                 full = false;
                 full = startFilling ();
-                buzzer = false;
+                yLed = false;
                 } 
             
             // spremnik je napunjen
@@ -25,6 +27,13 @@
                 gLed = true;
                 } else { gLed = false;}
                 
+            // aktivacija buzzera
+            if (full && button) {
+            
+                buttonPressed();
+                
+                }
+                
         } 
    } 
 }
@@ -32,3 +41,4 @@
 
 
 
+
diff -r 1a5027292b9a -r 07c01a8966ae spremnikVode.h
--- a/spremnikVode.h	Thu Sep 08 11:15:30 2022 +0000
+++ b/spremnikVode.h	Fri Sep 09 00:14:08 2022 +0000
@@ -1,15 +1,16 @@
 #include "mbed.h"
 
 DigitalIn sensor(D9);
-DigitalIn sw(D8);
-InterruptIn button(D2);
-DigitalOut buzzer(A5);
+InterruptIn sw(D8);
+DigitalIn button(D2);
+DigitalOut yLed(A5);
 DigitalOut led(A0);
 DigitalOut gLed(A1);
+DigitalOut buzzer(A2);
+bool gLedLight;
 Ticker ticker;
-bool debug2;
 bool full;
-bool debug;
+bool on;
 
 void flash(DigitalOut lamp, int period) {
     lamp = !lamp;
@@ -19,18 +20,29 @@
 
 bool startFilling () {
     printf("Water is filling. ");
-    buzzer = true;
+    yLed = true;
     wait_ms(5000);
     printf("Water level is now ok. ");
     return true;
 }
 
-void tick () {
-    lowLevel = sensor;
+void flashGreen() {
+    gLedLight = !gLedLight;
+    }
+    
+void buzz(){
+    buzzer = true;
+    wait_ms(2000);
+    buzzer = false;
+    }
+
+void buttonPressed () {
+    if (full) {
+        ticker.attach(&buzz, 2.0);
+    }
 }
 
-void interrupt () {
-    if (debug) {
-        debug2 = !debug2;
-    }
-}
\ No newline at end of file
+void turnOn () {
+    on = !on;
+    
+    }
\ No newline at end of file