{"id":4307,"date":"2023-11-16T19:54:46","date_gmt":"2023-11-16T11:54:46","guid":{"rendered":"http:\/\/www.wangkaixuan.tech\/?p=4307"},"modified":"2023-11-16T19:55:14","modified_gmt":"2023-11-16T11:55:14","slug":"%e5%85%a5%e5%9d%91%e6%a0%91%e8%8e%93%e6%b4%be-03-%e6%8c%89%e9%94%ae%e6%8e%a7%e5%88%b6","status":"publish","type":"post","link":"http:\/\/www.wangkaixuan.tech\/?p=4307","title":{"rendered":"\u5165\u5751\u6811\u8393\u6d3e-03-\u6309\u952e\u63a7\u5236"},"content":{"rendered":"\n<p>\u6309\u952e\u6307\u7684\u662f\u8fd9\u51e0\u4e2a\uff1a<\/p>\n\n\n\n<figure class=\"wp-block-image size-full\"><img loading=\"lazy\" decoding=\"async\" width=\"411\" height=\"470\" src=\"http:\/\/www.wangkaixuan.tech\/wp-content\/uploads\/2023\/11\/image-33.png\" alt=\"\" class=\"wp-image-4308\" srcset=\"http:\/\/www.wangkaixuan.tech\/wp-content\/uploads\/2023\/11\/image-33.png 411w, http:\/\/www.wangkaixuan.tech\/wp-content\/uploads\/2023\/11\/image-33-262x300.png 262w, http:\/\/www.wangkaixuan.tech\/wp-content\/uploads\/2023\/11\/image-33-236x270.png 236w\" sizes=\"auto, (max-width: 411px) 100vw, 411px\" \/><\/figure>\n\n\n\n<p>\u5206\u522b\u5bf9\u5e94\u8fd9\u51e0\u4e2a\u7aef\u53e3\uff1a<\/p>\n\n\n\n<figure class=\"wp-block-image size-full\"><img loading=\"lazy\" decoding=\"async\" width=\"602\" height=\"326\" src=\"http:\/\/www.wangkaixuan.tech\/wp-content\/uploads\/2023\/11\/image-34.png\" alt=\"\" class=\"wp-image-4309\" srcset=\"http:\/\/www.wangkaixuan.tech\/wp-content\/uploads\/2023\/11\/image-34.png 602w, http:\/\/www.wangkaixuan.tech\/wp-content\/uploads\/2023\/11\/image-34-300x162.png 300w, http:\/\/www.wangkaixuan.tech\/wp-content\/uploads\/2023\/11\/image-34-499x270.png 499w\" sizes=\"auto, (max-width: 602px) 100vw, 602px\" \/><\/figure>\n\n\n\n<p>\u56db\u4e2a\u6309\u952e\uff0c\u56db\u4e2a\u706f\uff0c\u6b63\u597d\u6211\u4eec\u53ef\u4ee5\u7528\u6309\u952e\u63a7\u5236\u706f\u3002<\/p>\n\n\n\n<p>python\u4ee3\u7801\u5982\u4e0b\uff1a<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>import RPi.GPIO as GPIO\nimport time\n\nGPIO.setmode(GPIO.BCM)\n\nBTN_1 = 6\nBTN_2 = 13\nBTN_3 = 19\nBTN_4 = 26\n\nLED_1 = 17\nLED_2 = 27\nLED_3 = 22\nLED_4 = 5\n\nGPIO.setup(BTN_1, GPIO.IN, pull_up_down=GPIO.PUD_DOWN)\nGPIO.setup(BTN_2, GPIO.IN, pull_up_down=GPIO.PUD_DOWN)\nGPIO.setup(BTN_3, GPIO.IN, pull_up_down=GPIO.PUD_DOWN)\nGPIO.setup(BTN_4, GPIO.IN, pull_up_down=GPIO.PUD_DOWN)\n\nGPIO.setup(LED_1, GPIO.OUT)\nGPIO.setup(LED_2, GPIO.OUT)\nGPIO.setup(LED_3, GPIO.OUT)\nGPIO.setup(LED_4, GPIO.OUT)\n\nwhile True:\n    if (GPIO.input(BTN_1) == GPIO.LOW):\n        GPIO.output(LED_1, GPIO.HIGH)\n    else:\n        GPIO.output(LED_1, GPIO.LOW)\n\n    if (GPIO.input(BTN_2) == GPIO.LOW):\n        GPIO.output(LED_2, GPIO.HIGH)\n    else:\n        GPIO.output(LED_2, GPIO.LOW)\n\n    if (GPIO.input(BTN_3) == GPIO.LOW):\n        GPIO.output(LED_3, GPIO.HIGH)\n    else:\n        GPIO.output(LED_3, GPIO.LOW)\n\n    if (GPIO.input(BTN_4) == GPIO.LOW):\n        GPIO.output(LED_4, GPIO.HIGH)\n    else:\n        GPIO.output(LED_4, GPIO.LOW)\n\n    time.sleep(0.01)<\/code><\/pre>\n\n\n\n<p>C\u4ee3\u7801\u5982\u4e0b\uff1a<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>#include &lt;bcm2835.h>\n#include &lt;stdio.h>\n#include &lt;unistd.h>\n\n\/\/ gcc -o button button.c -lbcm2835\n\n#define KEY_1 6\n#define KEY_2 13\n#define KEY_3 19\n#define KEY_4 26\n\n#define PIN_R 17\n#define PIN_Y 27\n#define PIN_G 22\n#define PIN_B 5\n\nint main(int argc, char **argv)\n{\n    if (!bcm2835_init())\n        return -1;\n\n    bcm2835_gpio_fsel(KEY_1, BCM2835_GPIO_FSEL_INPT);\n    bcm2835_gpio_fsel(KEY_2, BCM2835_GPIO_FSEL_INPT);\n    bcm2835_gpio_fsel(KEY_3, BCM2835_GPIO_FSEL_INPT);\n    bcm2835_gpio_fsel(KEY_4, BCM2835_GPIO_FSEL_INPT);\n\n    bcm2835_gpio_set_pud(KEY_1, BCM2835_GPIO_PUD_UP);\n    bcm2835_gpio_set_pud(KEY_2, BCM2835_GPIO_PUD_UP);\n    bcm2835_gpio_set_pud(KEY_3, BCM2835_GPIO_PUD_UP);\n    bcm2835_gpio_set_pud(KEY_4, BCM2835_GPIO_PUD_UP);\n\n    bcm2835_gpio_fsel(PIN_R, BCM2835_GPIO_FSEL_OUTP);\n    bcm2835_gpio_fsel(PIN_Y, BCM2835_GPIO_FSEL_OUTP);\n    bcm2835_gpio_fsel(PIN_G, BCM2835_GPIO_FSEL_OUTP);\n    bcm2835_gpio_fsel(PIN_B, BCM2835_GPIO_FSEL_OUTP);\n\n    bcm2835_gpio_write(PIN_R, LOW);\n    bcm2835_gpio_write(PIN_Y, LOW);\n    bcm2835_gpio_write(PIN_G, LOW);\n    bcm2835_gpio_write(PIN_B, LOW);\n\n    while (1)\n    {\n        if(bcm2835_gpio_lev(KEY_1) == 0)\n        {\n            bcm2835_gpio_write(PIN_R, HIGH);\n            while(bcm2835_gpio_lev(KEY_1) == 0)\n                bcm2835_delay(100);\n            bcm2835_gpio_write(PIN_R, LOW);\n        }\n        if(bcm2835_gpio_lev(KEY_2) == 0)\n        {\n            bcm2835_gpio_write(PIN_Y, HIGH);\n            while(bcm2835_gpio_lev(KEY_2) == 0)\n                bcm2835_delay(100);\n            bcm2835_gpio_write(PIN_Y, LOW);\n        }\n        if(bcm2835_gpio_lev(KEY_3) == 0)\n        {\n            bcm2835_gpio_write(PIN_G, HIGH);\n            while(bcm2835_gpio_lev(KEY_3) == 0)\n                bcm2835_delay(100);\n            bcm2835_gpio_write(PIN_G, LOW);\n        }\n        if(bcm2835_gpio_lev(KEY_4) == 0)\n        {\n            bcm2835_gpio_write(PIN_B, HIGH);\n            while(bcm2835_gpio_lev(KEY_4) == 0)\n                bcm2835_delay(100);\n            bcm2835_gpio_write(PIN_B, LOW);\n        }\n        bcm2835_delay(100);\n    }\n    bcm2835_close();\n\n    return 0;\n}\n<\/code><\/pre>\n","protected":false},"excerpt":{"rendered":"<p>\u6309\u952e\u6307\u7684\u662f\u8fd9\u51e0\u4e2a\uff1a \u5206\u522b\u5bf9\u5e94\u8fd9\u51e0\u4e2a\u7aef\u53e3\uff1a \u56db\u4e2a\u6309\u952e\uff0c\u56db\u4e2a\u706f\uff0c\u6b63\u597d\u6211\u4eec\u53ef\u4ee5\u7528\u6309\u952e\u63a7\u5236\u706f\u3002 python\u4ee3\u7801\u5982\u4e0b\uff1a C\u4ee3\u7801\u5982\u4e0b\uff1a<\/p>\n","protected":false},"author":2,"featured_media":0,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[17],"tags":[],"class_list":["post-4307","post","type-post","status-publish","format-standard","hentry","category-03-01-"],"_links":{"self":[{"href":"http:\/\/www.wangkaixuan.tech\/index.php?rest_route=\/wp\/v2\/posts\/4307","targetHints":{"allow":["GET"]}}],"collection":[{"href":"http:\/\/www.wangkaixuan.tech\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/www.wangkaixuan.tech\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/www.wangkaixuan.tech\/index.php?rest_route=\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"http:\/\/www.wangkaixuan.tech\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=4307"}],"version-history":[{"count":0,"href":"http:\/\/www.wangkaixuan.tech\/index.php?rest_route=\/wp\/v2\/posts\/4307\/revisions"}],"wp:attachment":[{"href":"http:\/\/www.wangkaixuan.tech\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=4307"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/www.wangkaixuan.tech\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=4307"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/www.wangkaixuan.tech\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=4307"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}