You must first complete Screen Movement Using Touchpads before viewing this Lesson

Displaying Individual Pixels to OLED

Introduction

We will now improve the movement code that we have by making the pixel contained within the boundaries of the screen.

Components Needed

  • Little Python Brain
  • A tablet/phone/laptop
Steps

1

The first condition

We will add another if condition inside our first if condition from the previous lesson.

Since our screen is 64 pixels tall (0 being the top and 64 being the bottom pixel), we want to make a code that will revert the pixel to 0 when it goes past the maximum bottom boundary (64). This can easily be done with an if condition and a y = 0 block inside it.

2

The second condition

Similar to the previous step, when we keep on pressing up, we want the pixel to go to the bottom when it goes past the boundary of the screen.

We can do this by setting y = 64 when the pixel goes below 0.

3

The third and fourth conditions

Finally, we use the same principle as in the past two steps to avoid letting the pixel go off the boundary of the screen. 

The Complete Code

Run the code and note where the pixel is! In the next lesson, we’ll be learning how to move this pixel.

Back to: Intermediate > Game Controller

CONTACT US

    Log in with your credentials

    or    

    Forgot your details?

    Create Account