Arduino Nano Matter, Arduino Nano Connector Carrier ve Arduino Plug and Make Kit içindeki Modulino’lar ile hazırladığım Ekranlı Akıllı Ev Sıcaklık Sensörü Arduino sketch kodu.
Modulino olarak sıcaklık sensörü ve LED’leri kullanıyorum. Kendi geliştirdiğim SSD1306 OLED Modulino ise sıcaklığı ve kartın açılış sürecini görüntülemek için kullanılıyor.
|
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 |
//===================================================================// // // // \ | __| __ __| __| | | _ \ __| \ // // |\/ | _| | _| __ | ( | ( _ \ // // _| _| ___| _| ___| _| _| \___/ \___| _/ _\ // // // // Takip et. Beğen. Yorum Yap. Paylaş. // /*===================================================================// Kod : Arduino Nano Matter, Arduino Nano Connector Carrier ve Arduino Plug and Make Kit içindeki Modulino'lar ile hazırladığım Ekranlı Akıllı Ev Sıcaklık Sensörü Arduino sketch kodu. Kart : Arduino Nano Matter *///===============================================================//// // YouTube : https://www.youtube.com/MeteHoca // // Instagram : https://www.instagram.com/metehoca/ // // Web : https://www.metehoca.com // //===================================================================// #include <Matter.h> #include <MatterTemperature.h> #include <Modulino.h> #include <U8g2lib.h> MatterTemperature matter_temp_sensor; ModulinoThermo thermo; ModulinoPixels leds; U8G2_SSD1306_128X64_NONAME_F_HW_I2C u8g2(U8G2_R0); ModulinoColor OFF(0, 0, 0); ModulinoColor COLD(0, 0, 255); // Blue ModulinoColor COOL(0, 128, 255); // Light blue ModulinoColor WARM(255, 128, 0); // Orange ModulinoColor HOT(255, 0, 0); // Red ModulinoColor PROGRESS(0, 255, 0); // Green int brightness = 10; void setup() { Serial.begin(115200); Matter.begin(); matter_temp_sensor.begin(); Modulino.begin(); thermo.begin(); leds.begin(); u8g2.setI2CAddress(0x3D << 1); u8g2.begin(); Serial.println("METE HOCA Nano Matter & Modulino Temperature Sensor"); u8g2.clearBuffer(); u8g2.setFont(u8g2_font_helvB08_tr); drawCenteredStr(20, "METE HOCA"); u8g2.setFont(u8g2_font_helvR08_tr); drawCenteredStr(32, "Nano Matter | Modulino"); drawCenteredStr(44, "| Nano Connector Carrier"); drawCenteredStr(56, "Temperature Sensor"); u8g2.sendBuffer(); if (!Matter.isDeviceCommissioned()) { Serial.println("Matter device is not commissioned"); Serial.println("Commission it to your Matter hub with the manual pairing code or QR code"); Serial.printf("Manual pairing code: %s\n", Matter.getManualPairingCode().c_str()); Serial.printf("QR code URL: %s\n", Matter.getOnboardingQRCodeUrl().c_str()); } leds.set(0, PROGRESS, brightness); leds.set(1, PROGRESS, brightness); leds.show(); while (!Matter.isDeviceCommissioned()) { delay(100); } Serial.println("Waiting for Thread network..."); u8g2.clearBuffer(); drawCenteredStr(32, "Waiting for"); drawCenteredStr(44, "Thread network..."); u8g2.sendBuffer(); leds.set(2, PROGRESS, brightness); leds.set(3, PROGRESS, brightness); leds.show(); while (!Matter.isDeviceThreadConnected()) { delay(100); } Serial.println("Connected to Thread network"); u8g2.clearBuffer(); drawCenteredStr(32, "Connected to"); drawCenteredStr(44, "Thread network"); u8g2.sendBuffer(); leds.set(4, PROGRESS, brightness); leds.set(5, PROGRESS, brightness); leds.show(); Serial.println("Waiting for Matter device discovery..."); u8g2.clearBuffer(); u8g2.setFont(u8g2_font_helvR08_tr); drawCenteredStr(32, "Waiting for Matter"); drawCenteredStr(44, "device discovery"); u8g2.sendBuffer(); leds.set(6, PROGRESS, brightness); leds.set(7, PROGRESS, brightness); leds.show(); while (!matter_temp_sensor.is_online()) { delay(100); } Serial.println("Matter device is now online"); u8g2.clearBuffer(); drawCenteredStr(32, "Matter device is"); drawCenteredStr(44, "now online!"); u8g2.sendBuffer(); delay(1000); } void loop() { float celsius = thermo.getTemperature(); matter_temp_sensor.set_measured_value_celsius(celsius); if (celsius <= 0.0) { for (int i = 0; i < 8; i++) { leds.set(i, COLD, brightness); } } else { int numLeds = constrain((int)(celsius / 5.0), 0, 8); for (int i = 0; i < 8; i++) { if (i < numLeds) { ModulinoColor color = getHeatColor(i); leds.set(i, color, brightness); } else { leds.set(i, OFF, brightness); } } } leds.show(); char buffer[16]; snprintf(buffer, sizeof(buffer), "%.1f%cC", celsius, char(176)); u8g2.clearBuffer(); u8g2.setFont(u8g2_font_logisoso32_tf); int16_t text_width = u8g2.getStrWidth(buffer); int16_t x = (128 - text_width) / 2; int16_t y = 50; u8g2.drawStr(x, y, buffer); u8g2.sendBuffer(); delay(500); } ModulinoColor getHeatColor(int index) { switch (index) { case 0: return COLD; case 1: return ModulinoColor(0, 64, 255); case 2: return ModulinoColor(0, 128, 128); case 3: return ModulinoColor(0, 200, 50); case 4: return ModulinoColor(128, 200, 0); case 5: return ModulinoColor(255, 150, 0); case 6: return ModulinoColor(255, 50, 0); case 7: return HOT; default: return OFF; } } void drawCenteredStr(int y, const char* text) { int16_t text_width = u8g2.getStrWidth(text); int16_t x = (128 - text_width) / 2; u8g2.drawStr(x, y, text); } |










