MicroBit Project #04 for INF 294
Project description:
Using code for MicroBit built in C/C++, Display one dot randomly in the LED matrix. If button A is pressed, active LED moves one LED to the left (clears initial LED). If button B is pressed, active LED moves one LED to the right. Pressing buttons A and B together moves the LED up one row. Whenever the active LED reaches an edge, the next button pressed wraps the LED around to the opposite side of the matrix.
I used the MakeCode editor to test the algorithm in the MicroBit framework, then wrote the code in the mbed compiler to create the HEX file and test the program. The MakeCode editor resulted in four large images of coding blocks and the JavaScript showed the translation out of order. Below is the manual algorithm:
Instantiate a MicroBit object
Assign variables for plotting LED values x(row), y(column), b(brightness currently set to fixed value 255)
Method for initial function: assign random variable to x value assign random variable to y value display randomly generated active LED at coordinates (x,y) with b brightness (x, y, b)
Method for if button A is pressed: if LED is at the far left edge (x == 0), change x value to 4 otherwise, move LED one place to the left (x -= 1) clear the field display active LED at new coordinates
Method for if button B is pressed: if LED is at the far right edge (x == 4), change x value to 0 otherwise, move LED one place to the right (x += 1) clear the field display active LED at new coordinates
Method for if button A+B is pressed: if LED is at the top edge (y == 0), change y value to 4 otherwise, move LED one row up (y -= 1) clear the field display active LED at new coordinates
In main method: initialize MicroBit call method to generate random active LED listen for button events and call appropriate method use release_fiber() to sleep
Please log in to post comments.