🎮 ボタン入力値の出力


✅ 概要

コーディングドローンで使用する送信機のボタン入力(押下)状態をリアルタイムで取得・出力します。


🔁 実行の流れ

  1. 通信の有効化
  2. イベント関数の登録
  3. ボタンイベントの受信

🎯 出力されるボタン値(例)

ボタン名 値 (Hex) 値 (Decimal)
↑ ボタン 0x0040 64
↓ ボタン 0x0200 512
→ ボタン 0x0100 256
← ボタン 0x0080 128
S ボタン 0x0400 1024
P ボタン 0x0800 2048
電源ボタン 0x0020 32
H ボタン(トリム) 0x0010 16

※複数ボタンが同時に押された場合、ビット演算の合計値になります。

from time import sleep

from CodingDrone.drone import *
from CodingDrone.protocol import *

def eventButton(button):
    print("eventButton() / " +
        "Button: 0b{0:16}, Event: {1:6}".format(bin(button.button)[2:].zfill(16), 
         button.event.name))

if __name__ == '__main__':

    drone = Drone()
    drone.open()

    # イベントハンドリング関数登録
    drone.setEventHandler(DataType.Button, eventButton)

    drone.sendPing(DeviceType.Controller)

    for i in range(10, 0, -1):
        print(i)
        sleep(1)

    drone.close()

🎮 ジョイスティック入力値の出力


✅ 概要

コーディングドローンで使用するコントローラのジョイスティック入力情報をリアルタイムで取得・出力します。