resist10k
Posts: 7
Joined: Sat Jun 22, 2013 1:14 am

Loop Interrupt

Wed Jan 22, 2014 6:37 am

Hello All Im pretty new to programming and im running into an issue. Ive been looking around everywhere but i cant seem to figure out how to get my program to work. I have a PWM for loop running to fade an LED. Id like to get user input from keyboard to stop the PWM loop.I cant use raw_input because that will stop the loop. Is there an EASY way to get a key press while a for loop is running? ive tried pygame but i cant seem to get it tor work. Everything i try seems to need to be out of a loop to run. Im trying to run this all from a ssh shell so it wont have any windows or anything. The workaround ive been doing is to launch another terminal and run a seperate python script with just the loop there which works but id like it a bit more neat. Again im pretty new to programming i was looking into threading but couldnt quite figure it out. Any suggestions will help thanks :)

User avatar
AndyD
Posts: 2334
Joined: Sat Jan 21, 2012 8:13 am
Location: Melbourne, Australia
Contact: Website

Re: Loop Interrupt

Wed Jan 22, 2014 7:20 am

This thread is has some suggestions.

resist10k
Posts: 7
Joined: Sat Jun 22, 2013 1:14 am

Re: Loop Interrupt

Fri Jan 24, 2014 9:02 pm

So ive tried curses and a couple other libraries and im still stuck. It seems that most libraries stop execution of the loop and wait for input so i cant have my PWM continue until key press. Pygame dosent look like its for command line programs. So im still kinda lost :(

User avatar
AndyD
Posts: 2334
Joined: Sat Jan 21, 2012 8:13 am
Location: Melbourne, Australia
Contact: Website

Re: Loop Interrupt

Fri Jan 24, 2014 9:33 pm

Did you look at this. You need to specifically tell curses not to wait for input.

Code: Select all

damn.nodelay(1) # doesn't keep waiting for a key press

resist10k
Posts: 7
Joined: Sat Jun 22, 2013 1:14 am

Re: Loop Interrupt

Fri Jan 24, 2014 9:53 pm

lol sorry was rushing around trying snippets of code and i didnt see that one just looked at the post where he said it didnt work. Tried it myself and it looks like its running Thx Andy :)

Return to “Python”