You must first complete Adding Screen Elements to Timer before viewing this Lesson

Controlling Timer Settings Using Touchpad

Introduction

Now that we know how to dynamically display the countdown on the OLED screen, let’s go ahead and make a self-contained “app” that will allow us to set the time we want using just the touchpads.

Components Needed

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

1

Setting up the touchpads

First up, we need to import the lp_sensors library and set the touchpads up. We only need L1, L2, and R1 for this project.

2

Replacing the User_Input and setTime blocks

We will then remove the User_Input and setTime blocks. We will change the way we initialize the setTime variable.

3

Adding a new setTime variable

Instead, we will be using an x = y block to initialize the setTime block. Simply change the x to setTime and y to 5. 

4

The setTime while block

What this condition means is simply that while we still haven’t pressed R1, it will execute the code inside.

5

Displaying the timer

We need to display the current timer setting so we can reliably change it.

6

Conditional statements for L1 and L2.

Finally, we will create two conditions. L1 (Down) will reduce the timer while L2 (Up) will increase it.

Add a sleep(0.1) after conditional statements.

The Complete Code

Run the code. On the next lesson we’ll integrate a limit that will stop the user from setting the time below 1 second as well as add some buzzer elements as an alarm tone.

Back to: Intermediate > Countdown Timer

CONTACT US

    Log in with your credentials

    or    

    Forgot your details?

    Create Account