Primjer kretanja kroz izbornike na SSD1306 OLED zaslonu uz pomoć 4 tipke.

Dependencies:   mbed OLED_SSD1306

Video rada projekta : https://youtu.be/hMW1pZ-a_38

Logika kretanja kroz izbornike https://os.mbed.com/media/uploads/oh_snaep/izrezak.jpg

Shema https://os.mbed.com/media/uploads/oh_snaep/shema-1.png

Files at this revision

API Documentation at this revision

Comitter:
oh_snaep
Date:
Mon Jan 31 20:44:44 2022 +0000
Commit message:
Predaja projekta

Changed in this revision

OLED_SSD1306.lib Show annotated file Show diff for this revision Revisions of this file
ikone.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
diff -r 000000000000 -r fa9ec70cc128 OLED_SSD1306.lib
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/OLED_SSD1306.lib	Mon Jan 31 20:44:44 2022 +0000
@@ -0,0 +1,1 @@
+https://os.mbed.com/users/Helmut64/code/OLED_SSD1306/#99a409809366
diff -r 000000000000 -r fa9ec70cc128 ikone.h
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/ikone.h	Mon Jan 31 20:44:44 2022 +0000
@@ -0,0 +1,45 @@
+const unsigned static char settings_48x48[] = {
+  0x00, 0x00, 0xC0, 0x02, 0x00, 0x00, 0x00, 0x00, 0xE0, 0x07, 0x00, 0x00, 
+  0x00, 0x00, 0xE0, 0x07, 0x00, 0x00, 0x00, 0x00, 0xF0, 0x0F, 0x00, 0x00, 
+  0x00, 0x00, 0xF0, 0x0F, 0x00, 0x00, 0x00, 0x00, 0xF0, 0x1F, 0x00, 0x00, 
+  0x00, 0x07, 0xF8, 0x1F, 0xE0, 0x00, 0x80, 0x1F, 0xFC, 0x3F, 0xF8, 0x01, 
+  0xC0, 0xFF, 0xFF, 0xFF, 0xFF, 0x03, 0xC0, 0xFF, 0xFF, 0xFF, 0xFF, 0x03, 
+  0xC0, 0xFF, 0xFF, 0xFF, 0xFF, 0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1F, 0xFE, 0x7F, 0xF8, 0x01, 0x00, 0x0F, 0xF8, 0x1F, 0xF0, 0x00, 
+  0x00, 0x00, 0xF8, 0x0F, 0x00, 0x00, 0x00, 0x00, 0xF0, 0x0F, 0x00, 0x00, 
+  0x00, 0x00, 0xF0, 0x0F, 0x00, 0x00, 0x00, 0x00, 0xE0, 0x07, 0x00, 0x00, 
+  0x00, 0x00, 0xE0, 0x07, 0x00, 0x00, 0x00, 0x00, 0xA0, 0x05, 0x00, 0x00, 
+  };
+
+const unsigned static char strelica_desno_12x9[] = {
+  0x02, 0x00, 0x1E, 0x00, 0x7E, 0x00, 0xFE, 0x03, 0xFF, 0x07, 0xFE, 0x01, 
+  0x7E, 0x00, 0x0E, 0x00, 0x02, 0x00, };
+
+const unsigned static char strelica_lijevo_12x9[] = {
+  0x00, 0x04, 0x00, 0x07, 0xE0, 0x07, 0xF8, 0x07, 0xFE, 0x0F, 0xFC, 0x07, 
+  0xE0, 0x07, 0x80, 0x07, 0x00, 0x04, };
+
+const unsigned char x_9x9[] = {
+  0x83, 0x01, 0xC7, 0x01, 0xEE, 0x00, 0x7C, 0x00, 0x38, 0x00, 0x7C, 0x00, 
+  0xEE, 0x00, 0xC7, 0x01, 0x83, 0x01, };
+
+
+const unsigned char check_11x9[] = {
+  0x00, 0x06, 0x00, 0x07, 0x80, 0x03, 0xC3, 0x01, 0xE7, 0x00, 0x7E, 0x00, 
+  0x3C, 0x00, 0x18, 0x00, 0x00, 0x00, };
+
+
diff -r 000000000000 -r fa9ec70cc128 main.cpp
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/main.cpp	Mon Jan 31 20:44:44 2022 +0000
@@ -0,0 +1,261 @@
+#include "mbed.h"
+#include "ikone.h"
+#include "SSD1306I2C.h"
+
+Serial pc(USBTX, USBRX);
+
+Timer debounce;
+Timer gasenje_zaslona;
+
+InterruptIn desno(D7);
+InterruptIn potvrda(D5);
+InterruptIn otkaz(D6);
+InterruptIn lijevo(D4);
+
+bool aktuator=false;
+bool potvrda_ulaska_u_izbornik=false;
+bool potvrda_ulaska_u_podizbornik=false;
+uint8_t postavka_gasenja_zaslona=15; //5, 15, 30 sekundi
+//bool postavka_izbornika=false;
+
+void ispis_desno(void);
+void ispis_potvrda(void);
+void ispis_otkaz(void);
+void ispis_lijevo(void);
+
+SSD1306I2C display(0x3c, D14, D15);
+
+DigitalOut myled(LED1);
+void izbornik_tipke(void);
+
+uint8_t izbornik=0;
+uint8_t pod_izbornik=0;
+uint8_t postavka_izbornika=0;
+
+int main()
+{
+
+    desno.rise(ispis_desno);
+    potvrda.rise(ispis_potvrda);
+    otkaz.rise(ispis_otkaz);
+    lijevo.rise(ispis_lijevo);
+    display.init();
+    display.resetDisplay();
+    display.setFont(ArialMT_Plain_10);
+    display.drawString(30,0,"Vanja Belosevic");
+    display.drawString(35,20,"0246076901");
+    display.drawString(38,40,"2021/2022");
+    //display.drawStringMaxWidth(0,0,128,"Vanja Belosevic");
+    //display.drawStringMaxWidth(0,20,128,"0246076901");
+    //display.drawStringMaxWidth(0,40,128,"2021/2022");
+    display.display();
+    pc.printf("Mirko pokrenut!");
+    wait(5);
+    display.clear();
+    gasenje_zaslona.start();
+
+    while(1) {
+
+        if(gasenje_zaslona >= postavka_gasenja_zaslona) {
+            display.displayOff();
+        } else {
+            display.displayOn();
+        }
+
+        if(izbornik == 0 && potvrda_ulaska_u_podizbornik == false && potvrda_ulaska_u_izbornik == false) {
+            display.clear();
+            display.setFont(ArialMT_Plain_10);
+            display.drawString(0,0,"Stanje aktuatora:");
+            display.setFont(ArialMT_Plain_16);
+            if(aktuator == false) {
+                display.drawString(0,20,"OFF");
+            } else if(aktuator == true) {
+                display.drawString(0,20,"ON");
+            }
+        } else if(izbornik == 1 || (potvrda_ulaska_u_izbornik == true || potvrda_ulaska_u_podizbornik == true)) {
+            if(potvrda_ulaska_u_izbornik == false && potvrda_ulaska_u_podizbornik == false) {
+                display.clear();
+                display.drawXbm(40,0,48,48,settings_48x48); //x početno, y početno, širina, visina, char polje od slike
+            } else if(potvrda_ulaska_u_izbornik == true && potvrda_ulaska_u_podizbornik == false) {
+                if(pod_izbornik == 0) {
+                    display.clear();
+                    display.setFont(ArialMT_Plain_10);
+                    display.drawStringMaxWidth(0,0,128,"Odabir stanja aktuatora?");
+                } else if(pod_izbornik == 1) {
+                    display.clear();
+                    display.setFont(ArialMT_Plain_10);
+                    display.drawStringMaxWidth(0,0,128,"Odabir perioda automatskog gasenja zaslona?");
+                }
+            } else if(potvrda_ulaska_u_izbornik == false && potvrda_ulaska_u_podizbornik == true) {
+                display.clear();
+                display.setFont(ArialMT_Plain_10);
+                if(pod_izbornik == 0) {
+                    if(postavka_izbornika == 0) {
+                        display.drawStringMaxWidth(0,0,128,"Aktuator :");
+                        display.setFont(ArialMT_Plain_16);
+                        display.drawString(60,30,"OFF?");
+                    } else if(postavka_izbornika == 1) {
+                        display.drawStringMaxWidth(0,0,128,"Aktuator :");
+                        display.setFont(ArialMT_Plain_16);
+                        display.drawString(60,30,"ON?");
+                    }
+                } else if(pod_izbornik == 1) {
+                    if(postavka_izbornika == 0) {
+                        display.drawStringMaxWidth(0,0,128,"Odabir :");
+                        display.drawStringMaxWidth(0,30,128,"5 sekundi?");
+                    } else if(postavka_izbornika == 1) {
+                        display.drawStringMaxWidth(0,0,128,"Odabir :");
+                        display.drawStringMaxWidth(0,30,128,"15 sekundi?");
+                    } else if(postavka_izbornika == 2) {
+                        display.drawStringMaxWidth(0,0,128,"Odabir :");
+                        display.drawStringMaxWidth(0,30,128,"30 sekundi?");
+                    }
+                }
+            }
+
+        }
+        izbornik_tipke();
+        display.display();
+    }
+}
+
+//wait(10.0);
+
+//pc.printf("%d\n",x);
+
+
+void ispis_desno()
+{
+    debounce.start();
+    if(debounce.read_ms() >= 150) {
+        pc.printf("desna tipka pritisnuta!\n");
+        if(potvrda_ulaska_u_izbornik == false && potvrda_ulaska_u_podizbornik == false) {
+            --izbornik;
+            if(izbornik >= 2) izbornik = 1;
+        } else if(potvrda_ulaska_u_izbornik == true && potvrda_ulaska_u_podizbornik == false) {
+            //potvrda_ulaska_u_izbornik = false;
+            --pod_izbornik;
+            if(pod_izbornik >= 2) pod_izbornik = 1;
+        } else if(potvrda_ulaska_u_podizbornik == true && potvrda_ulaska_u_izbornik == false) {
+            --postavka_izbornika;
+            if(pod_izbornik == 0) {
+                if(postavka_izbornika >= 2) postavka_izbornika = 1;
+            } else if (pod_izbornik==1) {
+                if(postavka_izbornika >= 3) postavka_izbornika = 2;
+            }
+        }
+        debounce.reset();
+        display.displayOn();
+        gasenje_zaslona.reset();
+        pc.printf("Stanje varijable izbornik: %d\n",izbornik);
+        pc.printf("Stanje varijable pod_izbornik: %d\n",pod_izbornik);
+        pc.printf("Stanje varijable postavka_izbornika %d",postavka_izbornika);
+        pc.printf("potvrda_ulaska_u_izbornik: %d\n",potvrda_ulaska_u_izbornik);
+        pc.printf("potvrda_ulaska_u_podizbornik: %d\n",potvrda_ulaska_u_podizbornik);
+    }
+
+}
+
+void ispis_potvrda()
+{
+    debounce.start();
+    if(debounce.read_ms() >= 150) {
+        pc.printf("tipka potvda pritisnuta!\n");
+        debounce.reset();
+        display.displayOn();
+        gasenje_zaslona.reset();
+        if(izbornik == 1 && potvrda_ulaska_u_izbornik == false && potvrda_ulaska_u_podizbornik == false) {
+            potvrda_ulaska_u_izbornik = true;
+            potvrda_ulaska_u_podizbornik = false;
+            pod_izbornik = 0;
+            postavka_izbornika = 0;
+        } else if(potvrda_ulaska_u_izbornik == true && potvrda_ulaska_u_podizbornik == false) {
+            potvrda_ulaska_u_podizbornik = true;
+            potvrda_ulaska_u_izbornik = false;
+        } else if(potvrda_ulaska_u_izbornik == false && potvrda_ulaska_u_podizbornik == true) {
+            if(pod_izbornik == 0 && postavka_izbornika == 0) {
+                aktuator = false;
+            } else if(pod_izbornik == 0 && postavka_izbornika == 1) {
+                aktuator = true;
+            } else if(pod_izbornik == 1 && postavka_izbornika == 0) {
+                postavka_gasenja_zaslona=5;
+            } else if(pod_izbornik == 1 && postavka_izbornika == 1) {
+                postavka_gasenja_zaslona=15;
+            } else if(pod_izbornik == 1 && postavka_izbornika == 2) {
+                postavka_gasenja_zaslona=30;
+            }
+            potvrda_ulaska_u_podizbornik = false;
+            potvrda_ulaska_u_izbornik = true;
+        }
+        pc.printf("potvrda_ulaska_u_izbornik: %d\n",potvrda_ulaska_u_izbornik);
+        pc.printf("potvrda_ulaska_u_podizbornik: %d\n",potvrda_ulaska_u_podizbornik);
+    }
+}
+
+void ispis_otkaz()
+{
+    debounce.start();
+    if(debounce.read_ms() >= 150) {
+        pc.printf("tipka otkaz pritisnuta!\n");
+        debounce.reset();
+        display.displayOn();
+        gasenje_zaslona.reset();
+
+        if(potvrda_ulaska_u_izbornik == true && potvrda_ulaska_u_podizbornik == false) {
+            pod_izbornik=0;
+            izbornik=1;
+            potvrda_ulaska_u_izbornik = false;
+        } else if(potvrda_ulaska_u_izbornik == false && potvrda_ulaska_u_podizbornik == true) {
+            potvrda_ulaska_u_podizbornik = false;
+            potvrda_ulaska_u_izbornik = true;
+            pod_izbornik=0;
+            postavka_izbornika=0;
+            izbornik=1;
+        }
+        pc.printf("potvrda_ulaska_u_izbornik: %d\n",potvrda_ulaska_u_izbornik);
+        pc.printf("potvrda_ulaska_u_podizbornik: %d\n",potvrda_ulaska_u_podizbornik);
+    }
+}
+
+void ispis_lijevo()
+{
+    debounce.start();
+    if(debounce.read_ms() >= 150) {
+        pc.printf("lijeva tipka pritisnuta!\n");
+
+        if(potvrda_ulaska_u_izbornik == false && potvrda_ulaska_u_podizbornik == false) {
+            ++izbornik;
+            if(izbornik >= 2) izbornik = 0;
+        } else if(potvrda_ulaska_u_izbornik == true && potvrda_ulaska_u_podizbornik == false) {
+            ++pod_izbornik;
+            if(pod_izbornik >= 2) pod_izbornik = 0;
+        } else if(potvrda_ulaska_u_podizbornik == true && potvrda_ulaska_u_izbornik == false) {
+            ++postavka_izbornika;
+            if(pod_izbornik == 0) {
+                if(postavka_izbornika >= 2) postavka_izbornika = 0;
+            } else if (pod_izbornik==1) {
+                if(postavka_izbornika >= 3) postavka_izbornika = 0;
+            }
+        }
+        debounce.reset();
+        display.displayOn();
+        gasenje_zaslona.reset();
+        pc.printf("Stanje varijable izbornik: %d\n",izbornik);
+        pc.printf("Stanje varijable pod_izbornik: %d\n",pod_izbornik);
+        pc.printf("Stanje varijable postavka_izbornika: %d\n",postavka_izbornika);
+        pc.printf("potvrda_ulaska_u_izbornik: %d\n",potvrda_ulaska_u_izbornik);
+        pc.printf("potvrda_ulaska_u_podizbornik: %d\n",potvrda_ulaska_u_podizbornik);
+    }
+
+}
+
+//trajni izbornik na dnu zaslona, sadrži ikone za korištenje tipki
+void izbornik_tipke()
+{
+    display.drawHorizontalLine(0,52,128);
+    display.drawXbm(0,55,12,9,strelica_lijevo_12x9);
+    display.drawXbm(108,55,12,9,strelica_desno_12x9);
+    display.drawXbm(42,55,9,9,x_9x9);
+    display.drawXbm(75,55,11,9,check_11x9);
+    //display.display();
+}
diff -r 000000000000 -r fa9ec70cc128 mbed.bld
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/mbed.bld	Mon Jan 31 20:44:44 2022 +0000
@@ -0,0 +1,1 @@
+https://os.mbed.com/users/mbed_official/code/mbed/builds/65be27845400
\ No newline at end of file