python - using delay between actions -


i trying communicate python arduino using pyserial library. in code below showing few functions trying switch on or off led based on value returned these functions. want when python telling switch on led, want led switched on 7 seconds, during time if set_forbidden_list returns value, want led switch off , keep switched off until set_forbidden_list becomes empty. heavily appreciated.

def openthedoor(set_accepted_list,set_list_ant_id,set_forbidden_list,set_accepted_list_frozen):     if(((len(set_accepted_list)) >0) & (set_forbidden_list == set()) & ((set_accepted_list_frozen == none) or ((set_accepted_list_frozen & set_accepted_list)== set_accepted_list))):         use_door(1)         delay_for_goodant(1)         print "open gate"     else:         use_door(0)         delay_for_goodant(0)         print "close gate"     set_for_comparison = set(set_accepted_list &  set_list_ant_id)     list_for_comparison = list(set_for_comparison)     return set_for_comparison,list_for_comparison      def establishing_connection():     print ser.read();     ser.write('1')  last_action = -1  def use_door(activate):     global last_action     if(last_action != activate):         send_data(activate)     last_action = activate  def send_data(data):     if (data ==0):         print "manga"         return true     else:         print "muringa"         return false  def delay_for_goodant(data):     print "thenga"     global ser     try:         if (ser == none):             ser = serial.serial("com1",9600,timeout = 0)             print "reconnect"             incoming_data = ser.readline()         else:                           ## turning off led             ser.write('0')             time.sleep(0)             incoming_data2 = ser.readline()     except ioerror:         ser = none 

instead of using time.sleep(7) halt program 7 seconds sleep few milliseconds inside loop keeps checking if there value in set_forbidden_list. time.sleep(0) not writing @ all.

for in range(700):    time.sleep(0.01);    if len(set_forbidden_list)==0:         #switchon led 

the above loop runs 700 times while each time wait 0.01 seconds , sums 7 seconds.


Comments

Popular posts from this blog

python Tkinter Capturing keyboard events save as one single string -

android - InAppBilling registering BroadcastReceiver in AndroidManifest -

javascript - Z-index in d3.js -