1
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?

【備忘録】Raspberry Pi Pico で CircuitPython を使って DVI 出力する方法(その2)

Posted at

0. はじめに

以前、↓こちらの記事を書きました。

今回、タクトスイッチ4個 と ブザー が搭載された、以前と 違うタイプの HDMI 出力ボードを入手したので、これを使う方法をまとめておきます。

PICO-HDMI-PLUS.jpg

1. Pinout

DVI に関するピンは、以前の記事のAdafruit DVI Breakout Boardと同じです。

Pinout
DVI Pico
TXC- GP15
TXC+ GP14
TX0- GP13
TX0+ GP12
TX1- GP19
TX1+ GP18
TX2- GP17
TX2+ GP16
Buzzer Pico
Buzzer GP8









Switch Pico
common GP9
SW1 GP10
SW2 GP11
SW3 GP20
SW4 GP21




  • 回路図
PICO-HDMI-PLUS_circuit.jpg

Switch(タクトスイッチ)回路は要注意です(後述)。

2. Buzzer 鳴動

次のコードで任意の周波数の音を出すことができます。

CircuitPython(440Hzの音を0.5秒出力)
import time
import board
import pwmio

buzzer_OFF, buzzer_ON = 0, 0x8000

buzzer = pwmio.PWMOut(board.GP8, variable_frequency=True)

buzzer.frequency = 440  # 440Hz : A4

buzzer.duty_cycle = buzzer_ON

time.sleep(0.5) # 0.5秒

buzzer.duty_cycle = buzzer_OFF

3. Switch チェック

次のコードでボタン(タクトスイッチ)の押下状況をチェックできます。

CircuitPython(SW1〜SW4をチェック)
import time
import board
import digitalio

GP9 = digitalio.DigitalInOut(board.GP9)
GP9.direction = digitalio.Direction.OUTPUT
GP9.value = True

buttonPins = [board.GP10, board.GP11, board.GP20, board.GP21]
btns = []
for pin in buttonPins:
    button = digitalio.DigitalInOut(pin) 
    #button.pull = digitalio.Pull.UP
    btns.append(button)

prev_pushed = 0
while True:
    time.sleep(0.05)
    pushed = 0
    for index, btn in enumerate(btns):
        if not btn.value: pushed |= (1 << index)
    if prev_pushed == pushed: continue
    prev_pushed = pushed
    for index in range(len(btns)):
        if pushed & (1 << index):
            print(f"sw{index + 1} ", end='')
        else:
            print(' '*4, end='')
    print()

GP9を HIGH にする必要があります。
これを忘れると、ボタンの3つ同時押しで誤動作(誤検知)します。
(GP9を HIGH にすれば外部プルアップは不要となる)

4. SIMONゲーム

せっかくボタンとブザーが付いているので、元祖「 ゲー 」サイモンを作ってみました。

ボタンと音の関係は次の通り。

黄色 青色 緑色 赤色
SW1 SW2 SW3 SW4
209 Hz 252 Hz 310 Hz 415 Hz

以前の記事と同じ環境

参考

- Pico DVI

- Simon

- Wokmi (Arduino)

(コードの一部を参考にさせてもらいました)





以上

1
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
1
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?