Circuit Playground Express ã®å種æ©è½ã試ã(2)
ç°å¢::
- CircuitPlaygroundExpress : Bootloader 3.10.0
- CircuitPython : 5.0
ã©ã¤ãã©ãªã§è²å½©/æ度/彩度 ãæ±ã
ã©ã¡ããã¨ããã° CircuitPython ã®æ©è½ã§ã ã©ã¤ãã©ãª ããã³ãã¼ãã¦ä½¿ãã
å
¨é¨ã®ã©ã¤ãã©ãªãã³ãã¼ã¯ã§ããªãã®ã§ãä»å使ããã®ã ãã
ãã®ä¸ã§
import time import board import neopixel import adafruit_fancyled.adafruit_fancyled as fancy npx = neopixel.NeoPixel(board.NEOPIXEL, 10, auto_write=False) while True: for pp in range(10): h = (pp * (1.0/10)) hsvcolor = fancy.CHSV(h, 1.0, 0.2) npx[pp] = hsvcolor.pack() npx.show() time.sleep(0.2)
ããã¨
綺éºãªã°ã©ãã¼ã·ã§ã³ã§ããâ¦
å å¦ã»ã³ãµã¼ã§æããè¨æ¸¬
import time import analogio import board light = analogio.AnalogIn(board.LIGHT) while True: print((light.value,)) time.sleep(1.0)
ã¨ããã¨ãé¨å±ã®èå ç¯ã§ãããªæãã§ã
(3168,) # èå ç¯ã®å (3136,) (800,) # æã§é ãã (720,) (720,)
ã¿ããã»ã³ãµã¼
ã¿ããã»ã³ãµã¼ã«ãã£ã¦ LED ã®è²ãå¤åãããããã°ã©ã
ã¿ããã»ã³ãµã¼ã¯å¨è¾ºã®ç©´ã®ç©ºãã端åã§ãããä»å A1, A2, A5, A6 ã使ãã¾ãã
以ä¸ã®åçã«ããããã®é
ç½®ãããªã³ãããã¦ã¾ãã
A ã·ãªã¼ãºã¯ãã¹ã¦æä½å¯è½ãªã®ã¯ããã£ã¦ã¾ããããRGB ãããããã ãã§ããã®ã§ä»åã¯é¿ãã¾ããã
import time import board import neopixel import touchio from simpleio import map_range # LED ã»ããã¢ãã npx = neopixel.NeoPixel(board.NEOPIXEL, 10, auto_write=True) # ã¿ããã»ã³ãµã¼ãè¨å®ãã touch_A1 = touchio.TouchIn(board.A1) touch_A2 = touchio.TouchIn(board.A2) touch_A5 = touchio.TouchIn(board.A5) touch_A6 = touchio.TouchIn(board.A6) # è²ã®ã»ãã r_in = 0 g_in = 0 b_in = 0 while True: # ã¿ããããã»ã³ãµã¼ã«ãã£ã¦ RGB ãæ±ºå® if touch_A1.value: r_in += 1 if touch_A2.value: g_in += 1 if touch_A5.value: b_in += 1 if touch_A6.value: r_in -= 1 g_in -= 1 b_in -= 1 # 0 - 255 ã¾ã§ã«æãã r_in = 0 if r_in < 0 else r_in g_in = 0 if g_in < 0 else g_in b_in = 0 if b_in < 0 else b_in r_in = 255 if r_in > 255 else r_in g_in = 255 if g_in > 255 else g_in b_in = 255 if b_in > 255 else b_in # LED ã«è²ãæ¸ãè¾¼ã npx[7] = (r_in, g_in, b_in) time.sleep(0.2)
ã§ã¡ãã£ã¨ãã£ã¦ã¿ãã®ããã® 2 æ
ã¿ããæéã«ãã£ã¦è²ãå¤åãã¾ãã