Microsoft MakeCode

Keyboard extension problem

Creating an app for CPX to send keystrokes to the computer.
After downloading image to CPX, the CPX is not recognized anymore by the computer. So any “keyboard type” block use fails.

Any insights?
How can I make the CPX show up as usb device after downloading the program to it?

Forgot to mention that CPX shows up in port /dev/tty.usbmodemFA131 when ready to accept a new program. But as soon one is copied into it, the usb closes.

I found the problem.
In the “forever” loop provided by make code, I had a “while” loop waiting for a pin press, then reading the pin values, next calling one of the blocks for emulating typing on the keyboard, and lastly another “while” loop waiting for the release of the pin.

Apparently, the nested while loop inside the for loop did not play well with the keyboard instructions --I tested this setup by lighting up different neopixels, and it seemed to work out just fine…as soon as I introduce the keyboard-related blocks, the CPX stop showing up as a USB device connected to the computer.

I redid the code using flags and if/else statements instead, and works just fine.

Forever loop has an implicit pause. Try adding a pause to your loop. When you pause you let other code run, including the USB handling code. It should in principle run in interrupts but maybe there are some issues with it.

1 Like

Aah…thanks for the tip. I’ll try that. :+1: