{"id":576,"date":"2015-11-01T18:44:21","date_gmt":"2015-11-01T09:44:21","guid":{"rendered":"http:\/\/goji2100.s199.coreserver.jp\/blog\/?p=576"},"modified":"2022-05-03T12:18:19","modified_gmt":"2022-05-03T03:18:19","slug":"arduino%ef%bc%8b7seg-led%ef%bc%8brtc%e3%81%a7%e3%83%87%e3%82%b8%e3%82%bf%e3%83%ab%e6%99%82%e8%a8%88","status":"publish","type":"post","link":"http:\/\/goji2100.com\/blog\/?p=576","title":{"rendered":"Arduino\uff0b7Seg LED\uff0bRTC\u3067\u30c7\u30b8\u30bf\u30eb\u6642\u8a08"},"content":{"rendered":"<p>\u90e8\u54c1\u7bb1\u3067\u7720\u3063\u3066\u3044\u308bArduino\u306b\u5b89\u30447Seg LED\u3092\u63a5\u7d9a\u3057\u3066\u30c7\u30b8\u30bf\u30eb\u6642\u8a08\u3092\u4f5c\u308a\u307e\u3059\u3002<br \/>\n\u7c21\u5358\u306b\u3059\u308b\u305f\u3081\u306b4\u6841(12:34)\u306eLED(<a href=\"http:\/\/www.aitendo.com\/product\/11532\" target=\"_blank\" rel=\"noopener\">4\u68417\u30bb\u30b0LED\u8868\u793a\u5668 [BW428G-E1-10MM]<\/a>)\u3092\u4f7f\u3044\u307e\u3059\u3002<br \/>\nArduino\u306e\u5185\u90e8\u30af\u30ed\u30c3\u30af\u3067\u306f\u7cbe\u5ea6\u304c\u5f97\u3089\u308c\u306a\u3044\u306e\u3067\u9ad8\u7cbe\u5ea6(\u6708\u5dee13\u79d2\u7a0b\u5ea6)\u306eRTC(<a href=\"http:\/\/akizukidenshi.com\/catalog\/g\/gK-08585\/\" target=\"_blank\" rel=\"noopener\">RX-8025NB\u4f7f\u7528 I2C\u63a5\u7d9a\u30ea\u30a2\u30eb\u30bf\u30a4\u30e0\u30af\u30ed\u30c3\u30af(RTC)\u30e2\u30b8\u30e5\u30fc\u30eb<\/a>)\u3092\u63a5\u7d9a\u3057\u307e\u3057\u305f\u3002<br \/>\n\uff0aRTC\u3092\u63a5\u7d9a\u3057\u306a\u304f\u3066\u3082\u52d5\u304d\u307e\u3059\u304c\u7cbe\u5ea6\u306f\u60aa\u3044\u3067\u3059\u30fb\u30fb<\/p>\n<p>\u96fb\u6e90\u6295\u5165\u6642\u306f\u300100:00\u3067\u8a08\u6642\u958b\u59cb\u3057\u307e\u3059\u3001\u6642\u523b\u5408\u308f\u305b\u306f\u300cYYMMDDhhmmss\uff0bCR(&#8216;\\r&#8217;)\u300d\u306e\u5f62\u5f0f\u3067UART\u306b\u66f8\u8fbc\u3081\u3070\u540c\u671f\u3057\u307e\u3059\u3002<\/p>\n<p>\u5168\u4f53\u306e\u5199\u771f<\/p>\n<div id=\"attachment_577\" style=\"width: 310px\" class=\"wp-caption alignnone\"><a href=\"http:\/\/goji2100.com\/blog\/wp-content\/uploads\/2015\/11\/IMG_1848.jpg\"><img loading=\"lazy\" decoding=\"async\" aria-describedby=\"caption-attachment-577\" class=\"size-medium wp-image-577\" src=\"http:\/\/goji2100.com\/blog\/wp-content\/uploads\/2015\/11\/IMG_1848-300x244.jpg\" alt=\"Arduino 7SEG \u6642\u8a08\u5168\u4f53\" width=\"300\" height=\"244\" srcset=\"http:\/\/goji2100.com\/blog\/wp-content\/uploads\/2015\/11\/IMG_1848-300x244.jpg 300w, http:\/\/goji2100.com\/blog\/wp-content\/uploads\/2015\/11\/IMG_1848-1024x833.jpg 1024w, http:\/\/goji2100.com\/blog\/wp-content\/uploads\/2015\/11\/IMG_1848.jpg 1961w\" sizes=\"(max-width: 300px) 100vw, 300px\" \/><\/a><p id=\"caption-attachment-577\" class=\"wp-caption-text\">Arduino 7SEG \u6642\u8a08\u5168\u4f53<\/p><\/div>\n<p><!--more \u3010\u7d9a\u304d\u3092\u8aad\u3080\u3011-->7Seg LED(BW428G-E1-10MM\uff1a\u30ab\u30bd\u30fc\u30c9\u30b3\u30e2\u30f3)\u306e\u30d4\u30f3\u914d\u5217\u5199\u771f<\/p>\n<div id=\"attachment_578\" style=\"width: 272px\" class=\"wp-caption alignnone\"><a href=\"http:\/\/goji2100.com\/blog\/wp-content\/uploads\/2015\/11\/7SEG.png\"><img loading=\"lazy\" decoding=\"async\" aria-describedby=\"caption-attachment-578\" class=\"wp-image-578 size-medium\" src=\"http:\/\/goji2100.com\/blog\/wp-content\/uploads\/2015\/11\/7SEG-262x300.png\" alt=\"7SEG \u30d4\u30f3\u914d\u5217\" width=\"262\" height=\"300\" srcset=\"http:\/\/goji2100.com\/blog\/wp-content\/uploads\/2015\/11\/7SEG-262x300.png 262w, http:\/\/goji2100.com\/blog\/wp-content\/uploads\/2015\/11\/7SEG.png 320w\" sizes=\"(max-width: 262px) 100vw, 262px\" \/><\/a><p id=\"caption-attachment-578\" class=\"wp-caption-text\">7SEG \u30d4\u30f3\u914d\u5217<\/p><\/div>\n<div id=\"attachment_649\" style=\"width: 310px\" class=\"wp-caption alignnone\"><a href=\"http:\/\/goji2100.com\/blog\/wp-content\/uploads\/2015\/11\/7SEG1.png\"><img loading=\"lazy\" decoding=\"async\" aria-describedby=\"caption-attachment-649\" class=\"wp-image-649 size-medium\" src=\"http:\/\/goji2100.com\/blog\/wp-content\/uploads\/2015\/11\/7SEG1-300x177.png\" alt=\"7SEG\u914d\u7f6e\" width=\"300\" height=\"177\" srcset=\"http:\/\/goji2100.com\/blog\/wp-content\/uploads\/2015\/11\/7SEG1-300x177.png 300w, http:\/\/goji2100.com\/blog\/wp-content\/uploads\/2015\/11\/7SEG1.png 320w\" sizes=\"(max-width: 300px) 100vw, 300px\" \/><\/a><p id=\"caption-attachment-649\" class=\"wp-caption-text\">7SEG\u914d\u7f6e<\/p><\/div>\n<p>7Seg LED(BW428G-E1-10MM)\u306e\u63a5\u7d9a\u5199\u771f(D2\uff5eD13\u306b\u76f4\u63a5\u523a\u3057\u3066\u3044\u307e\u3059)<\/p>\n<div id=\"attachment_579\" style=\"width: 310px\" class=\"wp-caption alignnone\"><a href=\"http:\/\/goji2100.com\/blog\/wp-content\/uploads\/2015\/11\/IMG_1887.jpg\"><img loading=\"lazy\" decoding=\"async\" aria-describedby=\"caption-attachment-579\" class=\"size-medium wp-image-579\" src=\"http:\/\/goji2100.com\/blog\/wp-content\/uploads\/2015\/11\/IMG_1887-300x254.jpg\" alt=\"7SEG LED\u306e\u63a5\u7d9a\u5199\u771f\" width=\"300\" height=\"254\" srcset=\"http:\/\/goji2100.com\/blog\/wp-content\/uploads\/2015\/11\/IMG_1887-300x254.jpg 300w, http:\/\/goji2100.com\/blog\/wp-content\/uploads\/2015\/11\/IMG_1887-1024x866.jpg 1024w, http:\/\/goji2100.com\/blog\/wp-content\/uploads\/2015\/11\/IMG_1887.jpg 1597w\" sizes=\"(max-width: 300px) 100vw, 300px\" \/><\/a><p id=\"caption-attachment-579\" class=\"wp-caption-text\">7SEG LED\u306e\u63a5\u7d9a\u5199\u771f<\/p><\/div>\n<p>RTC(RX-8025NB)\u30d6\u30ec\u30fc\u30af\u30a2\u30a6\u30c8\u30dc\u30fc\u30c9\u306e\u63a5\u7d9a<\/p>\n<div id=\"attachment_580\" style=\"width: 310px\" class=\"wp-caption alignnone\"><a href=\"http:\/\/goji2100.com\/blog\/wp-content\/uploads\/2015\/11\/K-08585-1.jpg\"><img loading=\"lazy\" decoding=\"async\" aria-describedby=\"caption-attachment-580\" class=\"size-medium wp-image-580\" src=\"http:\/\/goji2100.com\/blog\/wp-content\/uploads\/2015\/11\/K-08585-1-300x294.jpg\" alt=\"RTC\u306e\u63a5\u7d9a\" width=\"300\" height=\"294\" srcset=\"http:\/\/goji2100.com\/blog\/wp-content\/uploads\/2015\/11\/K-08585-1-300x294.jpg 300w, http:\/\/goji2100.com\/blog\/wp-content\/uploads\/2015\/11\/K-08585-1.jpg 320w\" sizes=\"(max-width: 300px) 100vw, 300px\" \/><\/a><p id=\"caption-attachment-580\" class=\"wp-caption-text\">RTC\u306e\u63a5\u7d9a<\/p><\/div>\n<p>\u30b9\u30b1\u30c3\u30c1(Arduino7SEG2.ino)\u3000\uff0a\u30bd\u30fc\u30b9\u884c\u3092\u6e1b\u3089\u3059\u305f\u3081\u306b\u53ef\u8aad\u6027\u3092\u72a0\u7272\u306b\u3057\u3066\u3044\u307e\u3059(*- -)(*_ _)<\/p>\n<pre class=\"lang:arduino decode:true \" title=\"Arduino7SEG2.ino\">#include &lt;Arduino.h&gt;\r\n#include &lt;Wire.h&gt;\r\n\r\n#define RTC_ADDR  0x32\r\n\r\nbyte fontArray[10] = {\r\n\/\/ .gfedcba\r\n  B00111111,  \/\/ 0xC0 '0'    a\r\n  B00000110,  \/\/ 0xF9 '1'  f   b .\r\n  B01011011,  \/\/ 0xA4 '2'    g\r\n  B01001111,  \/\/ 0xB0 '3'  e   c .\r\n  B01100110,  \/\/ 0x99 '4'    d\r\n  B01101101,  \/\/ 0x92 '5'\r\n  B01111101,  \/\/ 0x82 '6'\r\n  B00000111,  \/\/ 0xF8 '7'\r\n  B01111111,  \/\/ 0x80 '8'\r\n  B01101111   \/\/ 0x98 '9'\r\n};\r\n\r\nconst byte segMap[] = {  4,  6, 11,  2,  3,  5,  8, 12 };\r\nconst byte digMap[] = { 13, 10,  9,  7 };\r\nbyte Dates[6] = { 100, 12, 31, 12, 34, 60 };\r\nbyte rtc_OK;\r\n\r\nvoid rtc_read(byte *d)\r\n{\r\n  Wire.requestFrom(RTC_ADDR, 8);\r\n  for (int i = 5; i &gt;= 0; i--) {\r\n    if ((i == 5) || (i == 2)) Wire.read();  \/\/ skip 0x0F and 0x03\r\n    byte w = Wire.read();\r\n    *(d + i)  = ((w &gt;&gt; 4) * 10) + (w &amp; 15);\r\n  }\r\n}\r\n\r\nvoid rtc_write(byte *d)\r\n{\r\n  Wire.beginTransmission(RTC_ADDR);\r\n  for (int i = 5; i &gt;= 0; i--) {\r\n    if ((i == 5) || (i == 2)) Wire.write(0x00); \/\/ dummy 0x0F and 0x03\r\n    byte w = *(d + i);\r\n    Wire.write(((w \/ 10) &lt;&lt; 4) | (w % 10));\r\n  }\r\n  Wire.endTransmission();\r\n}\r\n\r\nint times_chk() {\r\n  int rc = 9;\r\n\r\n  if (Dates[0] &gt; 99) Dates[rc = 0] = 15; \/\/ YY &gt; Light check because the date is not used\r\n  if (Dates[1] &gt; 12) Dates[rc = 1] = 12; \/\/ MM &gt; ..\r\n  if (Dates[2] &gt; 31) Dates[rc = 2] = 31; \/\/ DD &gt; ..\r\n  if (Dates[3] &gt; 23) Dates[rc = 3] = 23; \/\/ hh\r\n  if (Dates[4] &gt; 59) Dates[rc = 4] = 59; \/\/ mm\r\n  if (Dates[5] &gt; 59) Dates[rc = 5] = 59; \/\/ ss\r\n  return(rc);\r\n}\r\n\r\nvoid setup(void) {\r\n  Serial.begin(115200);\r\n  pinMode(17, OUTPUT); digitalWrite(17, LOW);\r\n  pinMode(16, OUTPUT); digitalWrite(16, HIGH);\r\n  for (int i = 0; i &lt; 4; i++) pinMode(digMap[i], OUTPUT), digitalWrite(digMap[i], HIGH);\r\n  for (int i = 0; i &lt; 8; i++) pinMode(segMap[i], OUTPUT), digitalWrite(segMap[i], LOW);\r\n\r\n  Wire.begin();\r\n  delay(80);\r\n  Wire.beginTransmission(RTC_ADDR);\r\n  byte RTC_init[] = { 0xE0, 0x22, 0x00 };              \/\/151121\r\n  for (int i = 0; i &lt; 3; i++) Wire.write(RTC_init[i]); \/\/151121\r\n  Wire.endTransmission();\r\n  delay(20);\r\n\r\n  rtc_read(Dates);\r\n  if (times_chk() != 9) rtc_write(Dates);\r\n  Dates[0] = 100;\r\n  rtc_read(Dates);\r\n  rtc_OK = (times_chk() == 9);\r\n}\r\n\r\nvoid loop(void) {\r\n  int i, j, p = 0;\r\n  byte sbuff[12], w, x, y, z;\r\n  unsigned long pre_ms = millis() + 1000, temp_ms;\r\n\r\n  while  (1) {\r\n    if (Serial.available()) {\r\n      unsigned char b = Serial.read();\r\n      if ((b &gt;= '0') &amp;&amp; (b &lt;= '9') &amp;&amp; (p &lt; 12)) sbuff[p++] = b;\r\n      if (b == '\\r') {\r\n        if (p == 12) {\r\n          for (p = j = 0; j &lt; 6; j++)\r\n            Dates[j] = ((sbuff[j + j] &amp; 0x0F) * 10) + (sbuff[j + j + 1] &amp; 0x0F);\r\n          times_chk();\r\n          if (rtc_OK) rtc_write(Dates);\r\n          pre_ms = millis() + 1000;\r\n        }\r\n        for (j = 0; j &lt; 6; j++)\r\n          Serial.print(Dates[j]), Serial.print(\"\/\\0\/\\0 \\0:\\0:\\0\\n\" + j + j);\r\n      }\r\n    }\r\n\r\n    if ((temp_ms = millis()) &gt;= pre_ms) {\r\n      pre_ms = temp_ms + 1000 - (temp_ms - pre_ms);\r\n      if (                  ++Dates[5] &gt; 59)\r\n        if (Dates[5] = 0,   ++Dates[4] &gt; 59)\r\n          if (Dates[4] = 0, ++Dates[3] &gt; 23) Dates[3] = 0;\r\n      if ((Dates[5] == 0) &amp;&amp; (rtc_OK)) rtc_read(Dates);\r\n    }\r\n\r\n    for (i = 0; i &lt; 4; i++) {\r\n      if (i) digitalWrite(digMap[i - 1], HIGH);\r\n      digitalWrite(segMap[0], w = (((i == 1) &amp;&amp; ((pre_ms - millis()) &lt; 500)) ? 3 : 0));\r\n      j = ((i &amp; 1) ? (Dates[3 + (i &gt;&gt; 1)] % 10) : (Dates[3 + (i &gt;&gt; 1)] \/ 10));\r\n      for (x = 0x40, y = 1; y &lt; 8; x &gt;&gt;= 1, y++, w += z)\r\n        digitalWrite(segMap[y], z = ((fontArray[j] &amp; x) ? 1 : 0));\r\n      digitalWrite(digMap[i], LOW);\r\n      delayMicroseconds(w * 500);\r\n    }\r\n    digitalWrite(digMap[3], HIGH);\r\n  }\r\n}\r\n<\/pre>\n","protected":false},"excerpt":{"rendered":"<p>\u90e8\u54c1\u7bb1\u3067\u7720\u3063\u3066\u3044\u308bArduino\u306b\u5b89\u30447Seg LED\u3092\u63a5\u7d9a\u3057\u3066\u30c7\u30b8\u30bf\u30eb\u6642\u8a08\u3092\u4f5c\u308a\u307e\u3059\u3002 \u7c21\u5358\u306b\u3059\u308b\u305f\u3081\u306b4\u6841(12:34)\u306eLED(4\u68417\u30bb\u30b0LED\u8868\u793a\u5668 [BW428G-E1-10MM])\u3092\u4f7f\u3044\u307e\u3059\u3002 Arduino [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[7,31],"tags":[],"_links":{"self":[{"href":"http:\/\/goji2100.com\/blog\/index.php?rest_route=\/wp\/v2\/posts\/576"}],"collection":[{"href":"http:\/\/goji2100.com\/blog\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/goji2100.com\/blog\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/goji2100.com\/blog\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"http:\/\/goji2100.com\/blog\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=576"}],"version-history":[{"count":31,"href":"http:\/\/goji2100.com\/blog\/index.php?rest_route=\/wp\/v2\/posts\/576\/revisions"}],"predecessor-version":[{"id":1508,"href":"http:\/\/goji2100.com\/blog\/index.php?rest_route=\/wp\/v2\/posts\/576\/revisions\/1508"}],"wp:attachment":[{"href":"http:\/\/goji2100.com\/blog\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=576"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/goji2100.com\/blog\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=576"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/goji2100.com\/blog\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=576"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}