Deneyap Kart – Masa Saati

Bu projemizde Deneyap Kart modüllerinden OLED ekran, gerçek zamanlı saat modülü, sıcaklık ve nem sensörü mödülü, dokunmatik tuş yakımı modülünü kullandık. Tüm parçalar I2C bağlantı kabloları ile kolaylıkla bağlandı. Her birinin kütüphanesini indirip kodladık. Dokunmatik tuş takımı ile saatin ayarını yapabilmekteyiz. Kullanımı kodlarda var ama ben buraya da not düşeyim:

Keypad Tuş görevleri

  • 0 – 1 => Seçili değeri 1’er azaltıp(0) arttırır(1)
  • 2 – 3 => Seçili Değeri 10’ar azaltıp arttırır
  • 4 – 5 => Gün <-> Ay <-> Yıl <-> Saat <-> Dakika <-> değerleri arasında geçiş yapıp seçimi değiştirir
  • 6 – 7 => 6 Ayarlamayı iptal eder. 7 Ayarlamayı onaylar.
  • 8 – 9 => 8 Normal masa saati moduna alır. 9 Ayar moduna alır.

#include <Deneyap_OLED.h>
OLED OLED1;

#include <Deneyap_GercekZamanliSaat.h>
RTC GercekZamanliSaat;
DateTime now;

#include <Deneyap_SicaklikNemOlcer.h>
TempHum TempHum;

#include <Deneyap_DokunmatikTusTakimi.h>
Keypad Keypad;
/* Keypad Tuş görevleri
 * 0 - 1 => Seçili değeri 1'er azaltıp(0) arttırır(1)
 * 2 - 3 => Seçili Değeri 10'ar azaltıp arttırır
 * 4 - 5 => Gün <-> Ay <-> Yıl <-> Saat <-> Dakika <-> değerleri arasında geçiş yapıp seçimi değiştirir
 * 6 - 7 => 6 Ayarlamayı iptal eder. 7 Ayarlamayı onaylar.
 * 8 - 9 => 8 Normal masa saati moduna alır. 9 Ayar moduna alır
*/
bool mod = false;   //false saat modu, true ayar modu.
uint8_t secim = 0;  //0-gün, 1-ay, 2-yıl, 3-saat, 4-dakika
uint8_t ayrGun = 0;
uint8_t ayrAy = 0;
int ayrYil = 2024;
uint8_t ayrSaat = 0;
uint8_t ayrDakika = 0;

unsigned long timer1 = 0;

void setup() {
  //Serial.begin(115200);

  //Gerçek Zamanlı Saat Modülü
  if (!GercekZamanliSaat.begin()) {
    delay(3000);
    //Serial.println("I2C bağlantısı başarısız ");
    while (1)
      ;
  }

  //GercekZamanliSaat.adjust(DateTime(2024, 06, 11, 20, 31, 20));  // yıl, ay, gün, saat, dakika, saniyeni ayarlanması
  now = GercekZamanliSaat.now();

  Keypad.begin(0x0E);

  if (!TempHum.begin(0x70)) {
    delay(3000);
    //Serial.println("I2C bağlantısı başarısız ");
  }

  uint16_t READ_ID = TempHum.getReadID();
  //Serial.print("READ_ID = ");
  //Serial.println(READ_ID);

  //OLED Ekran Modülü
  OLED1.begin(0x7A);
  OLED1.clearDisplay();
  OLED1.setTextXY(0, 0);
  OLED1.putString("  Sistem Testi  ");
  delay(2000);
  for (int i = 0; i < 8; i++) {
    OLED1.setTextXY(i, 0);
    OLED1.putString("0123465789ABCDEF");
    delay(100);
  }

  delay(1000);

  OLED1.clearDisplay();
}

void loop() {
  int keyword = Keypad.KeypadRead();  // Tuş takımına basılan değeri okuması
  if (keyword != 0xFF) {
    switch (keyword) {
      case 0:
        if (mod) {
          switch (secim) {
            case 0:
              if (ayrGun == 1) {
                ayrGun = 31;
              } else {
                ayrGun--;
              }
              break;
            case 1:
              if (ayrAy == 1) {
                ayrAy = 12;
              } else {
                ayrAy--;
              }
              break;
            case 2:
              ayrYil--;
              break;
            case 3:
              if (ayrSaat == 0) {
                ayrSaat = 23;
              } else {
                ayrSaat--;
              }
              break;
            case 4:
              if (ayrDakika == 0) {
                ayrDakika = 59;
              } else {
                ayrDakika--;
              }
              break;
          }
          delay(100);
        }
        break;
      case 1:
        if (mod) {
          switch (secim) {
            case 0:
              if (ayrGun == 31) {
                ayrGun = 1;
              } else {
                ayrGun++;
              }
              break;
            case 1:
              if (ayrAy == 12) {
                ayrAy = 1;
              } else {
                ayrAy++;
              }
              break;
            case 2:
              ayrYil++;
              break;
            case 3:
              if (ayrSaat == 23) {
                ayrSaat = 0;
              } else {
                ayrSaat++;
              }
              break;
            case 4:
              if (ayrDakika == 59) {
                ayrDakika = 0;
              } else {
                ayrDakika++;
              }
              break;
          }
          delay(100);
        }
        break;
      case 2:
        if (mod) {
          switch (secim) {
            case 0:
              if (ayrGun >= 11) {
                ayrGun -= 10;
              } else {
                ayrGun = 31;
              }
              break;
            case 1:
              if (ayrAy >= 5) {
                ayrAy -= 5;
              } else {
                ayrAy = 12;
              }
              break;
            case 2:
              ayrYil -= 10;
              break;
            case 3:
              if (ayrSaat >= 5) {
                ayrSaat -= 5;
              } else {
                ayrSaat = 23;
              }
              break;
            case 4:
              if (ayrDakika >= 10) {
                ayrDakika -= 10;
              } else {
                ayrDakika = 59;
              }
              break;
          }
          delay(100);
        }
        break;
      case 3:
        if (mod) {
          switch (secim) {
            case 0:
              if (ayrGun > 21) {
                ayrGun = 1;
              } else {
                ayrGun += 10;
              }
              break;
            case 1:
              if (ayrAy > 7) {
                ayrAy = 1;
              } else {
                ayrAy += 5;
              }
              break;
            case 2:
              ayrYil += 10;
              break;
            case 3:
              if (ayrSaat > 18) {
                ayrSaat = 0;
              } else {
                ayrSaat += 5;
              }
              break;
            case 4:
              if (ayrDakika > 49) {
                ayrDakika = 0;
              } else {
                ayrDakika += 10;
              }
              break;
          }
          delay(100);
        }
        break;
      case 4:
        if (mod) {
          if (secim == 0) {
            secim = 4;
          } else {
            secim--;
          }
          delay(100);
        }
        break;
      case 5:
        if (mod) {
          if (secim == 4) {
            secim = 0;
          } else {
            secim++;
          }
          delay(100);
        }
        break;
      case 6:
        break;
      case 7:
        if (mod) {
          GercekZamanliSaat.adjust(DateTime(ayrYil, ayrAy, ayrGun, ayrSaat, ayrDakika, 0));  // yıl, ay, gün, saat, dakika, saniyeni ayarlanması
          now = GercekZamanliSaat.now();
          mod = false;
          OLED1.clearDisplay();
        }
        break;
      case 8:
        if (mod) {
          //Saat modunda değilse geçir.
          mod = false;
          secim = 0;
          OLED1.clearDisplay();
        }
        break;
      case 9:
        if (!mod) {
          //Ayar modunda değilse geçir.
          mod = true;
          ayrGun = now.day();
          ayrAy = now.month();
          ayrYil = now.year();
          ayrSaat = now.hour();
          ayrDakika = now.minute();
          OLED1.clearDisplay();
          secim = 0;
        }
        break;
    }
    delay(20);
  }
  if (mod) {
    //Ayar Modunda
    AyarModuYazdir();
  } else {
    //Masa Saati modunda
    Timer();  //Saati okur ve yazdırır.
  }
}

void Timer() {
  if (millis() - timer1 >= 1000 || millis() < timer1) {
    timer1 = millis();

    now = GercekZamanliSaat.now();

    OLED1.setTextXY(0, 0);
    OLED1.putString("|--------------|");
    OLED1.setTextXY(1, 0);
    OLED1.putString("|  ");

    if (now.day() < 10) {
      OLED1.putString("0");
    }
    OLED1.putNumber(now.day());
    OLED1.putString("/");
    if (now.month() < 10) {
      OLED1.putString("0");
    }
    OLED1.putNumber(now.month());
    OLED1.putString("/");
    OLED1.putNumber(now.year());
    OLED1.setTextXY(1, 15);
    OLED1.putString("|");
    OLED1.setTextXY(2, 0);
    OLED1.putString("|   ");
    if (now.hour() < 10) {
      OLED1.putString("0");
    }
    OLED1.putNumber(now.hour());
    OLED1.putString(":");
    if (now.minute() < 10) {
      OLED1.putString("0");
    }
    OLED1.putNumber(now.minute());
    OLED1.putString(":");
    if (now.second() < 10) {
      OLED1.putString("0");
    }
    OLED1.putNumber(now.second());
    OLED1.setTextXY(2, 15);
    OLED1.putString("|");
    OLED1.setTextXY(3, 0);
    OLED1.putString("|--------------|");
    OLED1.setTextXY(4, 0);
    OLED1.putString("| SICAKLIK:");
    float Tempvalue = TempHum.getTempValue();
    float Humvalue = TempHum.getHumValue();
    if (Tempvalue < 10.0) {
      OLED1.putString(" ");
    }
    OLED1.putNumber(floor(Tempvalue));
    OLED1.putString("C ");
    OLED1.setTextXY(4, 15);
    OLED1.putString("|");
    OLED1.setTextXY(5, 0);
    OLED1.putString("|--------------|");
    OLED1.setTextXY(6, 0);
    OLED1.putString("|   NEM:");
    if (Humvalue < 10.0) {
      OLED1.putString("  ");
    } else if (Humvalue < 100.0) {
      OLED1.putString(" ");
    }
    OLED1.putString("%");
    OLED1.putNumber(floor(Humvalue));
    OLED1.setTextXY(6, 15);
    OLED1.putString("|");
    OLED1.setTextXY(7, 0);
    OLED1.putString("|--------------|");
  }
}

void AyarModuYazdir() {
  OLED1.setTextXY(0, 0);
  OLED1.putString("---AYAR MODU----");
  OLED1.setTextXY(1, 0);
  if (secim == 0) {
    OLED1.putString(">>>");
  } else {
    OLED1.putString("   ");
  }
  OLED1.putString("Gun    : ");
  if (ayrGun < 10) {
    OLED1.putNumber(0);
  }
  OLED1.putNumber(ayrGun);
  OLED1.setTextXY(2, 0);
  if (secim == 1) {
    OLED1.putString(">>>");
  } else {
    OLED1.putString("   ");
  }
  OLED1.putString("Ay     : ");
  if (ayrAy < 10) {
    OLED1.putNumber(0);
  }
  OLED1.putNumber(ayrAy);
  OLED1.setTextXY(3, 0);
  if (secim == 2) {
    OLED1.putString(">>>");
  } else {
    OLED1.putString("   ");
  }
  OLED1.putString("Yil    : ");
  OLED1.putNumber(ayrYil);
  OLED1.setTextXY(4, 0);
  if (secim == 3) {
    OLED1.putString(">>>");
  } else {
    OLED1.putString("   ");
  }
  OLED1.putString("Saat   : ");
  if (ayrSaat < 10) {
    OLED1.putNumber(0);
  }
  OLED1.putNumber(ayrSaat);
  OLED1.setTextXY(5, 0);
  if (secim == 4) {
    OLED1.putString(">>>");
  } else {
    OLED1.putString("   ");
  }
  OLED1.putString("Dakika : ");
  if (ayrDakika < 10) {
    OLED1.putNumber(0);
  }
  OLED1.putNumber(ayrDakika);
  OLED1.setTextXY(7, 0);
  if (ayrGun < 10) {
    OLED1.putNumber(0);
  }
  OLED1.putNumber(ayrGun);
  OLED1.putString("/");
  if (ayrAy < 10) {
    OLED1.putNumber(0);
  }
  OLED1.putNumber(ayrAy);
  OLED1.putString("/");
  OLED1.putNumber(ayrYil);
  OLED1.putString(" ");
  if (ayrSaat < 10) {
    OLED1.putNumber(0);
  }
  OLED1.putNumber(ayrSaat);
  OLED1.putString(":");
  if (ayrDakika < 10) {
    OLED1.putNumber(0);
  }
  OLED1.putNumber(ayrDakika);
}

Yorum bırakın