{"id":1757,"date":"2013-02-02T17:52:08","date_gmt":"2013-02-02T08:52:08","guid":{"rendered":"http:\/\/www.pinewell.jp\/wordpress\/?p=1757"},"modified":"2013-02-02T17:52:08","modified_gmt":"2013-02-02T08:52:08","slug":"raspberrypi%e3%81%ab%e3%82%b9%e3%83%bc%e3%83%91%e3%83%bc%e3%83%95%e3%82%a1%e3%83%9f%e3%82%b3%e3%83%b3%e3%81%ae%e3%82%b3%e3%83%b3%e3%83%88%e3%83%ad%e3%83%bc%e3%83%a9%e3%82%92%e7%b9%8b%e3%81%90%e3%80%82","status":"publish","type":"post","link":"https:\/\/www.pinewell.jp\/wordpress\/?p=1757","title":{"rendered":"RaspberryPi\u306b\u30b9\u30fc\u30d1\u30fc\u30d5\u30a1\u30df\u30b3\u30f3\u306e\u30b3\u30f3\u30c8\u30ed\u30fc\u30e9\u3092\u7e4b\u3050\u3002"},"content":{"rendered":"<p>PS2\u306e\u30b3\u30f3\u30c8\u30ed\u30fc\u30e9\u3092\u7e4b\u304e\u305f\u304b\u3063\u305f\u306e\u3060\u304c\u3001Arduino\u7528\u306e\u30b5\u30f3\u30d7\u30eb\u306e\u307f\u3067\u6577\u5c45\u304c\u9ad8\u304b\u3063\u305f\u3002<br \/>\n\u30a2\u30ca\u30ed\u30b0\u90e8\u5206\u306f\u4f7f\u308f\u306a\u3044\u306e\u3067\u3001\u201d\u30d4\u30b3\u30fc\u30f3\uff01\u201d\u3068\u9583\u3044\u305f\u3002\u30b9\u30fc\u30d1\u30fc\u30d5\u30a1\u30df\u30b3\u30f3\u306e\u30b3\u30f3\u30c8\u30ed\u30fc\u30e9\u306a\u3089\u3082\u3063\u3068\u7c21\u5358\u3058\u3083\u306d?\u3068\u3002<\/p>\n<p>\u3067\u3001\u691c\u7d22\u3057\u3066\u307f\u308b\u3068\u30b5\u30f3\u30d7\u30eb\u3063\u307d\u3044\u3082\u306e\u3002\u3055\u3089\u306b\u3001Arduino\u306b\u7e4b\u3050library\u304c\u3068\u3066\u3082\u7c21\u6f54\u3067\u308f\u304b\u308a\u3084\u3059\u3044\u3002<br \/>\n\u306e\u3067\u3001\u30cf\u30fc\u30c9\u30aa\u30d5\u306b\u3066\u30c9\u30ca\u30fc\u3068\u306a\u308b\u30b3\u30f3\u30c8\u30ed\u30fc\u30e9\u3092\u30b2\u30c3\u30c8\u30021\u3064105\u5186\u3002<br \/>\n\u30b8\u30e3\u30f3\u30af\u672c\u4f53\u3067\u3082\u3042\u308c\u3070\u5c1a\u826f\u304b\u3063\u305f\u306e\u3060\u304c\u3001\u305d\u308c\u306f\u7121\u304b\u3063\u305f\u3002\u3082\u3046\u6271\u3063\u3066\u306a\u3044\u306e\u3060\u308d\u3046\u304b\u3002\uff08\u30b8\u30e3\u30f3\u30af\u3058\u3083\u7121\u3044\u30e2\u30ce\u306f\u3042\u3063\u305f\uff09<\/p>\n<p>\u3055\u3063\u305d\u304f\u30b3\u30cd\u30af\u30bf\u90e8\u5206\u3092\u3070\u3089\u3057\u3066\u307f\u308b\u3068\u30017pin\u3042\u308a\u305d\u3046\u306a\u30b3\u30cd\u30af\u30bf\u3060\u3063\u305f\u304c\u3001\u5b9f\u969b\u306f5pin\u3002<br \/>\n\u96fb\u6e90\u3068GND\u3001\u305d\u306e\u4ed63pin\u3002Arduino\u306b\u7e4b\u3044\u3067\u52d5\u4f5c\u78ba\u8a8d\u3002\u554f\u984c\u7121\u3057\u3002\u96fb\u6e90\u30923.3V\u306b\u3057\u3066\u307f\u305f\u304c\u3001\u3053\u308c\u3082\u554f\u984c\u7121\u3057\u3002<br \/>\n\u642d\u8f09\u30c1\u30c3\u30d7MC14021\u306e\u30c7\u30fc\u30bf\u30b7\u30fc\u30c8\u3067\u3082\u554f\u984c\u306a\u3055\u305d\u3046\u3060\u3063\u305f\u3002<\/p>\n<p>\u96fb\u6e90\u306fraspi\u306e3.3V\u304b\u3089\u53d6\u5f97\u3002\u30b5\u30b5\u30b5\u30b5\u30c3\u3068\u30b3\u30fc\u30c9\u3092\u66f8\u3044\u3066\u3001raspi\u3067\u306e\u52d5\u4f5c\u3082\u78ba\u8a8d\u3002<br \/>\n\u4ee5\u4e0b\u30bd\u30fc\u30b9<\/p>\n<pre lang=\"C\" line=\"\">\n#include <stdio.h>\n#include <stdlib.h>\n#include <bcm2835.h>\n#include <signal.h>\n#include <string.h>\n#include <strings.h>\n#include <unistd.h>\n\n#define PIN_DATA  RPI_V2_GPIO_P1_13   \/\/Red\n#define PIN_CLOCK RPI_V2_GPIO_P1_11   \/\/Yellow\n#define PIN_LATCH RPI_V2_GPIO_P1_15   \/\/Orange\n                                      \/\/Brown = Ground\n\t\t\t\t      \/\/White = VCC\n#define SFCPAD_B_BTN\t0x0001\n#define SFCPAD_Y_BTN\t0x0002\n#define SFCPAD_SELECT\t0x0004\n#define SFCPAD_START\t0x0008\n#define SFCPAD_UP \t0x0010\n#define SFCPAD_DOWN\t0x0020\n#define SFCPAD_LEFT\t0x0040\n#define SFCPAD_RIGHT\t0x0080\n#define SFCPAD_A_BTN\t0x0100\n#define SFCPAD_X_BTN\t0x0200\n#define SFCPAD_L_BTN\t0x0400\n#define SFCPAD_R_BTN\t0x0800\n\nuint16_t readsfcpad() {\n\tint i;\n\tuint16_t b;\n\tuint16_t d;\n\tuint8_t dataval;\n\n\t\tb = 1;\n\t\td = 0;\n        \tdataval = 1;\n\t\tbcm2835_gpio_write(PIN_LATCH,LOW);\n\t\tusleep(250);\n\t\tfor (i = 0;i < 16;i++ ){\n\t\t\tdataval = bcm2835_gpio_lev(PIN_DATA);\n\t\t\t\/\/printf(\"dataval:%d \\n\",dataval);\n\t\t\tif ( dataval == 0 ) {\n\t\t\t\td = d | b;\n\t\t\t}\n\t\t\tb = b<<1;\n\t\t\tbcm2835_gpio_write(PIN_CLOCK,HIGH);\n\t\t\tusleep(500);\n\t\t\tbcm2835_gpio_write(PIN_CLOCK,LOW);\n\t\t}\t\n\t\tbcm2835_gpio_write(PIN_LATCH,HIGH);\n\treturn d;\n}\n\nint main(int argc,char **argv)\n{\n\t\/\/GPIO\u3092\u521d\u671f\u5316\n\tif (!bcm2835_init()) { \n\t\tprintf(\"bcm2835 init error.\\n\");\n\t\texit(1); \n\t}\n\n\t\/\/PIN\u306e\u8a2d\u5b9a\n\tbcm2835_gpio_fsel(PIN_DATA ,BCM2835_GPIO_FSEL_INPT);\n\tbcm2835_gpio_fsel(PIN_CLOCK,BCM2835_GPIO_FSEL_OUTP);\n\tbcm2835_gpio_fsel(PIN_LATCH,BCM2835_GPIO_FSEL_OUTP);\n\t\n\t\/\/VCC\u307e\u3067\u30d7\u30eb\u30a2\u30c3\u30d7\n\tbcm2835_gpio_set_pud(PIN_DATA,BCM2835_GPIO_PUD_UP);\n\n\t\/\/SFC_PAD \u3068\u306e\u901a\u4fe1\u521d\u671f\u5316\n\tbcm2835_gpio_write(PIN_CLOCK,LOW);\n\tbcm2835_gpio_write(PIN_LATCH,HIGH);\n\n\tuint16_t rd;\n\twhile(1) {\n\t\t\/\/\u30dc\u30bf\u30f3\u306e\u72b6\u614b\u3092\u8aad\u307f\u3001\n\t\trd = readsfcpad();\t\n\t\tif (rd != 0) {\n\t\t\t\/\/\u30d3\u30c3\u30c8\u6f14\u7b97\u306b\u3088\u308a\u3001\u30dc\u30bf\u30f3\u304c\u62bc\u3055\u308c\u3066\u3044\u308b\u304b\n\t\t\tif ( (rd &#038; SFCPAD_B_BTN\t) == SFCPAD_B_BTN)  { printf(\"B\\n\");   }\n\t                if ( (rd &#038; SFCPAD_Y_BTN\t) == SFCPAD_Y_BTN)  { printf(\"Y\\n\");   }\n\t\t\tif ( (rd &#038; SFCPAD_SELECT) == SFCPAD_SELECT) { printf(\"Sel\\n\"); }\n\t\t\tif ( (rd &#038; SFCPAD_START\t) == SFCPAD_START)  { printf(\"Sta\\n\"); }\n\t\t\tif ( (rd &#038; SFCPAD_UP \t) == SFCPAD_UP )    { printf(\"UP\\n\");  }\n\t\t\tif ( (rd &#038; SFCPAD_DOWN\t) == SFCPAD_DOWN)   { printf(\"Do\\n\");  }\n\t\t\tif ( (rd &#038; SFCPAD_LEFT\t) == SFCPAD_LEFT)   { printf(\"Le\\n\");  }\n\t\t\tif ( (rd &#038; SFCPAD_RIGHT\t) == SFCPAD_RIGHT)  { printf(\"Ri\\n\");  }\n\t\t\tif ( (rd &#038; SFCPAD_A_BTN\t) == SFCPAD_A_BTN)  { printf(\"A\\n\");   }\n\t\t\tif ( (rd &#038; SFCPAD_X_BTN\t) == SFCPAD_X_BTN)  { printf(\"X\\n\");   }\n\t\t\tif ( (rd &#038; SFCPAD_L_BTN\t) == SFCPAD_L_BTN)  { printf(\"L\\n\");   }\n\t\t\tif ( (rd &#038; SFCPAD_R_BTN\t) == SFCPAD_R_BTN)  { printf(\"R\\n\");   }\n\t\t}\n\t}\n}\n<\/pre>\n","protected":false},"excerpt":{"rendered":"<p>PS2\u306e\u30b3\u30f3\u30c8\u30ed\u30fc\u30e9\u3092\u7e4b\u304e\u305f\u304b\u3063\u305f\u306e\u3060\u304c\u3001Arduino\u7528\u306e\u30b5\u30f3\u30d7\u30eb\u306e\u307f\u3067\u6577\u5c45\u304c\u9ad8\u304b\u3063\u305f\u3002 \u30a2\u30ca\u30ed\u30b0\u90e8\u5206\u306f\u4f7f\u308f\u306a\u3044\u306e\u3067\u3001\u201d\u30d4\u30b3\u30fc\u30f3\uff01\u201d\u3068\u9583\u3044\u305f\u3002\u30b9\u30fc\u30d1\u30fc\u30d5\u30a1\u30df\u30b3\u30f3\u306e\u30b3\u30f3\u30c8\u30ed\u30fc\u30e9\u306a\u3089\u3082\u3063\u3068\u7c21\u5358\u3058\u3083\u306d?\u3068\u3002 \u3067\u3001\u691c\u7d22\u3057\u3066\u307f\u308b [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[6,1],"tags":[],"class_list":["post-1757","post","type-post","status-publish","format-standard","hentry","category-6","category-1"],"views":1736,"_links":{"self":[{"href":"https:\/\/www.pinewell.jp\/wordpress\/index.php?rest_route=\/wp\/v2\/posts\/1757","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.pinewell.jp\/wordpress\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.pinewell.jp\/wordpress\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.pinewell.jp\/wordpress\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.pinewell.jp\/wordpress\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=1757"}],"version-history":[{"count":0,"href":"https:\/\/www.pinewell.jp\/wordpress\/index.php?rest_route=\/wp\/v2\/posts\/1757\/revisions"}],"wp:attachment":[{"href":"https:\/\/www.pinewell.jp\/wordpress\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=1757"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.pinewell.jp\/wordpress\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=1757"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.pinewell.jp\/wordpress\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=1757"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}