{"id":69,"date":"2022-10-04T05:41:03","date_gmt":"2022-10-04T05:41:03","guid":{"rendered":"http:\/\/www.ilgeipek.com\/tr\/?p=69"},"modified":"2022-10-04T05:41:18","modified_gmt":"2022-10-04T05:41:18","slug":"kum-saati","status":"publish","type":"post","link":"http:\/\/www.ilgeipek.com\/tr\/kum-saati\/","title":{"rendered":"Elektronik Kum Saati Yap\u0131m\u0131"},"content":{"rendered":"\n<p>Herkese selamlar arkada\u015flar, bu yaz\u0131da dot matrix kullanarak elektronik kum saati yap\u0131m\u0131n\u0131n detaylar\u0131na g\u00f6z ataca\u011f\u0131z. <br><br>Bu projenin esin kayna\u011f\u0131 olan ve ayn\u0131 zamanda kod k\u0131sm\u0131nda referans ald\u0131\u011f\u0131m\u0131z proje Fabrizio Branca&#8217;ya ait olan kum saati projesi. Proje videosuna a\u015fa\u011f\u0131daki link \u00fczerinden ula\u015fabilirsiniz.<br><a href=\"https:\/\/www.youtube.com\/watch?v=U-vmEOuy348\" target=\"_blank\" rel=\"noreferrer noopener\">https:\/\/www.youtube.com\/watch?v=U-vmEOuy348<\/a><\/p>\n\n\n\n<h3>Malzemeler<\/h3>\n\n\n\n<p>Projenin ana malzemesi kum saati g\u00f6r\u00fcnt\u00fcs\u00fcn\u00fc olu\u015fturacak dot matrixler. Dot matrix mod\u00fclleri \u00fczerindeki LEDleri kullanarak kum saati g\u00f6r\u00fcnt\u00fcs\u00fcn\u00fc sa\u011flam\u0131\u015f olaca\u011f\u0131z. Bir di\u011fer \u00f6nemli par\u00e7a ise ADXL345 \u0130vme \u00f6l\u00e7er.<\/p>\n\n\n\n<p><em>ADXL345 Sens\u00f6r\u00fc \u00d6zellikleri:<\/em><\/p>\n\n\n<div class=\"wp-block-image\">\n<figure class=\"alignright size-large is-resized\"><img loading=\"lazy\" src=\"http:\/\/ilgeipek.com\/wp-content\/uploads\/2021\/06\/image.png\" alt=\"\" class=\"wp-image-372\" width=\"302\" height=\"199\"\/><\/figure><\/div>\n\n\n<ul><li><em>Giri\u015f Voltaj\u0131: 3-5V<\/em><\/li><li><em>D\u00fc\u015f\u00fck g\u00fc\u00e7 t\u00fcketimi(40uA)<\/em><\/li><li><em>Serbest d\u00fc\u015f\u00fc\u015f alg\u0131lama<\/em><\/li><li><em>SPI ve I\u00b2C aray\u00fcz\u00fc<\/em><\/li><\/ul>\n\n\n\n<p>Sens\u00f6r\u00fcn \u00fc\u00e7 eksende verebildi\u011fi a\u00e7\u0131sal ivme de\u011ferleri ile saatin eksen hareketlerini tespit ederek LED matrixleri kontrol etmi\u015f olaca\u011f\u0131z. <\/p>\n\n\n\n<p><strong>Projenin ana malzemeleri:<\/strong><\/p>\n\n\n\n<ul><li><a href=\"https:\/\/www.robotistan.com\/arduino-nano?utm_source=blog&amp;utm_medium=ilgeipek\" target=\"_blank\" rel=\"noreferrer noopener\">Arduino Nano<\/a> (Elinizde olan herhangi bir Arduino modelini de kullanabilirsiniz.)<\/li><li><a href=\"https:\/\/www.robotistan.com\/adxl345-3-eksen-ivme-olcer-triple-axis-accelerometer-breakout-adxl345?utm_source=blog&amp;utm_medium=ilgeipek\" target=\"_blank\" rel=\"noreferrer noopener\">ADXL345 3 Eksen \u0130vme \u00d6l\u00e7er<\/a><\/li><li><a href=\"https:\/\/www.robotistan.com\/8x8-dot-matrix-karti-pespese-takilabilir-max7219?utm_source=blog&amp;utm_medium=ilgeipek\" target=\"_blank\" rel=\"noreferrer noopener\">8&#215;8 Dot Matrix Kart\u0131<\/a><\/li><li><a href=\"https:\/\/www.robotistan.com\/jumper-kablo?utm_source=blog&amp;utm_medium=ilgeipek\" target=\"_blank\" rel=\"noreferrer noopener\">Jumper Kablolar<\/a><\/li><\/ul>\n\n\n\n<h2>Ba\u011flant\u0131 \u015eemas\u0131<\/h2>\n\n\n\n<p>Sens\u00f6r ve dot matrixlerin Arduino ile olan ba\u011flant\u0131lar\u0131n\u0131 a\u015fa\u011f\u0131daki \u015fema \u00fczerinde g\u00f6rebilirsiniz. <\/p>\n\n\n<div class=\"wp-block-image\">\n<figure class=\"aligncenter size-large is-resized\"><img loading=\"lazy\" src=\"http:\/\/ilgeipek.com\/wp-content\/uploads\/2021\/06\/ba\u011flant\u0131-\u015femas\u0131-1024x621.jpg\" alt=\"\" class=\"wp-image-371\" width=\"768\" height=\"466\"\/><\/figure><\/div>\n\n\n<p>T\u00fcm ba\u011flant\u0131lar\u0131 yaparak projeyi kod a\u015famas\u0131na haz\u0131r hale getiriyoruz.<\/p>\n\n\n\n<h2>3D Dosyalar<\/h2>\n\n\n\n<p>Projeyi kum saati g\u00f6r\u00fcn\u00fcm\u00fcne \u00e7eviren tasar\u0131m\u0131n t\u00fcm par\u00e7alar\u0131na <a href=\"https:\/\/github.com\/eglix\/Projeler\/tree\/master\/Elektronic_Sand_Clock\" target=\"_blank\" rel=\"noreferrer noopener\">buraya<\/a> t\u0131klayarak ula\u015fabilirsiniz.<\/p>\n\n\n\n<h2>Proje Kodu<\/h2>\n\n\n\n<p>Projenin kod k\u0131sm\u0131nda proje fikrinin de esin kayna\u011f\u0131 olan Fabrizio Branca&#8217;n\u0131n kodundan faydalanarak kendi sens\u00f6r\u00fcm\u00fcze g\u00f6re uyarlad\u0131k. Kod k\u0131sm\u0131nda i\u015fe kendi kodunda kulland\u0131\u011f\u0131 k\u00fct\u00fcphaneleri indirerek ba\u015fl\u0131yoruz. Ard\u0131ndan k\u00fct\u00fcphaneleri Arduino IDE&#8217;ye dahil ediyoruz.<\/p>\n\n\n\n<p>K\u00fct\u00fcphaneler: <a href=\"https:\/\/github.com\/fbrnc\/Arduino_Hourglass\/tree\/master\/lib\" target=\"_blank\" rel=\"noreferrer noopener\">https:\/\/github.com\/fbrnc\/Arduino_Hourglass\/tree\/master\/lib<\/a><br>(Delay ve LedControl k\u00fct\u00fcphanelerini indiriyoruz)<\/p>\n\n\n\n<p>Projenin ana par\u00e7alar\u0131ndan olan ADXL345 sens\u00f6r\u00fcn\u00fcn kullan\u0131m \u00f6ncesi kalibre edilmesi projemizin daha sa\u011fl\u0131kl\u0131 \u00e7al\u0131\u015fmas\u0131n\u0131 sa\u011flayacakt\u0131r. ADXL sens\u00f6r\u00fcn\u00fc otomatik olarak kalibre etmek i\u00e7in Adafruit&#8217;in ADXL345 <a href=\"https:\/\/github.com\/adafruit\/Adafruit_ADXL345\" target=\"_blank\" rel=\"noreferrer noopener\">k\u00fct\u00fcphanesini<\/a> (E\u011fer y\u00fckl\u00fc de\u011filse Adafruit&#8217;in unified sensor <a href=\"https:\/\/github.com\/adafruit\/Adafruit_Sensor\" target=\"_blank\" rel=\"noreferrer noopener\">k\u00fct\u00fcphanesini <\/a>de kurman\u0131z gerekiyor.)  kurabilirsiniz. Ard\u0131ndan a\u015fa\u011f\u0131daki linkteki a\u015famalar\u0131 takip ederek sens\u00f6r\u00fc otomatik bir \u015fekilde kalibre edebilirsiniz.<br><a href=\"https:\/\/learn.adafruit.com\/adxl345-digital-accelerometer\/programming\" target=\"_blank\" rel=\"noreferrer noopener\">https:\/\/learn.adafruit.com\/adxl345-digital-accelerometer\/programming<\/a><\/p>\n\n\n\n<p>ADXL345 sens\u00f6r\u00fc ile ilgili detayl\u0131 bilgi i\u00e7in bu videoya da g\u00f6z atabilirsiniz: <a href=\"https:\/\/www.youtube.com\/watch?v=KMhbV1p3MWk\" target=\"_blank\" rel=\"noreferrer noopener\">https:\/\/www.youtube.com\/watch?v=KMhbV1p3MWk<\/a><\/p>\n\n\n\n<p>\u00d6n haz\u0131rl\u0131klar tamamland\u0131ysa kod y\u00fcklenmeye haz\u0131r. Kod i\u00e7erisindeki THRESHOLD de\u011ferleri ile oynayarak kum saatinin sens\u00f6re g\u00f6re d\u00f6n\u00fc\u015f hassasiyetini ayarlayabilirsiniz. <\/p>\n\n\n<div class=\"wp-block-image\">\n<figure class=\"aligncenter size-large is-resized\"><img loading=\"lazy\" src=\"http:\/\/ilgeipek.com\/wp-content\/uploads\/2021\/06\/image-1.png\" alt=\"\" class=\"wp-image-379\" width=\"555\" height=\"513\"\/><\/figure><\/div>\n\n\n<p>Koddaki delayHours ve delayMinutes de\u011fi\u015fkenlerinin de kum saatinin bo\u015falma s\u00fcresini temsil etti\u011fini eklemek isterim.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>#include \"Arduino.h\"\n#include \"LedControl.h\"\n#include \"Delay.h\"\n#include &lt;Wire.h&gt;\n\nint ADXL345 = 0x53; \/\/ The ADXL345 sensor I2C address\nfloat x, y;\n\n#define  MATRIX_A  1\n#define MATRIX_B  0\n\n#define ACC_THRESHOLD_LOW -0.5\n#define ACC_THRESHOLD_HIGH 0\n\n\/\/ Matrix\n#define PIN_DATAIN 5\n#define PIN_CLK 4\n#define PIN_LOAD 6\n\n\/\/ This takes into account how the matrixes are mounted\n#define ROTATION_OFFSET 90\n\n\/\/ in milliseconds\n#define DEBOUNCE_THRESHOLD 500\n#define DELAY_FRAME 80\n\n\nbyte delayHours = 0;\nbyte delayMinutes = 1;\n\nint gravity;\nLedControl lc = LedControl(PIN_DATAIN, PIN_CLK, PIN_LOAD, 2);\nNonBlockDelay d;\nint resetCounter = 0;\n\nlong getDelayDrop() {\n  \/\/ since we have exactly 60 particles we don't have to multiply by 60 and then divide by the number of particles again :)\n  return delayMinutes + delayHours * 60;\n}\n\ncoord getDown(int x, int y) {\n  coord xy;\n  xy.x = x-1;\n  xy.y = y+1;\n  return xy;\n}\ncoord getLeft(int x, int y) {\n  coord xy;\n  xy.x = x-1;\n  xy.y = y;\n  return xy;\n}\ncoord getRight(int x, int y) {\n  coord xy;\n  xy.x = x;\n  xy.y = y+1;\n  return xy;\n}\n\nbool canGoLeft(int addr, int x, int y) {\n  if (x == 0) return false; \/\/ not available\n  return !lc.getXY(addr, getLeft(x, y)); \/\/ you can go there if this is empty\n}\nbool canGoRight(int addr, int x, int y) {\n  if (y == 7) return false; \/\/ not available\n  return !lc.getXY(addr, getRight(x, y)); \/\/ you can go there if this is empty\n}\nbool canGoDown(int addr, int x, int y) {\n  if (y == 7) return false; \/\/ not available\n  if (x == 0) return false; \/\/ not available\n  if (!canGoLeft(addr, x, y)) return false;\n  if (!canGoRight(addr, x, y)) return false;\n  return !lc.getXY(addr, getDown(x, y)); \/\/ you can go there if this is empty\n}\n\n\nvoid goDown(int addr, int x, int y) {\n  lc.setXY(addr, x, y, false);\n  lc.setXY(addr, getDown(x,y), true);\n}\nvoid goLeft(int addr, int x, int y) {\n  lc.setXY(addr, x, y, false);\n  lc.setXY(addr, getLeft(x,y), true);\n}\nvoid goRight(int addr, int x, int y) {\n  lc.setXY(addr, x, y, false);\n  lc.setXY(addr, getRight(x,y), true);\n}\n\n\nint countParticles(int addr) {\n  int c = 0;\n  for (byte y=0; y&lt;8; y++) {\n    for (byte x=0; x&lt;8; x++) {\n      if (lc.getXY(addr, x, y)) {\n        c++;\n      }\n    }\n  }\n  return c;\n}\n\nbool moveParticle(int addr, int x, int y) {\n  if (!lc.getXY(addr,x,y)) {\n    return false;\n  }\n\n  bool can_GoLeft = canGoLeft(addr, x, y);\n  bool can_GoRight = canGoRight(addr, x, y);\n\n  if (!can_GoLeft &amp;&amp; !can_GoRight) {\n    return false; \/\/ we're stuck\n  }\n\n  bool can_GoDown = canGoDown(addr, x, y);\n\n  if (can_GoDown) {\n    goDown(addr, x, y);\n  } else if (can_GoLeft&amp;&amp; !can_GoRight) {\n    goLeft(addr, x, y);\n  } else if (can_GoRight &amp;&amp; !can_GoLeft) {\n    goRight(addr, x, y);\n  } else if (random(2) == 1) { \/\/ we can go left and right, but not down\n    goLeft(addr, x, y);\n  } else {\n    goRight(addr, x, y);\n  }\n  return true;\n}\n\nvoid fill(int addr, int maxcount) {\n  int n = 8;\n  byte x,y;\n  int count = 0;\n  for (byte slice = 0; slice &lt; 2*n-1; ++slice) {\n    byte z = slice&lt;n ? 0 : slice-n + 1;\n    for (byte j = z; j &lt;= slice-z; ++j) {\n      y = 7-j;\n      x = (slice-j);\n      lc.setXY(addr, x, y, (++count &lt;= maxcount));\n    }\n  }\n}\n\nint getGravity() {\n  Wire.beginTransmission(ADXL345);\n  Wire.write(0x32); \/\/ Start with register 0x32 (ACCEL_XOUT_H)\n  Wire.endTransmission(false);\n  Wire.requestFrom(ADXL345, 6, true); \/\/ Read 6 registers total, each axis value is stored in 2 registers\n  x = ( Wire.read()| Wire.read() &lt;&lt; 8); \/\/ X-axis value\n  x = x\/256; \/\/For a range of +-2g, we need to divide the raw values by 256, according to the datasheet\n  y = ( Wire.read()| Wire.read() &lt;&lt; 8); \/\/ Y-axis value\n  y = y\/256;\n  if (y &lt; ACC_THRESHOLD_LOW)  { return 0;   }\n  if (x &gt; ACC_THRESHOLD_HIGH) { return 90;  }\n  if (y &gt; ACC_THRESHOLD_HIGH) { return 180; }\n  if (x &lt; ACC_THRESHOLD_LOW)  { return 270; }\n}\n\nint getTopMatrix() {\n  return (getGravity() == 90) ? MATRIX_A : MATRIX_B;\n}\nint getBottomMatrix() {\n  return (getGravity() != 90) ? MATRIX_A : MATRIX_B;\n}\n\nvoid resetTime() {\n  for (byte i=0; i&lt;2; i++) {\n    lc.clearDisplay(i);\n  }\n  fill(getTopMatrix(), 60);\n  d.Delay(getDelayDrop() * 1000);\n}\n\n\/**\n * Traverse matrix and check if particles need to be moved\n *\/\nbool updateMatrix() {\n  int n = 8;\n  bool somethingMoved = false;\n  byte x,y;\n  bool direction;\n  for (byte slice = 0; slice &lt; 2*n-1; ++slice) {\n    direction = (random(2) == 1); \/\/ randomize if we scan from left to right or from right to left, so the grain doesn't always fall the same direction\n    byte z = slice&lt;n ? 0 : slice-n + 1;\n    for (byte j = z; j &lt;= slice-z; ++j) {\n      y = direction ? (7-j) : (7-(slice-j));\n      x = direction ? (slice-j) : j;\n      \/\/ for (byte d=0; d&lt;2; d++) { lc.invertXY(0, x, y); delay(50); }\n      if (moveParticle(MATRIX_B, x, y)) {\n        somethingMoved = true;\n      };\n      if (moveParticle(MATRIX_A, x, y)) {\n        somethingMoved = true;\n      }\n    }\n  }\n  return somethingMoved;\n}\n\n\/**\n * Let a particle go from one matrix to the other\n *\/\nboolean dropParticle() {\n  if (d.Timeout()) {\n    d.Delay(getDelayDrop() * 1000);\n    if (gravity == 0 || gravity == 180) {\n      if ((lc.getRawXY(MATRIX_A, 0, 0) &amp;&amp; !lc.getRawXY(MATRIX_B, 7, 7)) ||\n          (!lc.getRawXY(MATRIX_A, 0, 0) &amp;&amp; lc.getRawXY(MATRIX_B, 7, 7))\n      ) {\n        \/\/ for (byte d=0; d&lt;8; d++) { lc.invertXY(0, 0, 7); delay(50); }\n        lc.invertRawXY(MATRIX_A, 0, 0);\n        lc.invertRawXY(MATRIX_B, 7, 7);\n        return true;\n      }\n    }\n  }\n  return false;\n}\n\n\nvoid resetCheck() {\n  int z = analogRead(A3);\n  if (z &gt; ACC_THRESHOLD_HIGH || z &lt; ACC_THRESHOLD_LOW) {\n    resetCounter++;\n    Serial.println(resetCounter);\n  } else {\n    resetCounter = 0;\n  }\n  if (resetCounter &gt; 20) {\n    Serial.println(\"RESET!\");\n    resetTime();\n    resetCounter = 0;\n  }\n}\n\n\/**\n * Setup\n *\/\nvoid setup() {\n  Serial.begin(9600);\n\n  Wire.begin(); \/\/ Initiate the Wire library\n  \/\/ Set ADXL345 in measuring mode\n  Wire.beginTransmission(ADXL345); \/\/ Start communicating with the device \n  Wire.write(0x2D); \/\/ Access\/ talk to POWER_CTL Register - 0x2D\n  \/\/ Enable measurement\n  Wire.write(8); \/\/ (8dec -&gt; 0000 1000 binary) Bit D3 High for measuring enable \n  Wire.endTransmission();\n  delay(10);\n\n  \/\/ init displays\n  for (byte i=0; i&lt;2; i++) {\n    lc.shutdown(i,false);\n    lc.setIntensity(i,2);\n  }\n\n  resetTime();\n}\n\n\/**\n * Main loop\n *\/\nvoid loop() {\n  delay(DELAY_FRAME);\n\n  gravity = getGravity();\n  lc.setRotation((ROTATION_OFFSET + gravity) % 360);\n\n  bool moved = updateMatrix();\n  bool dropped = dropParticle();\n  }\n<\/code><\/pre>\n\n\n\n<p>Umar\u0131m keyifli bir proje olmu\u015ftur. Gelecek videolar i\u00e7in proje fikirlerinizi yorum k\u0131sm\u0131nda payla\u015fmay\u0131 unutmay\u0131n. Bir ba\u015fka projede g\u00f6r\u00fc\u015f\u00fcnceye dek, ho\u015f\u00e7a kal\u0131n \ud83d\ude42<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Herkese selamlar arkada\u015flar, bu yaz\u0131da dot matrix kullanarak elektronik kum saati yap\u0131m\u0131n\u0131n detaylar\u0131na g\u00f6z ataca\u011f\u0131z. Bu projenin esin kayna\u011f\u0131 olan ve ayn\u0131 zamanda kod k\u0131sm\u0131nda referans ald\u0131\u011f\u0131m\u0131z proje Fabrizio Branca&#8217;ya ait olan kum saati projesi. Proje videosuna a\u015fa\u011f\u0131daki link \u00fczerinden ula\u015fabilirsiniz.https:\/\/www.youtube.com\/watch?v=U-vmEOuy348 Malzemeler Projenin ana malzemesi kum saati g\u00f6r\u00fcnt\u00fcs\u00fcn\u00fc olu\u015fturacak dot matrixler. Dot matrix mod\u00fclleri \u00fczerindeki&#8230;<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_coblocks_attr":"","_coblocks_dimensions":"","_coblocks_responsive_height":"","_coblocks_accordion_ie_support":""},"categories":[],"tags":[],"_links":{"self":[{"href":"http:\/\/www.ilgeipek.com\/tr\/wp-json\/wp\/v2\/posts\/69"}],"collection":[{"href":"http:\/\/www.ilgeipek.com\/tr\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/www.ilgeipek.com\/tr\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/www.ilgeipek.com\/tr\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"http:\/\/www.ilgeipek.com\/tr\/wp-json\/wp\/v2\/comments?post=69"}],"version-history":[{"count":1,"href":"http:\/\/www.ilgeipek.com\/tr\/wp-json\/wp\/v2\/posts\/69\/revisions"}],"predecessor-version":[{"id":70,"href":"http:\/\/www.ilgeipek.com\/tr\/wp-json\/wp\/v2\/posts\/69\/revisions\/70"}],"wp:attachment":[{"href":"http:\/\/www.ilgeipek.com\/tr\/wp-json\/wp\/v2\/media?parent=69"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/www.ilgeipek.com\/tr\/wp-json\/wp\/v2\/categories?post=69"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/www.ilgeipek.com\/tr\/wp-json\/wp\/v2\/tags?post=69"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}