0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

概要

電子工作コンテスト、見つけたので、やってみる。

ピン配置図(ビジュアルイメージ)

PicoをUSB端子が上にくるように置いたときの、具体的なピンの位置です。

      [ USB 端子 ]
    +---------------+
 1  | GP0      VBUS | 40  =======> [ LEDの VCC (5V) へ ]

    |               |
    |               |
 22 | GP17     GND  | 38  =======> [ LEDの GND へ ]
    |               |
    |          3v3  | 36  =======> [ VR の VDD へ ]
    |               |
    |               |
    |          gnd  | 33  =======> [ VR の GND へ ]
    |          adc1 | 32  =======> [ VR の VR1 へ ]
    |          adc0 | 31  =======> [ VR の VR0 へ ]
    |               |

    
    +---------------+
 ||
 ||
 +=========================> [ LEDの DIN (信号) へ ]

プログラムの永続化、手順

電源が切れても、main.pyで起動する。

フォルダを掘る。

>mkdir pico
>cd picp

main.pyを書く。


import array
import time
import rp2
from machine import ADC, Pin
vr_sensor = ADC(Pin(26))
V_REF = 3.3
@rp2.asm_pio(sideset_init = rp2.PIO.OUT_LOW, autopull = True, pull_thresh = 24, out_shiftdir = rp2.PIO.SHIFT_LEFT)
def ws2812():
   label("loop")
   out(x, 1)
   nop().side(1)
   jmp(not_x, "tugi")
   nop()
   nop()
   nop().side(0)
   label("tugi")
   nop().side(0)
   nop()
   jmp("loop")
sm = rp2.StateMachine(0, ws2812, freq = 5_000_000, sideset_base = Pin(17))
sm.active(1)
def main():
   global sm
   NUM_LEDS = 7
   ar = array.array("I", [0 for _ in range(NUM_LEDS)])
   step = 0
   adc_counter = 0
   color_mix = 0.0
   print("start")
   while True:
      raw_value = vr_sensor.read_u16()
      color_mix = raw_value / 65535.0
      adc_counter += 1
      if adc_counter >= 7:
         voltage = color_mix * V_REF
         print(f"VR Raw: {raw_value:5d} | Voltage: {voltage:.3f} V | Mix: {color_mix:.2f}")
         adc_counter = 0
      for j in range(NUM_LEDS):
         pos = (step + j * 10) % 300
         if pos < 100:
            g_base = 100 - pos
            b_base = pos
            r_base = 0
         elif pos < 200:
            pos_sub = pos - 100
            g_base = 0
            b_base = 100 - pos_sub
            r_base = pos_sub
         else:
            pos_sub = pos - 200
            g_base = pos_sub
            b_base = 0
            r_base = 100 - pos_sub
         r = int(r_base * color_mix)
         g = int(g_base * (1.0 - abs(color_mix - 0.5) * 2))
         b = int(b_base * (1.0 - color_mix))
         r >>= 1
         g >>= 1
         b >>= 1
         ar[j] = (r << 16) | (g << 8) | b
      sm.put(ar, 8)
      step += 1
      time.sleep_ms(30)


ampyで焼く。

>ampy -p COM3 put main.py

以上。

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?