Skip to content Skip to sidebar Skip to footer

Performing Infinite Loop While Awaiting Input

I have a little project I'm working on, it's fairly simple so I'm hoping someone can help me. I'm using a raspberry pi to dim a single LED with some very crude PWM. my PWM code loo

Solution 1:

It looks like you need multithreading!

# import the moduleimport threading

# define a function to be called in the other threaddefget_input():
    whileTrue:
        dwell=raw_input()

# create a Thread object
input_thread=threading.Thread(target=get_input)

# start the thread
input_thread.start()

# now enter the infinite loopwhileTrue:
    time.sleep(frequency)
    GPIO.output(7, 1)
    time.sleep(dwell)
    GPIO.output(7, 0)

There's probably something about locks or semaphores or mutex...es (mutices?) missing here, but I don't know much about those. Simple things like this seem to work for me.

Post a Comment for "Performing Infinite Loop While Awaiting Input"