Samples_GPIO - gfd-dennou-club/mrubyc-esp32 GitHub Wiki

ăŻă˜ă‚ă«Â¶ ↑

GPIO ă‚Żăƒ©ă‚čăźăƒĄă‚œăƒƒăƒ‰ă«ă€ă„ăŠăŻïŒŒClass_GPIO ă‚’ć‚ç…§ă•ă‚ŒăŸă„ïŒŽ

L ăƒă‚«Â¶ ↑

LED (GPIO 13) を 1 ç§’ăŠăă«ç‚čæ»…ă•ă›ă‚‹ăƒ—ăƒ­ă‚°ăƒ©ăƒ ăŻä»„äž‹ăźă‚ˆă†ă«æ›žă‘ă°è‰Żă„ïŒŽ

#ă‚€ăƒłă‚čタンă‚čăźäœœæˆ. LED ăźæŽ„ç¶šă•ă‚ŒăŠă„ă‚‹ăƒ”ăƒł (GPIO 13) をć‡șćŠ›ă«èš­ćźš.
led1 = GPIO.new( 13, GPIO::OUT )

loop do
  led1.write(1)  # pin ăźć€€ă‚’ăƒă‚€ăƒŹăƒ™ăƒ«ă«
  sleep 1        # 1 ç§’ćŸ…ă€

  led1.write(0)  # pin ăźć€€ă‚’ăƒ­ăƒŒăƒŹăƒ™ăƒ«ă«
  sleep 1        # 1 ç§’ćŸ…ă€
end

L ăƒă‚«ăšă‚čă‚€ăƒƒăƒÂ¶ ↑

ă‚čă‚€ăƒƒăƒ(GPIO 34)ず LED (GPIO 13) ă‚’é€Łć‹•ă•ă›ă‚‹ć Žćˆă«ăŻïŒŒä»„äž‹ăźă‚ˆă†ăȘăƒ—ăƒ­ă‚°ăƒ©ăƒ ă‚’æ›žă‘ă°è‰Żă„.

# LED ăźæŽ„ç¶šă•ă‚ŒăŠă„ă‚‹ăƒ”ăƒł (GPIO 13) をć‡șćŠ›ă«èš­ćźš.
led1 = GPIO.new( 13, GPIO::OUT )
# ă‚čă‚€ăƒƒăƒăźæŽ„ç¶šă•ă‚ŒăŠă„ă‚‹ăƒ”ăƒł (GPIO 34) ă‚’ć…„ćŠ›ă«èš­ćźš. ăƒ—ăƒ«ă‚ąăƒƒăƒ—ă™ă‚‹.
sw1  = GPIO.new( 34, GPIO::IN, GPIO::PULL_UP )

loop do
   if (sw1.read == 0) #ă‚čă‚€ăƒƒăƒăźăƒ”ăƒłăźć€€ăŒăƒ­ăƒŒăƒŹăƒ™ăƒ«ăźæ™‚
     led1.write(1)       # LED ăźăƒ”ăƒłăźć€€ă‚’ăƒă‚€ăƒŹăƒ™ăƒ«ă«
   else
     led1.write(0)       # LED ăźăƒ”ăƒłăźć€€ă‚’ăƒ­ăƒŒăƒŹăƒ™ăƒ«ă«
   end

   sleep 1
end
⚠ **GitHub.com Fallback** ⚠