{"id":230,"date":"2017-06-28T17:33:03","date_gmt":"2017-06-28T08:33:03","guid":{"rendered":"http:\/\/home.hiroshima-u.ac.jp\/~tigawa\/?p=230"},"modified":"2019-10-17T22:18:49","modified_gmt":"2019-10-17T13:18:49","slug":"%e3%80%90arduino%e3%80%91%e5%a3%81%e3%82%b9%e3%82%a4%e3%83%83%e3%83%81%e3%81%ab%e3%82%bf%e3%82%a4%e3%83%9e%e3%83%bc%e3%82%92%e4%bb%98%e3%81%91%e3%82%8b","status":"publish","type":"post","link":"https:\/\/home.hiroshima-u.ac.jp\/~tigawa\/?p=230","title":{"rendered":"[arduino][breeding]\u58c1\u30b9\u30a4\u30c3\u30c1\u306b\u30bf\u30a4\u30de\u30fc\u3092\u4ed8\u3051\u308b"},"content":{"rendered":"<p>\u751f\u7269\u3092\u5ba4\u5185\u3067\u98fc\u80b2\u3059\u308b\u305f\u3081\u306b\u306f\u65e5\u5468\u671f\u3092\u30b3\u30f3\u30c8\u30ed\u30fc\u30eb\u3059\u308b\u305f\u3081\u306b\u3001\u30e9\u30a4\u30c8\u306eON\/OFF\u3092\u6bce\u65e5\u884c\u3046\u5fc5\u8981\u304c\u3042\u308a\u307e\u3059\u3002\u3088\u304f\u3084\u308b\u306e\u306f\u30b3\u30f3\u30bb\u30f3\u30c8\u306b\u30bf\u30a4\u30de\u30fc\u3092\u304b\u307e\u305b\u3066\u3001\u30e9\u30a4\u30c8\u306eON\/OFF\u3092\u30b3\u30f3\u30c8\u30ed\u30fc\u30eb\u3059\u308b\u3082\u306e\u3067\u3059\u304c\u3001\u90e8\u5c4b\u306e\u58c1\u30b9\u30a4\u30c3\u30c1\u3084\u3001\u6a5f\u5668\u306b\u5099\u3048\u4ed8\u3051\u306e\u30b9\u30a4\u30c3\u30c1\u3092ON\/OFF\u3059\u308b\u306b\u306f\u96fb\u6c17\u5de5\u4e8b\u3084\u672c\u683c\u7684\u306a\u6539\u9020\u304c\u5fc5\u8981\u306b\u306a\u308a\u307e\u3059\u3002\u3057\u304b\u3057\u3001\u3084\u308a\u305f\u3044\u3053\u3068\u306f\u5358\u7d14\u306a\u306e\u306b\u5927\u639b\u304b\u308a\u306a\u5de5\u4e8b\u3084\u9ad8\u984d\u306a\u6539\u9020\u8cbb\u3092\u8981\u6c42\u3055\u308c\u308b\u306e\u306f\u3001\u975e\u5e38\u306b\u6b8b\u5ff5\u3067\u3059\u3002<\/p>\n<p>\u305d\u3053\u3067\u3001\u518d\u3073arduino\u3068\u30b5\u30fc\u30dc\u30e2\u30fc\u30bf\u30fc\uff08\u89d2\u5ea6\u8abf\u6574\u306e\u3067\u304d\u308b\u30e2\u30fc\u30bf\u30fc\uff09\u3092\u5229\u7528\u3057\u3066\u3001\u7269\u7406\u7684\u306b\u30b9\u30a4\u30c3\u30c1\u3092ON\/OFF\u3059\u308b\u3060\u3051\u306e\u30b7\u30f3\u30d7\u30eb\u306a\u30bf\u30a4\u30de\u30fc\u3092\u4f5c\u308a\u307e\u3057\u305f\u3002<\/p>\n<p>arduino\u306f\u975e\u5e38\u306b\u81ea\u7531\u5ea6\u306e\u9ad8\u3044\u30de\u30a4\u30b3\u30f3\u3067\u69d8\u3005\u306a\u3053\u3068\u304c\u53ef\u80fd\u3067\u3059\u304c\u3001\u82e6\u624b\u306a\u3053\u3068\u306e\u4e00\u3064\u306f\u3001\u610f\u5916\u306b\u3082\u6642\u9593\u3092\u8a2d\u5b9a\u3057\u305f\u5358\u7d14\u306a\u30bf\u30a4\u30de\u30fc\u51e6\u7406\u3067\u3059\u3002\u3068\u3044\u3046\u306e\u3082\u3001arduino\u306e\u5185\u90e8\u6642\u8a08\u306f\u975e\u5e38\u306b\u7cbe\u5ea6\u304c\u60aa\u304f\u3001\u65e5\u5dee\u3067\u30821\u5206\u4ee5\u4e0a\u305a\u308c\u308b\u5834\u5408\u304c\u3042\u308a\u307e\u3059\u3002\u305d\u3053\u3067\u3001\u4eca\u56de\u306farudino\u306b\u52a0\u3048\u3066\u3001\u6642\u8a08\u30e2\u30b8\u30e5\u30fc\u30eb\uff08<a href=\"http:\/\/amzn.to\/2smRKMP\">zs-042<\/a>\uff09\u3092\u5229\u7528\u3057\u307e\u3057\u305f\u3002\u6642\u8a08\u30e2\u30b8\u30e5\u30fc\u30eb\u306f200\u5186\u7a0b\u5ea6\u3001\u4eca\u56de\u306farduino\u3082300\u5186\u7a0b\u5ea6\u8cb7\u3048\u308b<a href=\"http:\/\/amzn.to\/2tl6Who\">aruduino nano<\/a>(300\u5186\u7a0b\u5ea6\uff09\u306b\u3057\u305f\u306e\u3067\u3001\u30b5\u30fc\u30dc\u3092\u9664\u3051\u3070\u4e2d\u5fc3\u7684\u306a\u96fb\u5b50\u57fa\u677f\u306f500\u5186\u7a0b\u5ea6\u3067\u8cfc\u5165\u3067\u304d\u307e\u3059\u3002\u30b5\u30fc\u30dc\u306farudino\u306e\u96fb\u6d41\u3067\u3082\u5341\u5206\u5229\u7528\u53ef\u80fd\u306a\u3001<a href=\"http:\/\/amzn.to\/2tl9UCy\">\u30de\u30a4\u30af\u30ed\u30b5\u30fc\u30dc\uff08SG90\uff09<\/a>\u3092\u5229\u7528\u3057\u307e\u3057\u305f\u3002<\/p>\n<p>\u30d0\u30c3\u30c6\u30ea\u30fc\u3067\u306e\u904b\u7528\u3082\u8003\u3048\u3066\u3001\u6642\u8a08\u30e2\u30b8\u30e5\u30fc\u30eb\u306b\u8a2d\u5b9a\u3057\u305f\u30a2\u30e9\u30fc\u30c8\u30671\u6642\u9593\u3054\u3068\u306barduino\u3092\u8d77\u52d5\u3055\u305b\uff08\u305d\u306e\u9593\u3001arudino\u306f\u30b9\u30ea\u30fc\u30d7\u72b6\u614b\uff09\u3001\u305d\u306e\u969b\u306b\u30a2\u30e9\u30fc\u30c8\u304c\u8a2d\u5b9a\u3057\u305f\u6642\u523b\u3067\u3042\u308c\u3070\u30b5\u30fc\u30dc\u3092\u8d77\u52d5\u3057\u3066ON\u3042\u308b\u3044\u306fOFF\u306b\u30b9\u30a4\u30c3\u30c1\u3092\u52d5\u304b\u3059\u3068\u3044\u3046\u3053\u3068\u306b\u3057\u307e\u3057\u305f\u3002<\/p>\n<p>\u30b9\u30b1\u30c3\u30c1\u306f\u6b21\u306e\u901a\u308a\u3002<\/p>\n<pre class=\"lang:default decode:true\">#include &lt;Time.h&gt;\r\n#include &lt;TimeLib.h&gt;\r\n#include &lt;DS3232RTC.h&gt;\r\n#include &lt;Wire.h&gt;  \r\n#include &lt;avr\/sleep.h&gt;\r\n#include &lt;avr\/power.h&gt;\r\n#include &lt;avr\/interrupt.h&gt;\r\n#include &lt;Servo.h&gt;\r\n\r\nboolean restart = false;\r\nvolatile boolean alarmIsrWasCalled = false;\r\nServo myservo;  \/\/ create servo object to control a servo \r\n \r\nvoid setup() {\r\n \r\n  \/\/ Serial \u306e\u8a2d\u5b9a\r\n  Serial.begin(9600);\r\n \r\n  \/\/ RTC Time \u306e\u8a2d\u5b9a\r\n  setSyncProvider(RTC.get);\r\n  setTime(RTC.get());\r\n \r\n  \/\/ Alarm \u8a2d\u5b9a\r\n  RTC.alarmInterrupt(1, false);\r\n  RTC.alarmInterrupt(2, false);\r\n  \r\n\r\n  RTC.alarm(ALARM_2);\r\n\/\/\u4e00\u6642\u9593\u306b\u4e00\u56de\u8d77\u304d\u308b\u3002\r\n  RTC.setAlarm(ALM2_MATCH_MINUTES , 00, 00, 0, 0);\r\n  RTC.alarmInterrupt(ALARM_2, true);\r\n  \r\n  attachInterrupt(0, wakeup, FALLING);\r\n}\r\n \r\n \r\nvoid loop() {\r\n\/\/\u4e00\u6642\u9593\u3054\u3068\u306b\u8d77\u52d5\u3057\u3066\u6642\u8a08\u5408\u308f\u305b\u3092\u3059\u308b\u3002\u6642\u9593\u306b\u306a\u3063\u3066\u3044\u308c\u3070\u30b5\u30fc\u30dc\u3092\u4f5c\u52d5\u3055\u305b\u308b\u3002\r\n  if (restart) {\r\n    if (RTC.alarm(ALARM_2)) {\r\n      setTime(RTC.get());\r\n      \/\/digitalClockDisplay();\r\n      if (hour() == 8) {\r\n        myservo.attach(9);\r\n        moveservoDown();\r\n        myservo.detach();\r\n        }\r\n      if (hour() == 20) {\r\n        myservo.attach(9);\r\n        moveservoUp();\r\n        myservo.detach();\r\n       }\r\n      }\r\n    \r\n    restart = false;\r\n  }\r\n \r\n  delay(1000);\r\n  goToBed();\r\n}\r\n\r\nvoid digitalClockDisplay(void)\r\n{\r\n  \/\/ digital clock display of the time\r\n  setSyncProvider(RTC.get); \/\/sync time with RTC\r\n  Serial.print(hour());\r\n  printDigits(minute());\r\n  printDigits(second());\r\n  Serial.print(' ');\r\n  Serial.print(day());\r\n  Serial.print(' ');\r\n  Serial.print(month());\r\n  Serial.print(' ');\r\n  Serial.print(year());\r\n  Serial.println();\r\n  Serial.flush();\r\n}\r\n\r\nvoid moveservoUp(void)\r\n{\r\n    myservo.write(107);              \/\/ tell servo to go to position in variable 'pos'\r\n    delay(1000);                       \/\/ waits 15ms for the servo to reach the position\r\n    myservo.write(90);              \/\/ tell servo to go to position in variable 'pos'\r\n    delay(1000);                       \/\/ waits 15ms for the servo to reach the position\r\n}\r\n\r\nvoid moveservoDown(void)\r\n{\r\n    myservo.write(73);              \/\/ tell servo to go to position in variable 'pos'\r\n    delay(1000);                       \/\/ waits 15ms for the servo to reach the position\r\n    myservo.write(90);              \/\/ tell servo to go to position in variable 'pos'\r\n    delay(1000);                       \/\/ waits 15ms for the servo to reach the position\r\n}\r\n\r\n\r\nvoid printDigits(int digits)\r\n{\r\n  \/\/ utility function for digital clock display: prints preceding colon and leading 0\r\n  Serial.print(':');\r\n  if (digits &lt; 10)\r\n    Serial.print('0');\r\n  Serial.print(digits);\r\n}\r\nvoid goToBed() {\r\n  set_sleep_mode(SLEEP_MODE_PWR_DOWN);\r\n  sleep_enable();\r\n  sleep_mode();\r\n  sleep_disable();\r\n  power_all_enable();\r\n}\r\n \r\n \r\n\/\/ \u8d77\u52d5\r\nvoid wakeup() {\r\n  restart = true;\r\n}<\/pre>\n","protected":false},"excerpt":{"rendered":"<p>\u751f\u7269\u3092\u5ba4\u5185\u3067\u98fc\u80b2\u3059\u308b\u305f\u3081\u306b\u306f\u65e5\u5468\u671f\u3092\u30b3\u30f3<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"colormag_page_container_layout":"default_layout","colormag_page_sidebar_layout":"default_layout","_locale":"ja","_original_post":"230","footnotes":""},"categories":[7],"tags":[15,17],"class_list":["post-230","post","type-post","status-publish","format-standard","hentry","category-protocol","tag-arduno","tag-breeding-amphibians","ja"],"_links":{"self":[{"href":"https:\/\/home.hiroshima-u.ac.jp\/~tigawa\/index.php?rest_route=\/wp\/v2\/posts\/230","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/home.hiroshima-u.ac.jp\/~tigawa\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/home.hiroshima-u.ac.jp\/~tigawa\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/home.hiroshima-u.ac.jp\/~tigawa\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/home.hiroshima-u.ac.jp\/~tigawa\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=230"}],"version-history":[{"count":6,"href":"https:\/\/home.hiroshima-u.ac.jp\/~tigawa\/index.php?rest_route=\/wp\/v2\/posts\/230\/revisions"}],"predecessor-version":[{"id":1086,"href":"https:\/\/home.hiroshima-u.ac.jp\/~tigawa\/index.php?rest_route=\/wp\/v2\/posts\/230\/revisions\/1086"}],"wp:attachment":[{"href":"https:\/\/home.hiroshima-u.ac.jp\/~tigawa\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=230"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/home.hiroshima-u.ac.jp\/~tigawa\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=230"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/home.hiroshima-u.ac.jp\/~tigawa\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=230"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}