{"id":2314,"date":"2019-10-28T23:31:27","date_gmt":"2019-10-28T14:31:27","guid":{"rendered":"http:\/\/androiphone.uvs.jp\/?p=2314"},"modified":"2020-05-14T12:55:37","modified_gmt":"2020-05-14T03:55:37","slug":"%e3%83%a9%e3%82%ba%e3%83%91%e3%82%a4-led%e7%82%b9%e7%81%afl%e3%83%81%e3%82%ab%e3%81%a7python%e3%81%ae%e5%8b%89%e5%bc%b7%e3%81%8c%e3%81%a6%e3%82%89%e3%82%ab%e3%82%b9%e3%82%bf%e3%83%a0%e3%82%af","status":"publish","type":"post","link":"https:\/\/androiphone.uvs.jp\/?p=2314","title":{"rendered":"[\u30e9\u30ba\u30d1\u30a4] LED\u70b9\u706f(L\u30c1\u30ab)\u3067Python\u306e\u52c9\u5f37\u304c\u3066\u3089\u30ab\u30b9\u30bf\u30e0\u30af\u30e9\u30b9\u3092\u4f5c\u3063\u305f\u8a71"},"content":{"rendered":"<p><span style=\"font-size: 14pt;\">\u3000I2C\u306e\u3053\u3068\u3070\u3063\u304b\u308a\u3084\u3063\u3066\u305f\u3089\u3001GPIO\u3092\u7528\u3044\u3066LED\u3092\u5149\u3089\u305b\u308b\u3068\u304b\u5168\u304f\u30b9\u30eb\u30fc\u3057\u3066\u305fw\u3002Python\u3082\u307e\u3068\u3082\u306b\u6253\u3066\u306a\u3044\u3057\u3001\u305d\u3082\u305d\u3082\u30af\u30e9\u30b9\u3068\u304b\u3044\u3046\u524d\u306b<span style=\"color: #ff0000;\"><strong><span style=\"font-size: 18pt;\">\u5236\u5fa1\u6587(if\u3001while\u3001for)\u3068\u304b\u3082\u3001\u307e\u3068\u3082\u306b\u66f8\u3051\u306a\u3044<\/span><\/strong><\/span>\u306e\u3067\u3001\u52c9\u5f37\u304c\u3066\u3089L\u30c1\u30ab\u3059\u308b\u30af\u30e9\u30b9\u3092\u4f5c\u3063\u3066\u307f\u3088\u3046\u3068\u65e5\u66dc\u65e5\u306b\u601d\u3044\u7acb\u3063\u305f<\/span><\/p>\n<p><span style=\"font-size: 14pt;\">\u3000\u307e\u305a\u3001LED\u3001\u30d6\u30ec\u30c3\u30c9\u30dc\u30fc\u30c9\u3001\u30b3\u30fc\u30c9\u3001\u62b5\u6297\u306f\u4ee5\u4e0b\u306e\u30bb\u30c3\u30c8\u306b\u3064\u3044\u3066\u304d\u305f\u3084\u3064\u3067\u4e8b\u8db3\u308a\u308b\u3068\u304a\u3082\u3046\u3002\u3042\u3068\u3001\u30c6\u30b9\u30bf\u30fc\u304c\u3042\u308b\u3068\u78ba\u8a8d\u3057\u3084\u3059\u3044\u3002\u306a\u305c\u304b\u3046\u3061\u306b\u306f\u30c6\u30b9\u30bf\u30fc\u304c3\u53f0\u3042\u308b\u3002\u9589\u5e97\u3059\u308b\u500b\u4eba\u96fb\u6c17\u5e97\u306e\u77e5\u308a\u5408\u3044\u304b\u3089\u3082\u3089\u3063\u305f\u3084\u3064\u3002\u534a\u7530\u3053\u3066\u3068\u304b\u3082\u3082\u3089\u3063\u305f\u3002<\/span><\/p>\n<p><iframe style=\"width: 120px; height: 240px;\" src=\"https:\/\/rcm-fe.amazon-adsystem.com\/e\/cm?ref=qf_sp_asin_til&amp;t=dinagon-22&amp;m=amazon&amp;o=9&amp;p=8&amp;l=as1&amp;IS1=1&amp;detail=1&amp;asins=B075167Y4D&amp;linkId=c8986c73e2c2c8b0a44a059d273ea4bd&amp;bc1=000000&amp;lt1=_blank&amp;fc1=333333&amp;lc1=0066c0&amp;bg1=ffffff&amp;f=ifr\" frameborder=\"0\" marginwidth=\"0\" marginheight=\"0\" scrolling=\"no\"><br \/>\n<\/iframe><iframe style=\"width: 120px; height: 240px;\" src=\"https:\/\/rcm-fe.amazon-adsystem.com\/e\/cm?ref=qf_sp_asin_til&amp;t=dinagon-22&amp;m=amazon&amp;o=9&amp;p=8&amp;l=as1&amp;IS1=1&amp;detail=1&amp;asins=B00KXX2OYY&amp;linkId=a070e6adf9da1bfc45219763eb9e8198&amp;bc1=000000&amp;lt1=_blank&amp;fc1=333333&amp;lc1=0066c0&amp;bg1=ffffff&amp;f=ifr\" frameborder=\"0\" marginwidth=\"0\" marginheight=\"0\" scrolling=\"no\"><br \/>\n<\/iframe><\/p>\n<p><span style=\"font-size: 14pt;\">\u30c6\u30b9\u30bf\u30fc\u3068\u304b\u4e0a\u306e\u3084\u3064\u3068\u304b\u3067\u5341\u5206\u3068\u601d\u3046\u3002<\/span><\/p>\n<p><span style=\"font-size: 14pt;\">GPIO\u30d4\u30f3\u3068LED\u306e\u63a5\u7d9a\u65b9\u6cd5\u3060\u3051\u3069\u3001\u8272\u3005\u306a\u30b5\u30a4\u30c8\u306b\u8aac\u660e\u3055\u308c\u3066\u3044\u308b\u306e\u3067\u3088\u304f\u8aad\u3093\u3067\u306d\u3002<\/span><\/p>\n<div class=\"linkcard\"><div class=\"lkc-external-wrap\"><a class=\"lkc-link no_icon\" href=\"http:\/\/make.bcde.jp\/raspberry-pi\/gpio%E3%81%A7led%E3%81%AE%E7%82%B9%E6%BB%85python\/\" data-lkc-id=\"794\" target=\"_blank\" rel=\"external noopener\"><div class=\"lkc-card\"><div class=\"lkc-info\"><div class=\"lkc-favicon\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/www.google.com\/s2\/favicons?domain=make.bcde.jp\" alt=\"\" width=\"16\" height=\"16\" \/><\/div><div class=\"lkc-domain\">Make.<\/div><div class=\"lkc-share\"> <div class=\"lkc-sns-hb\">13 Users<\/div> <div class=\"lkc-sns-po\">44 Pockets<\/div><\/div><\/div><div class=\"lkc-content\"><figure class=\"lkc-thumbnail\"><img decoding=\"async\" class=\"lkc-thumbnail-img\" src=\"\/\/androiphone.uvs.jp\/wp-content\/uploads\/pz-linkcard\/cache\/b252ac9b0b900224b99389b2772b847200dd489a9c29f7f79bbf17bdb0be9167.jpeg\" width=\"100px\" height=\"108px\" alt=\"\" \/><\/figure><div class=\"lkc-title\">GPIO\u3067LED\u306e\u70b9\u6ec5(Python)<\/div><div class=\"lkc-url\" title=\"http:\/\/make.bcde.jp\/raspberry-pi\/gpio%E3%81%A7led%E3%81%AE%E7%82%B9%E6%BB%85python\/\">http:\/\/make.bcde.jp\/raspberry-pi\/gpio\u3067led\u306e\u70b9\u6ec5python\/<\/div><div class=\"lkc-excerpt\">Raspberry Pi\u3067\u3001Python\u3092GPIO\u3092\u4f7f\u7528\u3057\u3066\u3001LED\u3092\u70b9\u6ec5\u3055\u305b\u307e\u3059\u3002 LED\u3092\u30c1\u30ab\u30c1\u30ab\u3055\u305b\u308b\u305f\u2026<\/div><\/div><div class=\"clear\"><\/div><\/div><\/a><\/div><\/div>\n<p><span style=\"font-size: 14pt;\">LED\u5149\u3089\u305b\u305f\u3053\u3068\u306a\u3044\u4eba\u306b\u306f\u306a\u3093\u3067\u62b5\u6297\u3044\u308c\u306a\u3044\u3068\u30c0\u30e1\u306a\u3093\uff1f\u3063\u3066\u601d\u3046\u4eba\u3044\u308b\u3068\u304a\u3082\u3046\u3002\u307e\u305a\u306f\u30aa\u30fc\u30e0\u306e\u6cd5\u5247\u3092\u899a\u3048\u3088\u3046\u3002\u3068\u3044\u3046\u304b\u3001\u7fa9\u52d9\u6559\u80b2\u3067\u306f\u3084\u3063\u3066\u308b\u306f\u305a\u306a\u306e\u3067\u601d\u3044\u51fa\u3057\u307e\u3057\u3087\u3046\u3002\u30aa\u30fc\u30e0\u306e\u3066\u3093\u3068\u3046\u866b\u306f\u6709\u540d\u3067\u3001\u6c42\u3081\u305f\u3044\u3082\u306e\u3092\u6307\u3067\u96a0\u3059\u3068\u5f0f\u304c\u3067\u304d\u307e\u3059\u3002\u4ef2\u9593\u306b\u30cf\u30b8\u30ad\u306e\u3066\u3093\u3068\u3046\u866b\u3068\u304b\u3082\u3044\u307e\u3059\u306d(\u306a\u3064\u3044ww)<\/span><\/p>\n<p><iframe loading=\"lazy\" width=\"560\" height=\"315\" src=\"https:\/\/www.youtube.com\/embed\/ouX0xtou-Fk\" frameborder=\"0\" allowfullscreen=\"allowfullscreen\"><\/iframe><\/p>\n<p><span style=\"font-size: 14pt;\">\u96fb\u6c60\u306b\u8c46\u96fb\u7403\u3064\u306a\u3044\u3067\u5149\u3089\u305b\u305f\u611f\u899a\u3067LED\u306b\u76f4\u3067\u96fb\u6c60\u3092\u3064\u306a\u3050\u3068LED\u304c\u3076\u3063\u98db\u3073\u307e\u3059(\u610f\u5916\u306b\u5927\u4e08\u592b\u306a\u3053\u3068\u3082\u3042\u308b\u3051\u3069\u30c0\u30e1\u3067\u3059w)\u3002\u7406\u7531\u306f\u3001\u8c46\u96fb\u7403(\u30d5\u30a3\u30e9\u30e1\u30f3\u30c8))\u304c\u305d\u308c\u81ea\u4f53\u304c\u62b5\u6297\u3092\u6301\u3063\u3066\u3044\u308b\u306e\u3067\u3001\u5b9a\u96fb\u5727(\u4e7e\u96fb\u6c601.5V\u3068\u304b)\u306a\u3089\u6c7a\u307e\u3063\u305f\u96fb\u6d41\u304c\u6d41\u308c\u308b\u3002\u3053\u308c\u306f\u30aa\u30fc\u30e0\u306e\u6cd5\u5247\u3068\u3044\u3046\u5927\u539f\u5247\u304b\u3042\u308b\u304b\u3089\u3002<\/span><\/p>\n<p><span style=\"font-size: 14pt;\">LED\u306f\u534a\u5c0e\u4f53\u306a\u306e\u3067\u96fb\u5727\u306b\u3088\u3063\u3066\u62b5\u6297\u304c\u5909\u308f\u308b(\u904e\u5927\u96fb\u6d41\u304c\u6d41\u308c\u3066\u3057\u307e\u3063\u3066\u58ca\u308c\u308b)\u306e\u3067\u3001\u96fb\u6d41\u3092\u5236\u9650\u3059\u308b\u305f\u3081\u306b\u62b5\u6297\u3092\u5165\u308c\u306a\u304f\u3066\u306f\u306a\u308a\u307e\u305b\u3093\u3002<span style=\"font-size: 18pt; color: #ff0000;\">\u9069\u5f53\u306a\u62b5\u6297\u3092\u5165\u308c\u307e\u3057\u3087\u3046<\/span>\u3063\u3066\u66f8\u3044\u3066\u308b\u3068\u3053\u308d\u3082\u591a\u3044\u3067\u3059\u304c\u3001<strong><span style=\"font-size: 18pt; color: #0000ff;\">\u521d\u5fc3\u8005\u306b\u306f\u305d\u306e\u9069\u5f53\u3059\u3089\u308f\u304b\u3089\u3093\u306e\u3067\u3059\u3088\uff01\uff01<\/span><\/strong>\u3002\u8a08\u7b97\u3081\u3093\u3069\u304f\u305b\u30fc\u3063\u3066\u601d\u3046\u4eba\u304c\u3044\u308b\u3068\u601d\u3046\u3051\u3069\u3001\u4ee5\u4e0b\u306e\u30b5\u30a4\u30c8\u3067\u7c21\u5358\u306b\u3067\u304d\u307e\u3059<\/span><\/p>\n<div class=\"linkcard\"><div class=\"lkc-external-wrap\"><div class=\"lkc-unlink\"><div class=\"lkc-card\"><div class=\"lkc-info\"><div class=\"lkc-favicon\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/www.google.com\/s2\/favicons?domain=www.cityjp.com\" alt=\"\" width=\"16\" height=\"16\" \/><\/div><div class=\"lkc-domain\">www.cityjp.com<\/div><div class=\"lkc-share\"> <div class=\"lkc-sns-hb\">1 User<\/div><\/div><\/div><div class=\"lkc-content\"><figure class=\"lkc-thumbnail\"><img decoding=\"async\" class=\"lkc-thumbnail-img\" src=\"https:\/\/s.wordpress.com\/mshots\/v1\/http%3A%2F%2Fwww.cityjp.com%2Fjavascript%2Fetc%2Fled_r.html?w=100\" width=\"100px\" height=\"108px\" alt=\"\" \/><\/figure><div class=\"lkc-title\">\u767a\u5149\u30c0\u30a4\u30aa\u30fc\u30c9\u7528\u96fb\u6d41\u5236\u9650\u62b5\u6297\u8a08\u7b97\u30d5\u30a9\u30fc\u30e0<\/div><div class=\"lkc-url\" title=\"http:\/\/www.cityjp.com\/javascript\/etc\/led_r.html\"><strike>http:\/\/www.cityjp.com\/javascript\/etc\/led_r.html<\/strike><\/div><\/div><div class=\"clear\"><\/div><\/div><\/div><\/div><\/div>\n<p><span style=\"font-size: 14pt;\">\u3053\u306e\u3064\u3044\u3066\u304d\u305fLED\u306e\u30c7\u30fc\u30bf\u30b7\u30fc\u30c8\u304c\u306a\u3044\u306e\u3067\u3001Amazon\u3067\u8cb7\u3063\u305f\u90e8\u54c1\u30bb\u30c3\u30c8\u306e\u30c1\u30e5\u30fc\u30c8\u30ea\u30a2\u30eb\u306b\u306a\u3093\u304b\u66f8\u3044\u3066\u3042\u308b\u304b\u3068\u601d\u3044\u3001\u76ee\u3092\u901a\u3057\u3066\u307f\u305f\u3002\u30ec\u30c3\u30b9\u30f31\u306eLED\u70b9\u706f\u306e\u30da\u30fc\u30b8\u3092\u898b\u3066\u5fc5\u8981\u306a\u7269\u306e\u30ea\u30b9\u30c8\u3092\u307f\u308b\u3068\u30fb\u30fb\u30fb\u3042\u308c\u30fb\u30fb\u30fb<span style=\"color: #ff0000;\"><strong><span style=\"font-size: 18pt;\">\u62b5\u6297\u4f7f\u3063\u3066\u7121\u304f\u306a\u3044( \u00b4\u2200\uff40 )\uff1f<\/span><\/strong><\/span><\/span><\/p>\n<p><a href=\"http:\/\/androiphone.uvs.jp\/wp-content\/uploads\/2019\/10\/SnapCrab_NoName_2019-10-28_18-19-16_No-00.png\"><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-medium wp-image-2318\" src=\"http:\/\/androiphone.uvs.jp\/wp-content\/uploads\/2019\/10\/SnapCrab_NoName_2019-10-28_18-19-16_No-00-204x300.png\" alt=\"\" width=\"204\" height=\"300\" srcset=\"https:\/\/androiphone.uvs.jp\/wp-content\/uploads\/2019\/10\/SnapCrab_NoName_2019-10-28_18-19-16_No-00-204x300.png 204w, https:\/\/androiphone.uvs.jp\/wp-content\/uploads\/2019\/10\/SnapCrab_NoName_2019-10-28_18-19-16_No-00.png 546w\" sizes=\"auto, (max-width: 204px) 100vw, 204px\" \/><\/a><\/p>\n<p><del><span style=\"font-size: 14pt;\">\u3000\u6c17\u3092\u53d6\u308a\u76f4\u3057\u3066\u4e88\u60f3\u3067led\u306e\u9806\u96fb\u5727VF=2.0V\u3067\u3001\u6d41\u3057\u305f\u3044\u96fb\u6d4110mA\uff5e15mA\u3067\u3044\u3044\u3093\u3058\u3083\u306a\u3044\u3067\u3057\u3087\u3046\u304b\uff1f(\u9069\u5f53w)\u3002\u305d\u3046\u3059\u308b\u306886\uff5e129\u03a9\u3068\u3067\u307e\u3059\u3002\u306a\u306e\u3067100\u03a9\u3092\u3064\u304b\u3063\u3066\u3044\u304d\u307e\u3059\u3002\u307b\u304b\u306e\u30b5\u30a4\u30c8\u307f\u308b\u3068330\u03a9\u4f7f\u3063\u3066\u308b\u4eba\u591a\u3044\u3067\u3059\u304c4mA\u3050\u3089\u3044\u3067\u6697\u304f\u306a\u3044\u3067\u3059\u304b\uff1f\u3069\u3046\u3067\u3059\u304b\u306d\uff1f\u30e9\u30ba\u30d1\u30a4\u306eGIO\u96fb\u5727\u306f3.3V\u3001\u6700\u5927\u96fb\u6d4150mA\u306a\u306e\u3067\u5927\u4e08\u592b\u304b\u3068\u601d\u3044\u307e\u3059\u3002<\/span><\/del><\/p>\n<p><a href=\"http:\/\/androiphone.uvs.jp\/wp-content\/uploads\/2019\/10\/SnapCrab_NoName_2019-10-28_18-38-18_No-00.png\"><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-medium wp-image-2317\" src=\"http:\/\/androiphone.uvs.jp\/wp-content\/uploads\/2019\/10\/SnapCrab_NoName_2019-10-28_18-38-18_No-00-300x98.png\" alt=\"\" width=\"300\" height=\"98\" srcset=\"https:\/\/androiphone.uvs.jp\/wp-content\/uploads\/2019\/10\/SnapCrab_NoName_2019-10-28_18-38-18_No-00-300x98.png 300w, https:\/\/androiphone.uvs.jp\/wp-content\/uploads\/2019\/10\/SnapCrab_NoName_2019-10-28_18-38-18_No-00-768x250.png 768w, https:\/\/androiphone.uvs.jp\/wp-content\/uploads\/2019\/10\/SnapCrab_NoName_2019-10-28_18-38-18_No-00.png 775w\" sizes=\"auto, (max-width: 300px) 100vw, 300px\" \/><\/a><\/p>\n<p><span style=\"font-size: 14pt;\"><em><strong>(\u8a02\u6b6311\/18)<\/strong><\/em>\u30003.3V\u306eGPIO\u306f1\u30d4\u30f3\u5f53\u305f\u308a\u6700\u592716mA\u3089\u3057\u3044\u3067\u3059\u3002\u6700\u5927\u96fb\u6d4150mA\u3068\u3044\u3046\u306e\u306fGPIO\u5408\u8a08\u5024\u3067\u3059\u306e\u30671pin\u306b50mA\u6d41\u3059\u3068\u58ca\u308c\u307e\u3059\u3002\u4e0a\u306fVF=2.0v\u3067100\u03a9\u3060\u3068<strong><span style=\"font-size: 18pt; color: #ff0000;\">13mA\u3068\u306a\u308a\u30ae\u30ea\u30ae\u30ea\u3059\u304e\u308b<\/span><\/strong>\u3068\u601d\u3044\u307e\u3057\u305f\u306e\u3067\u8a02\u6b63\u3057\u307e\u3059\u3002\u4eca\u56de\u306f3\u3064\u306eLED\u30928mA\u00d73= 24mA\u7a0b\u5ea6\u3067\u3064\u3051\u305f\u3044\u3068\u601d\u3044\u307e\u3059\u3002\u8a08\u7b97\u3059\u308b\u3068162\u03a9\u3068\u306a\u308a\u307e\u3059\u306e\u3067\u3001200\u03a9\u3042\u305f\u308a\u3092\u9078\u629e\u3057\u3066\u304a\u304f\u3068\u7121\u96e3\u3067\u3057\u3087\u3046\u3002<\/span><\/p>\n<p><a href=\"http:\/\/androiphone.uvs.jp\/wp-content\/uploads\/2019\/10\/SnapCrab_NoName_2019-11-18_16-26-39_No-00.png\"><img loading=\"lazy\" decoding=\"async\" class=\"alignnone wp-image-2568\" src=\"http:\/\/androiphone.uvs.jp\/wp-content\/uploads\/2019\/10\/SnapCrab_NoName_2019-11-18_16-26-39_No-00-300x45.png\" alt=\"\" width=\"340\" height=\"51\" srcset=\"https:\/\/androiphone.uvs.jp\/wp-content\/uploads\/2019\/10\/SnapCrab_NoName_2019-11-18_16-26-39_No-00-300x45.png 300w, https:\/\/androiphone.uvs.jp\/wp-content\/uploads\/2019\/10\/SnapCrab_NoName_2019-11-18_16-26-39_No-00-768x114.png 768w, https:\/\/androiphone.uvs.jp\/wp-content\/uploads\/2019\/10\/SnapCrab_NoName_2019-11-18_16-26-39_No-00.png 772w\" sizes=\"auto, (max-width: 340px) 100vw, 340px\" \/><\/a><\/p>\n<p><span style=\"font-size: 14pt;\">\u30b5\u30af\u30b5\u30af\u3064\u306a\u3052\u307e\u3057\u3087\u3046\u3002<\/span><\/p>\n<p><span style=\"font-size: 14pt;\">\u3067\u3001\u30b3\u30fc\u30c9\u3067\u3059\u304c\u4ed6\u306e\u30b5\u30a4\u30c8\u3067\u306fL\u30c1\u30ab\u3055\u305b\u308b\u306e\u306b\u5927\u4f53\u3001GPIO18\u306b\u3064\u306a\u3044\u3060\u5834\u5408<\/span><\/p>\n<pre class=\"lang:python decode:true\">import RPi.GPIO as GPIO\r\nimport time\r\nGPIO.setmode(GPIO.BOARD)\r\nGPIO.setup(18, GPIO.OUT)\r\nwhile True:\r\n    GPIO.output(11, True)\r\n    time.sleep(2)\r\n    GPIO.output(11, False)\r\n    time.sleep(2)<\/pre>\n<p><span style=\"font-size: 14pt;\">\u3063\u3066\u306a\u611f\u3058\u3067\u66f8\u3044\u3066\u3042\u308a\u307e\u3059\u304c\u3001LED\u30c1\u30ab\u30c1\u30ab\u3055\u305b\u308b\u306b\u306f\u3044\u3044\u3093\u3067\u3059\u3051\u3069\u3001\u306a\u3093\u304b\u306e\u51e6\u7406\u4e2d\u306b\u30c1\u30ab\u30c1\u30ab\u3055\u305b\u308b\u3068\u304b\u306a\u308b\u3068\u3001\u30c1\u30ab\u30c1\u30ab\u30eb\u30fc\u30d7\u3092\u3044\u3061\u3044\u3061\u66f8\u304f\u306e\u3063\u3066\u30fb\u30fb\u30fb\u6c4e\u7528\u6027\u304c\u60aa\u304f\u306a\u3044\u3067\u3059\u304b\uff1fPython\u306e\u52c9\u5f37\u517c\u306d\u3066\u30b9\u30ec\u30c3\u30c9\u3092\u7528\u3044\u3066\u30af\u30e9\u30b9\u5316\u3057\u3066\u307f\u3088\u3046\u3068\u601d\u3044\u307e\u3057\u305f\u3002<\/span><\/p>\n<p><span style=\"font-size: 14pt;\">myled.py\u306b\u30af\u30e9\u30b9MyLed\u4f5c\u3063\u3066\u307f\u307e\u3057\u305f\u3002\u3044\u304d\u306a\u308a\u30b3\u30fc\u30c9\u3067\u3059w\u3002\u30b9\u30ec\u30c3\u30c9\u306e\u64cd\u4f5c\u306e\u8aac\u660e\u306f\u9577\u30fc\u304f\u306a\u308b\u306e\u3067\u5225\u30b5\u30a4\u30c8\u306b\u4efb\u305b\u307e\u3059<\/span><\/p>\n<pre class=\"lang:python decode:true\">import RPi.GPIO as GPIO\r\nimport time\r\nimport threading\r\n\r\nclass MyLED():\r\n    def __init__(self, gpio_num: int):\r\n        self.gpio_num = gpio_num\r\n        self.offLed = False\r\n        self.rate = 100\r\n        GPIO.setwarnings(False)\r\n        GPIO.setmode(GPIO.BCM)\r\n        GPIO.setup(gpio_num, GPIO.OUT)\r\n\r\n    def Light_ON(self, sec=0, rate=100, freq=50):\r\n        def LedOnThread(sec, freq):\r\n            led = GPIO.PWM(self.gpio_num, freq)\r\n            led.start(self.rate)\r\n\r\n            start_time = time.time()\r\n            while True:\r\n                led.ChangeDutyCycle(self.rate)\r\n                if (sec &gt; 0 and (time.time()-start_time) &gt; sec) or self.offLed:\r\n                    break\r\n            led.stop\r\n\r\n        self.rate = rate\r\n        if self.chkLedOnThread():\r\n            self.Light_OFF()\r\n        self.th = threading.Thread(target=LedOnThread, args=(sec, freq,))\r\n        self.th.start()\r\n\r\n    def Light_OFF(self):\r\n        if not hasattr(self, 'th'):\r\n            return\r\n        if self.th.isAlive():\r\n            self.offLed = True\r\n            self.waitLedOnThread()\r\n            self.offLed = False\r\n\r\n    def Hotaru_ON(self, sec=0, interval=2, r=30, freq=50):\r\n        def HotaruThread(sec, r, freq):\r\n            self.rate = 0\r\n            led = GPIO.PWM(self.gpio_num, freq)\r\n            led.start(self.rate)\r\n\r\n            start_time = time.time()\r\n            while True:\r\n                for i in range(r):\r\n                    if (sec &gt; 0 and (time.time()-start_time) &gt; sec) or self.offLed:\r\n                        led.stop\r\n                        return\r\n                    self.rate = 100*i\/r\r\n                    time.sleep(interval\/2\/r)\r\n                    led.ChangeDutyCycle(self.rate)\r\n                for i in range(r):\r\n                    if (sec &gt; 0 and (time.time()-start_time) &gt; sec) or self.offLed:\r\n                        led.stop\r\n                        return\r\n                    self.rate = 100-100*i\/r\r\n                    time.sleep(interval\/2\/r)\r\n                    led.ChangeDutyCycle(self.rate)\r\n            led.stop\r\n\r\n        if self.chkLedOnThread():\r\n            self.Light_OFF()\r\n        self.th = threading.Thread(target=HotaruThread, args=(sec, r, freq,))\r\n        self.th.start()\r\n\r\n    def Flash_ON(self, sec=0,rate=100,f_sec=0.1, freq=50):\r\n        def FlashThread(sec, freq):\r\n            led = GPIO.PWM(self.gpio_num, freq)\r\n            led.start(self.rate)\r\n\r\n            start_time = time.time()\r\n            while True:\r\n\r\n                led.ChangeDutyCycle(self.rate)\r\n                c_time = time.time();\r\n                while (time.time()-c_time) &lt; f_sec: if (sec &gt; 0 and (time.time()-start_time) &gt; sec) or self.offLed:\r\n                        led.stop\r\n                        return\r\n\r\n                led.ChangeDutyCycle(0)\r\n                c_time = time.time();\r\n                while (time.time()-c_time) &lt; f_sec: if (sec &gt; 0 and (time.time()-start_time) &gt; sec) or self.offLed:\r\n                        led.stop\r\n                        return\r\n\r\n            led.stop\r\n\r\n        self.rate = rate\r\n        if self.chkLedOnThread():\r\n            self.Light_OFF()\r\n        self.th = threading.Thread(target=FlashThread, args=(sec, freq,))\r\n        self.th.start()\r\n        \r\n    def chkLedOnThread(self):\r\n        if hasattr(self, 'th'):\r\n            return self.th.isAlive()\r\n        else:\r\n            return False\r\n\r\n    def waitLedOnThread(self):\r\n        if hasattr(self, 'th'):\r\n            self.th.join()\r\n\r\n    def changeRate(self, rate):\r\n        self.rate = rate\r\n\r\n    def CleanUp(self):\r\n        GPIO.cleanup(self.gpio_num)<\/pre>\n<p><span style=\"font-size: 14pt;\">\u3000\u8efd\u304f\u8aac\u660e\u3002MyLED(GPIO\u756a\u53f7)\u3067\u30a4\u30f3\u30b9\u30bf\u30f3\u30b9\u3092\u751f\u6210\u3002<\/span><\/p>\n<ul>\n<li><span style=\"font-size: 14pt;\">Light_ON\u30e1\u30bd\u30c3\u30c9\u3000LED\u70b9\u706f\u3002sec\u306f\u70b9\u706f\u79d2\u6570(0\u3060\u3068\u305a\u3063\u3068\u70b9\u706f)\u3001rate\u306fLED\u306e\u660e\u308b\u3055\u3001freq\u306fPWM\u306e\u5468\u6ce2\u6570(\u901a\u5e38\u306f50\u3067OK)<\/span><\/li>\n<li><span style=\"font-size: 14pt;\">Hotaru_ON\u30e1\u30bd\u30c3\u30c9\u3000\u30db\u30bf\u30eb\u306e\u3088\u3046\u306a\u77ac\u304d\u3092\u3002sec\u306f\u70b9\u706f\u6642\u9593\u3001interval\u306f\u3064\u3044\u3066\u6d88\u3048\u308b\u307e\u3067\u306e\u6642\u9593\u3001r\u306f\u5909\u5316\u3059\u308b\u30ec\u30fc\u30c8(\u6570\u5024\u304c\u591a\u3044\u307b\u3069\u8ae7\u8abf\u304c\u7d30\u304b\u304f\u306a\u308b)\u3001freq\u306f\u540c\u3058<\/span><\/li>\n<li><span style=\"font-size: 14pt;\">Flash_ON\u30e1\u30bd\u30c3\u30c9\u3000\u70b9\u6ec5\u70b9\u706f\u3002f_sec\u306f\u70b9\u6ec5\u9593\u9694\u6642\u9593\u3002\u4ed6\u306fLight_ON\u3068\u4e00\u7dd2<\/span><\/li>\n<li><span style=\"font-size: 14pt;\">waitLedOnThread\u30e1\u30bd\u30c3\u30c9\u3000Light_ON\u3001Hotaru_ON\u3001Flash_ON\u306f\u30b9\u30ec\u30c3\u30c9\u3067\u52d5\u4f5c\u3059\u308b\u306e\u3067\u305d\u306e\u30b9\u30ec\u30c3\u30c9\u304c\u7d42\u308f\u308b\u307e\u3067\u5f85\u6a5f\u3059\u308b\u30e1\u30bd\u30c3\u30c9\u3002sec=0\u3092\u6307\u5b9a\u3057\u305f\u5834\u5408\u547c\u3073\u51fa\u3059\u3068\u7121\u9650\u30eb\u30fc\u30d7\u306b\u306a\u308b\u306e\u3067\u6ce8\u610f<\/span><\/li>\n<li><span style=\"font-size: 14pt;\">changeRate\u30e1\u30bd\u30c3\u30c9\u3000Ligtht_ON\u30e1\u30bd\u30c3\u30c9\u3001Flash_ON\u30e1\u30bd\u30c3\u30c9\u3069\u52d5\u4f5c\u3057\u3066\u308b\u30b9\u30ec\u30c3\u30c9\u306eLED\u306e\u660e\u308b\u3055\u3092\u5909\u3048\u308b\u3002Hotaru_ON\u306f\u610f\u5473\u306a\u3057<\/span><\/li>\n<li><span style=\"font-size: 14pt;\">Light_OFF\u30e1\u30bd\u30c3\u30c9\u3000LED\u306e\u5404\u7a2e\u70b9\u706f\u30b9\u30ec\u30c3\u30c9\u3092\u6b62\u3081\u308b<\/span><\/li>\n<li><span style=\"font-size: 14pt;\">CleanUp\u30e1\u30bd\u30c3\u30c9\u3000GPIO\u30d4\u30f3\u306e\u958b\u653e<\/span><\/li>\n<\/ul>\n<p><span style=\"font-size: 14pt;\">\u3000\u3053\u306e\u30af\u30e9\u30b9\u3067\u306fGPIO.output\u30e1\u30bd\u30c3\u30c9\u3060\u3068\u660e\u308b\u3055\u3092\u5236\u5fa1\u3067\u304d\u306a\u3044\u304b\u3089\u3001LED\u306e\u70b9\u706f\u5236\u5fa1\u306fPWM\u3092\u3059\u3079\u3066\u4f7f\u3044\u307e\u3057\u305f\u3002<\/span><\/p>\n<p><span style=\"font-size: 14pt;\">\u3067\u3001\u5b9f\u969b\u306e\u30af\u30e9\u30b9\u3092\u4f7f\u3063\u3066\u70b9\u706f\u3055\u305b\u308b\u30b3\u30fc\u30c9\u3002GPIO18\u306b\u7dd1LED\u3068\u62b5\u6297\u3001GPIO17\u306b\u8d64LED\u3068\u62b5\u6297\u3001GPIO27\u306b\u9752LED\u3068\u62b5\u6297\u3092\u63a5\u7d9a\u3057\u3066\u3044\u307e\u3059\u3002GND\u306f\u30d6\u30ec\u30c3\u30c9\u30dc\u30fc\u30c9\u3067\u307e\u3068\u3081\u3066\u63a5\u7d9a\u3002Frizing\u3092\u4f7f\u3063\u3066\u521d\u3081\u3066\u66f8\u3044\u3066\u307f\u305f\u3051\u3069\u30fb\u30fb\u30fb\u306a\u3093\u304b\u91cd\u306a\u3063\u3066\u4e0b\u624bw<\/span><\/p>\n<p><a href=\"http:\/\/androiphone.uvs.jp\/wp-content\/uploads\/2019\/10\/led-e1572328705693.jpg\"><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-medium wp-image-2342\" src=\"http:\/\/androiphone.uvs.jp\/wp-content\/uploads\/2019\/10\/led-e1572328705693-300x300.jpg\" alt=\"\" width=\"300\" height=\"300\" srcset=\"https:\/\/androiphone.uvs.jp\/wp-content\/uploads\/2019\/10\/led-e1572328705693-300x300.jpg 300w, https:\/\/androiphone.uvs.jp\/wp-content\/uploads\/2019\/10\/led-e1572328705693-150x150.jpg 150w, https:\/\/androiphone.uvs.jp\/wp-content\/uploads\/2019\/10\/led-e1572328705693-768x768.jpg 768w, https:\/\/androiphone.uvs.jp\/wp-content\/uploads\/2019\/10\/led-e1572328705693-144x144.jpg 144w, https:\/\/androiphone.uvs.jp\/wp-content\/uploads\/2019\/10\/led-e1572328705693.jpg 846w\" sizes=\"auto, (max-width: 300px) 100vw, 300px\" \/><\/a><\/p>\n<pre class=\"lang:python decode:true\">import time\r\nfrom myled import MyLED\r\n\r\nins = MyLED(18)\r\nins2 = MyLED(17)\r\nins3 = MyLED(27)\r\n\r\ntry:\r\n    ins.Hotaru_ON(0)\r\n    ins2.Flash_ON(0,10,0.1)\r\n    ins3.Hotaru_ON(0,1.6)\r\n    \r\n    ins.waitLedOnThread()\r\n\r\nfinally:\r\n    ins.Light_OFF()\r\n    ins.CleanUp()\r\n    ins2.Light_OFF()\r\n    ins2.CleanUp()\r\n    ins3.Light_OFF()\r\n    ins3.CleanUp()<\/pre>\n<p><iframe loading=\"lazy\" width=\"560\" height=\"315\" src=\"https:\/\/www.youtube.com\/embed\/_OQhrPwx5KQ\" frameborder=\"0\" allowfullscreen=\"allowfullscreen\"><\/iframe><br \/>\n<span style=\"font-size: 14pt;\">\u3000\u30b9\u30ec\u30c3\u30c9\u3067\u52d5\u4f5c\u3059\u308b\u306e\u3067\u3001\u30d1\u30e9\u30ec\u30eb\u306bLED\u3092\u5236\u5fa1\u3059\u308b\u3053\u3068\u304c\u3067\u304d\u308b\u3088\u3046\u306b\u306a\u308a\u307e\u3057\u305f\u3002\u4e0a\u306e\u30b3\u30fc\u30c9\u3060\u3068ins.waitLedOnThread()\u304c\u306a\u3044\u3068\u3001\u5b9f\u884c\u306e\u77ac\u9593finally\u306b\u6d41\u3055\u308c\u3066\u3057\u307e\u3046\u306e\u3067\u3001\u5f85\u6a5f\u306e\u305f\u3081\u306b\u547c\u3073\u51fa\u3057\u3066\u3044\u308b(ins\u306f\u30db\u30bf\u30eb\u3067\u6c38\u9060\u306b\u70b9\u706f\u4e2d\u306a\u306e\u3067\u6c38\u9060\u306b\u5f85\u3064\u3053\u3068\u306b\u306a\u308b)\u3002<\/span><\/p>\n<p><span style=\"font-size: 14pt;\">\u3000\u3053\u308c\u3060\u3068\u3001\u4ed6\u306e\u30bb\u30f3\u30b5\u30fc\u306e\u691c\u51fa\u4e2d\u3068\u304b\u3001\u52d5\u4f5c\u4e2d\u3068\u304b\u306b\u4f7f\u3044\u3084\u3059\u304f\u306a\u308b\u306e\u304b\u306a\u3068\u601d\u3046\u3002\u3067\u3082Python\u3055\u308f\u3063\u30661\u9031\u9593\u7a0b\u5ea6\u306a\u306e\u3067\u30fb\u30fb\u30fb\u53c2\u8003\u7a0b\u5ea6\u306b\u2026<\/span><\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u3000I2C\u306e\u3053\u3068\u3070\u3063\u304b\u308a\u3084\u3063\u3066\u305f\u3089\u3001GPIO\u3092\u7528\u3044\u3066LED\u3092\u5149\u3089\u305b\u308b\u3068\u304b\u5168\u304f\u30b9\u30eb\u30fc\u3057\u3066\u305fw\u3002Python\u3082\u307e\u3068\u3082\u306b\u6253\u3066\u306a\u3044\u3057\u3001\u305d\u3082\u305d\u3082\u30af\u30e9\u30b9\u3068\u304b\u3044\u3046\u524d\u306b\u5236\u5fa1\u6587(if\u3001while\u3001for)\u3068\u304b\u3082\u3001\u307e\u3068\u3082\u306b\u66f8\u3051\u306a\u3044\u306e\u3067\u3001\u52c9\u5f37\u304c [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":2342,"comment_status":"closed","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_locale":"","_original_post":"","footnotes":""},"categories":[58,56],"tags":[],"class_list":["post-2314","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-python","category-raspberry-pi","ja"],"_links":{"self":[{"href":"https:\/\/androiphone.uvs.jp\/index.php?rest_route=\/wp\/v2\/posts\/2314","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/androiphone.uvs.jp\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/androiphone.uvs.jp\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/androiphone.uvs.jp\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/androiphone.uvs.jp\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=2314"}],"version-history":[{"count":18,"href":"https:\/\/androiphone.uvs.jp\/index.php?rest_route=\/wp\/v2\/posts\/2314\/revisions"}],"predecessor-version":[{"id":3155,"href":"https:\/\/androiphone.uvs.jp\/index.php?rest_route=\/wp\/v2\/posts\/2314\/revisions\/3155"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/androiphone.uvs.jp\/index.php?rest_route=\/wp\/v2\/media\/2342"}],"wp:attachment":[{"href":"https:\/\/androiphone.uvs.jp\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=2314"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/androiphone.uvs.jp\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=2314"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/androiphone.uvs.jp\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=2314"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}