Alternative to raw_input - Raspberry Pi Forums


i'm building system prompts user text input, submits web server using 1 of gpio pins. problem raw_input waits return key press before allowing pi read gpio pins. there way around this? can manually end process using code? here's code i've got far:

code: select all

#!/usr/bin/env python  import rpi.gpio gpio subprocess import call time import sleep  import urllib2, json, os  #setup gpio pins gpio.setmode(gpio.bcm)  gpio.setup(23, gpio.out) gpio.setup(25, gpio.in, pull_up_down=gpio.pud_down)    tweet="" line="" block=[] space=" " hash = 140   #get prompt json json_url = "http://testurl.com/data" json_string = urllib2.urlopen(json_url).read() the_data = json.loads(json_string) data = the_data["data"]  in data: 	type = i["typewriter"] 	prompt=i["prompt"]  #subtract hash tag character count hash = hash - len(type)  #upload function def upload(tweet): 	url = "https://testurl.com/tweet" 	try: 		call(["curl --data 'text=" + tweet + "' " + url], shell=true) 	except:  		print "fail"     while true:  	if gpio.input(25): 		tweet = space.join(block) #add block of text spaces in between 		gpio.output(23, gpio.high) 		upload(tweet) 		sleep(1)  	else: 		gpio.output(23, gpio.low) 		 		 		try: 			line = line + raw_input("") 		except keyboardinterrupt: 			break #accounts line breaks within tweet 		block.append(line) #add separate lines 		line = "" 

pygame allows poll keyboard keypresses directly if prefer that?

otherwise dont know of way.


.net/mono used let console.readkey() instead of readline handy purpose, wish there direct python equivalent.


raspberrypi



Comments

Popular posts from this blog

Thread: PKI Client 5.00 install (for eToken Pro)

ATmega2560-Arduino Pin Mapping

Crossfader Arduino Tutorial