ledice

Dependencies:   mbed

https://os.mbed.com/media/uploads/kivankic/kristina_ivankic.png

Files at this revision

API Documentation at this revision

Comitter:
kivankic
Date:
Sun Jul 11 13:44:14 2021 +0000
Commit message:
ledice

Changed in this revision

ledice.cpp Show annotated file Show diff for this revision Revisions of this file
ledice.h 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.bld Show annotated file Show diff for this revision Revisions of this file
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/ledice.cpp	Sun Jul 11 13:44:14 2021 +0000
@@ -0,0 +1,30 @@
+#include "ledice.h"
+
+Ledice::Ledice(PinName pinZelenaLed, PinName pinZutaLed, PinName pinCrvenaLed): _zelenaLed(pinZelenaLed), _zutaLed(pinZutaLed), _crvenaLed(pinCrvenaLed)
+{
+    _zelenaLed = 0;
+    _zutaLed = 0;
+    _crvenaLed = 0;
+}
+
+void Ledice::postaviLedice(int zelena, int zuta, int crvena)
+{
+        _zelenaLed.write(zelena);
+        _zutaLed.write(zuta);
+        _crvenaLed.write(crvena);    
+}
+
+void Ledice::upaliSveLedice(int frekvencija)
+{
+        for(int i = 0; i<=5 ; i++) {
+            _zelenaLed.write(1);
+            _zutaLed.write(1);
+            _crvenaLed.write(1);
+            wait(frekvencija);
+            _zelenaLed.write(0);
+            _zutaLed.write(0);
+            _crvenaLed.write(0);
+            wait(frekvencija);
+            }
+}
+
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/ledice.h	Sun Jul 11 13:44:14 2021 +0000
@@ -0,0 +1,17 @@
+#include "mbed.h"
+#ifndef LEDICE_H
+#define LEDICE_H
+
+class Ledice
+{
+public:
+    Ledice(PinName pinZelenaLed, PinName pinZutaLed, PinName pinCrvenaLed);
+    void postaviLedice(int zelena, int zuta, int crvena);
+    void upaliSveLedice(int vrijemeRada);
+    
+private:
+    DigitalOut _zelenaLed;
+    DigitalOut _zutaLed;
+    DigitalOut _crvenaLed;
+};
+#endif
\ No newline at end of file
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/main.cpp	Sun Jul 11 13:44:14 2021 +0000
@@ -0,0 +1,48 @@
+#include "mbed.h"
+#include "ledice.h"
+
+//Serial pc(USBTX, USBRX);
+
+//Timer timer;
+Ticker kontrolniUlazT;
+InterruptIn button(D7, PullDown);
+Timer debounce;
+Ledice ledice(D4, D3, D2);
+
+
+DigitalIn ulazZelena(D5);
+DigitalIn ulazZuta(D6);
+DigitalIn ulazCrvena(D8);
+DigitalIn ulazKont(D9);
+
+void provjeraKontrolnogUlazaT();
+void prekid();
+
+int main()
+{
+   debounce.start();
+   button.rise(&prekid);    
+   kontrolniUlazT.attach(&provjeraKontrolnogUlazaT, 0.5);
+   ulazZelena.mode(PullDown);
+   ulazZuta.mode(PullDown);
+   ulazCrvena.mode(PullDown);
+   ulazKont.mode(PullDown);
+   
+   while(1){
+           ledice.postaviLedice(ulazZelena, ulazZuta, ulazCrvena);
+           wait(0.2);
+           }
+}
+
+void provjeraKontrolnogUlazaT(){
+    if(ulazKont == 1) {
+        ledice.upaliSveLedice(1);
+    }
+}
+
+void prekid() {
+    if(debounce.read_ms() > 200) {
+        ledice.upaliSveLedice(1.5);
+        debounce.reset();
+    }
+}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/mbed.bld	Sun Jul 11 13:44:14 2021 +0000
@@ -0,0 +1,1 @@
+https://os.mbed.com/users/mbed_official/code/mbed/builds/65be27845400
\ No newline at end of file