@@ -13,23 +13,23 @@ will look something like this::
1313
1414 import pyb
1515 #pyb.main('main.py') # main script to run after this one
16- #pyb.usb_mode('CDC +MSC') # act as a serial and a storage device
17- #pyb.usb_mode('CDC +HID') # act as a serial device and a mouse
16+ #pyb.usb_mode('VCP +MSC') # act as a serial and a storage device
17+ #pyb.usb_mode('VCP +HID') # act as a serial device and a mouse
1818
1919To enable the mouse mode, uncomment the last line of the file, to
2020make it look like::
2121
22- pyb.usb_mode('CDC +HID') # act as a serial device and a mouse
22+ pyb.usb_mode('VCP +HID') # act as a serial device and a mouse
2323
2424If you already changed your ``boot.py `` file, then the minimum code it
2525needs to work is::
2626
2727 import pyb
28- pyb.usb_mode('CDC +HID')
28+ pyb.usb_mode('VCP +HID')
2929
30- This tells the pyboard to configure itself as a CDC (serial) and HID
31- (human interface device, in our case a mouse) USB device when it boots
32- up.
30+ This tells the pyboard to configure itself as a VCP (Virtual COM Port,
31+ ie serial port) and HID (human interface device, in our case a mouse)
32+ USB device when it boots up.
3333
3434Eject/unmount the pyboard drive and reset it using the RST switch.
3535Your PC should now detect the pyboard as a mouse!
@@ -41,7 +41,8 @@ To get the py-mouse to do anything we need to send mouse events to the PC.
4141We will first do this manually using the REPL prompt. Connect to your
4242pyboard using your serial program and type the following::
4343
44- >>> pyb.hid((0, 10, 0, 0))
44+ >>> hid = pyb.USB_HID()
45+ >>> hid.send((0, 10, 0, 0))
4546
4647Your mouse should move 10 pixels to the right! In the command above you
4748are sending 4 pieces of information: button status, x, y and scroll. The
@@ -52,7 +53,7 @@ Let's make the mouse oscillate left and right::
5253 >>> import math
5354 >>> def osc(n, d):
5455 ... for i in range(n):
55- ... pyb. hid((0, int(20 * math.sin(i / 10)), 0, 0))
56+ ... hid.send ((0, int(20 * math.sin(i / 10)), 0, 0))
5657 ... pyb.delay(d)
5758 ...
5859 >>> osc(100, 50)
@@ -100,9 +101,10 @@ In ``main.py`` put the following code::
100101
101102 switch = pyb.Switch()
102103 accel = pyb.Accel()
104+ hid = pyb.USB_HID()
103105
104106 while not switch():
105- pyb. hid((0, accel.x(), accel.y(), 0))
107+ hid.send ((0, accel.x(), accel.y(), 0))
106108 pyb.delay(20)
107109
108110Save your file, eject/unmount your pyboard drive, and reset it using the RST
@@ -112,7 +114,7 @@ the mouse around. Try it out, and see if you can make the mouse stand still!
112114Press the USR switch to stop the mouse motion.
113115
114116You'll note that the y-axis is inverted. That's easy to fix: just put a
115- minus sign in front of the y-coordinate in the ``pyb. hid() `` line above.
117+ minus sign in front of the y-coordinate in the ``hid.send () `` line above.
116118
117119Restoring your pyboard to normal
118120--------------------------------
@@ -121,9 +123,9 @@ If you leave your pyboard as-is, it'll behave as a mouse everytime you plug
121123it in. You probably want to change it back to normal. To do this you need
122124to first enter safe mode (see above), and then edit the ``boot.py `` file.
123125In the ``boot.py `` file, comment out (put a # in front of) the line with the
124- ``CDC +HID `` setting, so it looks like::
126+ ``VCP +HID `` setting, so it looks like::
125127
126- #pyb.usb_mode('CDC +HID') # act as a serial device and a mouse
128+ #pyb.usb_mode('VCP +HID') # act as a serial device and a mouse
127129
128130Save your file, eject/unmount the drive, and reset the pyboard. It is now
129131back to normal operating mode.
0 commit comments