Writing the CodeBug controller program

To interface with PyDance we need to write a tethered CodeBug Python program.

We need to install a Python module that will allow us to generate the arrow keyboard strokes that you need to play PyDance, but first we need to install Pip to be able to install the modules::

sudo apt-get install python3-pip

sudo pip-3.2 install python3-xlib

sudo pip-3.2 install PyUserInput

Create a python program called codebug_dance.py or download it here:

nano codebug_dance.py

And fill it with the code below.

from pykeyboard import PyKeyboard

import time

keyboard = PyKeyboard()

import codebug_tether

cb = codebug_tether.CodeBug()

keys = [ 'Up', 'Right', 'Left', 'Down'] 

pressed = [ False, False, False, False]

while True:

    for i in range(4):

        if not cb.get_input(i):

            if not pressed[i]:

                keyboard.tap_key(keys[i])

                pressed[i] = True

                time.sleep(.01)

        else:

            pressed[i] = False

This code checks if a CodeBug input has been connected to Ground and generates one key press each time the input is pressed.


Activities with this step

Back to top