{"id":597,"date":"2012-03-15T01:25:41","date_gmt":"2012-03-14T16:25:41","guid":{"rendered":"https:\/\/blog.eldhrimnir.com?p=597"},"modified":"2013-08-04T13:14:25","modified_gmt":"2013-08-04T04:14:25","slug":"arduino%e3%81%ae%e3%82%a2%e3%83%8a%e3%83%ad%e3%82%b0%e3%83%94%e3%83%b31%e3%81%a4%e3%81%a75ch%e3%81%ae%e3%82%b9%e3%82%a4%e3%83%83%e3%83%81","status":"publish","type":"post","link":"https:\/\/blog.eldhrimnir.com\/?p=597","title":{"rendered":"Arduino\u306e\u30a2\u30ca\u30ed\u30b0\u30d4\u30f31\u3064\u30675ch\u306e\u30b9\u30a4\u30c3\u30c1"},"content":{"rendered":"<p>\u6d77\u5916\u88fd\u306eLCD\u30c7\u30a3\u30b9\u30d7\u30ec\u30a4\u30b7\u30fc\u30eb\u30c9\u306e\u56de\u8def\u56f3\u3092\u773a\u3081\u3066\u3044\u305f\u3089\u30a2\u30ca\u30ed\u30b0\u30d4\u30f3\uff11\u3064\u30675ch\u306e\u30b9\u30a4\u30c3\u30c1\u3092\u5b9f\u73fe\u3057\u3066\u3044\u308b\u3063\u307d\u3044\u306e\u3067\u30d6\u30ec\u30c3\u30c9\u30dc\u30fc\u30c9\u3067\u4f5c\u3063\u3066\u307f\u307e\u3057\u305f\u3002\u8a66\u3057\u3066\u307f\u305f\u611f\u60f3\u3068\u3057\u3066\u306f1\u54c1\u3060\u3051\u3067\u4f7f\u3048\u308b\u306e\u3067\u4fbf\u5229\u3067\u3059\u3002\u4f55\u304b\u4f5c\u308b\u3068\u304d\u306b\u306f\u5fdc\u7528\u3068\u3057\u3066\u4f7f\u304a\u3046\u3068\u601d\u3044\u307e\u3059\u3002<\/p>\n<p><a href=\"https:\/\/blog.eldhrimnir.comwp-content\/uploads\/2012\/03\/DSC08502-res.jpg\"><img loading=\"lazy\" decoding=\"async\" class=\"alignnone  wp-image-603\" title=\"SONY DSC\" alt=\"\" src=\"https:\/\/blog.eldhrimnir.comwp-content\/uploads\/2012\/03\/DSC08502-res.jpg\" width=\"494\" height=\"278\" \/><\/a><\/p>\n<p><!--more--><\/p>\n<p><strong>\u56de\u8def\u56f3<\/strong><\/p>\n<p><a href=\"https:\/\/blog.eldhrimnir.comwp-content\/uploads\/2012\/03\/5ch_sw.bmp\"><img loading=\"lazy\" decoding=\"async\" class=\"alignnone  wp-image-598\" title=\"5ch_sw\" alt=\"\" src=\"https:\/\/blog.eldhrimnir.comwp-content\/uploads\/2012\/03\/5ch_sw.bmp\" width=\"600\" height=\"450\" \/><\/a><\/p>\n<p>\u30b9\u30b1\u30c3\u30c1<br \/>\n[code]<br \/>\n\/\/example use of LCD4Bit_mod library<br \/>\n#include &lt;stdio.h&gt;<\/p>\n<p>\/\/Key message<br \/>\nchar msgs[5][15] = {&quot;Right Key OK &quot;,<br \/>\n                    &quot;Up Key OK    &quot;,<br \/>\n                    &quot;Down Key OK  &quot;,<br \/>\n                    &quot;Left Key OK  &quot;,<br \/>\n                    &quot;Select Key OK&quot; };<br \/>\nint adc_key_val[5] ={30, 150, 360, 535, 760 };<br \/>\nstatic uint8_t NUM_KEYS = 5;<br \/>\nint adc_key_in;<br \/>\nint key=-1;<br \/>\nstatic uint8_t oldkey=-1;<\/p>\n<p>void setup() {<br \/>\n  \/\/ Setup Serial<br \/>\n  Serial.begin(19200);<\/p>\n<p>  Serial.println(&quot;KEYPAD testing&#8230; pressing&quot;);<\/p>\n<p>}<\/p>\n<p>void loop() {<\/p>\n<p>  adc_key_in = analogRead(0);    \/\/ read the value from the sensor<br \/>\n  digitalWrite(13, HIGH);<br \/>\n  key = get_key(adc_key_in);\t\t        \/\/ convert into key press<\/p>\n<p>    if (key != oldkey)\t\t\t\t    \/\/ if keypress is detected<br \/>\n      {<br \/>\n      delay(50);\t\t\/\/ wait for debounce time<br \/>\n      adc_key_in = analogRead(0);    \/\/ read the value from the sensor<br \/>\n      key = get_key(adc_key_in);\t\t        \/\/ convert into key press<br \/>\n      if (key != oldkey)<br \/>\n        {<br \/>\n        oldkey = key;<br \/>\n        if (key &gt;=0)<br \/>\n          {<br \/>\n        Serial.println(msgs[key]);<br \/>\n          }<br \/>\n        }<br \/>\n      }<\/p>\n<p>  \/\/delay(1000);<br \/>\n  digitalWrite(13, LOW);<br \/>\n}<\/p>\n<p>\/\/ Convert ADC value to key number<br \/>\nint get_key(unsigned int input){<br \/>\n  int k;<\/p>\n<p>  for (k = 0; k &lt; NUM_KEYS; k++){<br \/>\n    if (input &lt; adc_key_val[k]){<br \/>\n      return k;<br \/>\n    }<br \/>\n  }<\/p>\n<p>  if (k &gt;= NUM_KEYS) k = -1;     \/\/ No valid key pressed<br \/>\n    return k;<br \/>\n}<\/p>\n<p>[\/code]<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u6d77\u5916\u88fd\u306eLCD\u30c7\u30a3\u30b9\u30d7\u30ec\u30a4\u30b7\u30fc\u30eb\u30c9\u306e\u56de\u8def\u56f3\u3092\u773a\u3081\u3066\u3044\u305f\u3089\u30a2\u30ca\u30ed\u30b0\u30d4\u30f3\uff11\u3064\u30675ch\u306e\u30b9\u30a4\u30c3\u30c1\u3092\u5b9f\u73fe\u3057\u3066\u3044\u308b\u3063\u307d\u3044\u306e\u3067\u30d6\u30ec\u30c3\u30c9\u30dc\u30fc\u30c9\u3067\u4f5c\u3063\u3066\u307f\u307e\u3057\u305f\u3002\u8a66\u3057\u3066\u307f\u305f\u611f\u60f3\u3068\u3057\u3066\u306f1\u54c1\u3060\u3051\u3067\u4f7f\u3048\u308b\u306e\u3067\u4fbf\u5229\u3067\u3059\u3002\u4f55\u304b\u4f5c\u308b\u3068\u304d\u306b\u306f\u5fdc\u7528\u3068 [&hellip;]<\/p>\n","protected":false},"author":3,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[13],"tags":[],"_links":{"self":[{"href":"https:\/\/blog.eldhrimnir.com\/index.php?rest_route=\/wp\/v2\/posts\/597"}],"collection":[{"href":"https:\/\/blog.eldhrimnir.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/blog.eldhrimnir.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/blog.eldhrimnir.com\/index.php?rest_route=\/wp\/v2\/users\/3"}],"replies":[{"embeddable":true,"href":"https:\/\/blog.eldhrimnir.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=597"}],"version-history":[{"count":0,"href":"https:\/\/blog.eldhrimnir.com\/index.php?rest_route=\/wp\/v2\/posts\/597\/revisions"}],"wp:attachment":[{"href":"https:\/\/blog.eldhrimnir.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=597"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/blog.eldhrimnir.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=597"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/blog.eldhrimnir.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=597"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}