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ではバージョンによって入らない場合もあるかもしれない。
必要なライブラリをインストールしてバージョンを下げてトライします。
以上。

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?