Simple test

Ensure your device works with this simple test.

examples/wiichuck_simpletest.py
 1# SPDX-FileCopyrightText: 2021 ladyada for Adafruit Industries
 2# SPDX-License-Identifier: MIT
 3
 4import time
 5import board
 6from wiichuck.nunchuk import Nunchuk
 7
 8nc = Nunchuk(board.I2C())
 9
10while True:
11    x, y = nc.joystick
12    ax, ay, az = nc.acceleration
13    print("joystick = {},{}".format(x, y))
14    print("accceleration ax={}, ay={}, az={}".format(ax, ay, az))
15
16    if nc.buttons.C:
17        print("button C")
18    if nc.buttons.Z:
19        print("button Z")
20    time.sleep(0.5)
examples/nunchuk_analog_mouse.py
 1# SPDX-FileCopyrightText: 2021 ladyada for Adafruit Industries
 2# SPDX-License-Identifier: MIT
 3
 4import board
 5import usb_hid
 6from adafruit_hid.mouse import Mouse
 7from wiichuck.nunchuk import Nunchuk
 8
 9m = Mouse(usb_hid.devices)
10nc = Nunchuk(board.I2C())
11
12centerX = 128
13centerY = 128
14
15scaleX = 0.15
16scaleY = 0.15
17
18cDown = False
19zDown = False
20
21# This is to allow double checking (only on left click - and it doesn't really work)
22CHECK_COUNT = 0
23
24
25# This is just to show that we're getting back data - uncomment it and hold down the buttons
26# while True:
27#    print((0 if nc.button_C else 1, 0 if nc.button_Z else 1))
28
29while True:
30
31    x, y = nc.joystick
32    # Eliminate spurious reads
33    if x == 255 or y == 255:
34        continue
35    relX = x - centerX
36    relY = centerY - y
37
38    m.move(int(scaleX * relX), int(scaleY * relY), 0)
39
40    buttons = nc.buttons
41    c = buttons.C
42    z = buttons.Z
43
44    if z and not zDown:
45        stillDown = True
46        for n in range(CHECK_COUNT):
47            if nc.button_Z:
48                stillDown = False
49                break
50        if stillDown:
51            m.press(Mouse.LEFT_BUTTON)
52            zDown = True
53    elif not z and zDown:
54        stillDown = True
55        for n in range(CHECK_COUNT):
56            if not nc.button_Z:
57                stillDown = False
58                break
59        if stillDown:
60            m.release(Mouse.LEFT_BUTTON)
61            zDown = False
62    if c and not cDown:
63        m.press(Mouse.RIGHT_BUTTON)
64        cDown = True
65    elif not c and cDown:
66        m.release(Mouse.RIGHT_BUTTON)
67        cDown = False
examples/nunchuk_accel_mouse.py
 1# SPDX-FileCopyrightText: 2021 ladyada for Adafruit Industries
 2# SPDX-License-Identifier: MIT
 3
 4import board
 5import usb_hid
 6from adafruit_hid.mouse import Mouse
 7from wiichuck.nunchuk import Nunchuk
 8
 9m = Mouse(usb_hid.devices)
10nc = Nunchuk(board.I2C())
11
12centerX = 120
13centerY = 110
14
15scaleX = 0.4
16scaleY = 0.5
17
18cDown = False
19zDown = False
20
21# This is to allow double checking (only on left click - and it doesn't really work)
22CHECK_COUNT = 0
23
24
25# This is just to show that we're getting back data - uncomment it and hold down the buttons
26# while True:
27#    print((0 if nc.button_C else 1, 0 if nc.button_Z else 1))
28
29while True:
30
31    accel = nc.acceleration
32    #    print(accel)
33    #    x, y = nc.joystick
34    #    print((x,y))
35    x = accel[0] / 4
36    y = accel[1] / 4
37    print((x, y))
38    # Eliminate spurious reads
39    if x == 255 or y == 255:
40        continue
41    relX = x - centerX
42    relY = y - centerY
43
44    m.move(int(scaleX * relX), int(scaleY * relY), 0)
45    buttons = nc.buttons
46
47    c = buttons.C
48    z = buttons.Z
49
50    if z and not zDown:
51        stillDown = True
52        for n in range(CHECK_COUNT):
53            if nc.button_Z:
54                stillDown = False
55                break
56        if stillDown:
57            m.press(Mouse.LEFT_BUTTON)
58            zDown = True
59    elif not z and zDown:
60        stillDown = True
61        for n in range(CHECK_COUNT):
62            if not nc.button_Z:
63                stillDown = False
64                break
65        if stillDown:
66            m.release(Mouse.LEFT_BUTTON)
67            zDown = False
68    if c and not cDown:
69        m.press(Mouse.RIGHT_BUTTON)
70        cDown = True
71    elif not c and cDown:
72        m.release(Mouse.RIGHT_BUTTON)
73        cDown = False
examples/classic_controller_simpletest.py
 1# SPDX-FileCopyrightText: 2021 John Furcean
 2# SPDX-License-Identifier: MIT
 3
 4import board
 5from wiichuck.classic_controller import ClassicController
 6
 7controller = ClassicController(board.I2C())
 8
 9while True:
10    joysticks, buttons, dpad, triggers = controller.values
11
12    # center for the right joystick is (16,16)
13    if (joysticks.rx, joysticks.ry) != (16, 16):
14        print("Right joystick = {},{}".format(joysticks.rx, joysticks.ry))
15
16    # center for the left joystick is (32,32)
17    if (joysticks.lx, joysticks.ly) != (32, 32):
18        print("Left joystick = {},{}".format(joysticks.lx, joysticks.ly))
19
20    # triggers when not pressed is at (0,0)
21    # Classic Controler Pro as no potentiometer and only report 0 or 31
22    if (triggers.left, triggers.right) != (0, 0):
23        print("Trigger left and right = {},{}".format(triggers.left, triggers.right))
24
25    if buttons.A:
26        print("button A")
27    if buttons.B:
28        print("button B")
29    if buttons.X:
30        print("button X")
31    if buttons.Y:
32        print("button Y")
33    if buttons.R:
34        print("button R")
35    if buttons.L:
36        print("button L")
37    if buttons.ZR:
38        print("button ZR")
39    if buttons.ZL:
40        print("button ZL")
41    if buttons.start:
42        print("button start")
43    if buttons.select:
44        print("button select")
45    if buttons.home:
46        print("button home")
47
48    if dpad.up:
49        print("dpad up")
50    if dpad.down:
51        print("dpad down")
52    if dpad.right:
53        print("dpad right")
54    if dpad.left:
55        print("dpad left")
examples/classic_controller_pro_simpletest.py
 1# SPDX-FileCopyrightText: 2021 John Furcean
 2# SPDX-License-Identifier: MIT
 3
 4import board
 5from wiichuck.classic_controller import ClassicController
 6
 7controller = ClassicController(board.I2C())
 8
 9while True:
10    # Classic Controller Pro has no trigger/potentiometer and only use L and R
11    joysticks, buttons, dpad, _ = controller.values
12
13    # center for the right joystick is (16,16)
14    if (joysticks.rx, joysticks.ry) != (16, 16):
15        print("Right joystick = {},{}".format(joysticks.rx, joysticks.ry))
16
17    # center for the left joystick is (32,32)
18    if (joysticks.lx, joysticks.ly) != (32, 32):
19        print("Left joystick = {},{}".format(joysticks.lx, joysticks.ly))
20
21    if buttons.A:
22        print("button A")
23    if buttons.B:
24        print("button B")
25    if buttons.X:
26        print("button X")
27    if buttons.Y:
28        print("button Y")
29    if buttons.R:
30        print("button R")
31    if buttons.L:
32        print("button L")
33    if buttons.ZR:
34        print("button ZR")
35    if buttons.ZL:
36        print("button ZL")
37    if buttons.start:
38        print("button start")
39    if buttons.select:
40        print("button select")
41    if buttons.home:
42        print("button home")
43
44    if dpad.up:
45        print("dpad up")
46    if dpad.down:
47        print("dpad down")
48    if dpad.right:
49        print("dpad right")
50    if dpad.left:
51        print("dpad left")
examples/guitar_simpletest.py
 1# SPDX-FileCopyrightText: Copyright (c) 2021 John Furcean
 2#
 3# SPDX-License-Identifier: MIT
 4import board
 5from wiichuck.guitar import Guitar
 6
 7guitar = Guitar(board.I2C())
 8
 9while True:
10
11    joystic, buttons, strum, whammy, touchbar = guitar.values
12
13    # Joystick: (0-63,0-63), middle is (32,32)
14    if joystic != (32, 32):
15        print(f"Joystick (x,y): {joystic}")
16
17    # Whammy Bar: 0-31
18    if whammy > 0:
19        print(f"Whammy Bar: {whammy}")
20
21    # strum
22    if strum.up:
23        print("STRUM UP")
24    if strum.down:
25        print("STRUM DOWN")
26
27    # Neck Buttons
28    if buttons.orange:
29        print("Button Pressed: ORANGE")
30    if buttons.blue:
31        print("Button Pressed: BLUE")
32    if buttons.yellow:
33        print("Button Pressed: YELLOW")
34    if buttons.red:
35        print("Button Pressed: RED")
36    if buttons.green:
37        print("Button Pressed: GREEN")
38
39    if buttons.plus:
40        print("Button Pressed: PLUS")
41    if buttons.minus:
42        print("Button Pressed: MINUS")
examples/udraw_simpletest.py
 1# SPDX-FileCopyrightText: 2021 John Furcean
 2# SPDX-License-Identifier: MIT
 3
 4import board
 5from wiichuck.udraw import UDraw
 6
 7controller = UDraw(board.I2C())
 8
 9while True:
10    position, buttons, pressure = controller.values
11
12    # off grid position is (4095,4095)
13    if (position.x, position.y) != (4095, 4095):
14        print("Pen position = {},{}".format(position.x, position.y))
15
16    # off pressure on the tip of the pen is 8
17    if pressure != 8:
18        print("Pen pressure = {}".format(pressure))
19
20    if buttons.C:
21        print("button C")
22    if buttons.Z:
23        print("button Z")
24    if buttons.tip:
25        print("button tip")
examples/udraw_mouse.py
 1# SPDX-FileCopyrightText: 2021 David Glaude
 2# SPDX-License-Identifier: MIT
 3
 4import board
 5import usb_hid
 6from adafruit_hid.mouse import Mouse
 7from wiichuck.udraw import UDraw
 8
 9udraw = UDraw(board.I2C())
10
11m = Mouse(usb_hid.devices)
12
13zDown = False
14pDown = False
15
16oldx = 4095
17oldy = 4095
18
19while True:
20    # We don't use the pressure, maybe converting to watcom protocol would permit that
21    position, buttons, _ = udraw.values
22
23    P = buttons.tip or buttons.C  # Both the C button and tip work as LEFT mouse click
24
25    # Handeling the button to create mouse click
26    if P and not pDown:
27        m.press(Mouse.LEFT_BUTTON)
28        pDown = True
29    elif not P and pDown:
30        m.release(Mouse.LEFT_BUTTON)
31        pDown = False
32
33    if buttons.Z and not zDown:
34        m.press(Mouse.RIGHT_BUTTON)
35        zDown = True
36    elif not buttons.Z and zDown:
37        m.release(Mouse.RIGHT_BUTTON)
38        zDown = False
39
40    # Values (4095,4095) mean the pen is not near the tablet
41    if position.x == 4095 or position.y == 4095:
42        oldx = 4095
43        oldy = 4095
44        continue  # We remember that the pen was raised UP
45
46    # If we reach here, the pen was UP and is now DOWN
47    if oldx == 4095 or oldy == 4095:
48        oldx = position.x
49        oldy = position.y
50        continue
51
52    if (position.x != oldx) or (
53        position.y != oldy
54    ):  # PEN has moved we move the HID mouse
55        m.move((position.x - oldx), (oldy - position.y), 0)
56        oldx = position.x
57        oldy = position.y