Posts: 85
Joined: Thu May 31, 2012 7:56 pm

Multitasking functions ?

Sat Feb 22, 2014 12:06 am


Not sure if this is easily possible or not, I'm hoping it is.

I'm playing around with the PiFace CAD ( ... d_display/). Which is nice, except when there is more than 16 characters that you want to display then you have to scroll the text across the screen ... which isn't so nice.

I've written a little test program that gets the input from the user and then scrolls the text around and around on the LCD screen. All good except that in scrolling the screen this takes up the focus of the program and the user can't enter anything else. This is very much just a simple test/sandbox type program that I quickly put together to illustrate what I'm trying to achieve.

Code: Select all

import pifacecad
import time

#Set up the CAD
cad = pifacecad.PiFaceCAD()

#Function to scroll the lcd screen
def scroll_lcd():
        while var == 1:

#Main body of program. Collect the users input and output it to the LCD screen 
#and then scroll

var = 1
while var == 1:
        line_1_input = input()
        cad.lcd.write (line_1_input)

Can this be done ? I want to be able to launch the function scroll_lcd and for it then to just run happily away in the background.

I've been thinking about this and I think I could achieve this by running the scroll function as a separate script (and I could pass the text that I want it to display via a text file / MySQL Database / XML which one program writes to, the other picks up and displays on the LCD screen ..... but only if that really is the best way.

Any help/advice would be very much appriciated

User avatar
Posts: 2566
Joined: Sat Jan 28, 2012 11:57 am
Location: UK

Re: Multitasking functions ?

Sat Feb 22, 2014 12:51 am

use threading. Lots of questions on this very forum or look in python docs. One thing, don't be tempted to write the output string to a global variable. This seems the easiest way but it's a slippery slope. Pass it as an argument to the thread function.

Posts: 85
Joined: Thu May 31, 2012 7:56 pm

Re: Multitasking functions ?

Sun Feb 23, 2014 12:13 pm

Many thanks for pointing in the right direction, very much appreciated :-)

Return to “Python”