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?

Jupyter lab上でジョイスティックF710を使おう。

Last updated at Posted at 2022-11-13

ポイントは、ビデオをダミーにします。
jetson nanoではバージョンによって入らない場合もあるかもしれない。
必要なライブラリをインストールしてバージョンを下げてトライします。
以上。

ビルドに必要なライブラリは依存関係でうまくインストールできない場合があります。

sudo apt update

依存関係を修正

sudo apt --fix-broken install

pygameに必要なライブラリをインストール

sudo apt install -y libsdl2-dev libsdl2-image-dev libsdl2-mixer-dev libsdl2-ttf-dev
sudo apt install -y python3-dev python3-pip build-essential libffi-dev

pipアップグレード

/home/pi/env/bin/python3 -m pip install --upgrade pip

pygameインストール

pip3 install pygame
import time         
import pygame
import os
from IPython.display import clear_output

#Displayをオフ
os.environ["SDL_VIDEODRIVER"] = "dummy"


pygame.init()
joy = pygame.joystick.Joystick(0)
joy.init()
time.sleep(0.5)

try:
    while True:
        leftStick = int( joy.get_axis(1)*-1023 )
        righSstick = int( joy.get_axis(3)*-1023 )
        button0 = joy.get_button(0)
        button1 = joy.get_button(1)
        button2 = joy.get_button(2)
        button3 = joy.get_button(3)
        pygame.event.pump()

        print("left=%d  right=%d"%(leftStick, righSstick))

        if button0 == 1:
            print("Button_A")
        elif button1 == 1:
            print("Button_B")
        elif button2 == 1:
            print("Button_X")
        elif button3 == 1:
            print("Button_Y")

        time.sleep(0.01)
        clear_output(True)

except( KeyboardInterrupt, SystemExit):
    print( "Ctr + D pushed. EXIT!" )
    
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?