Exemplo n.º 1
0
def run(systemlist,paralist,unparalist,pinlist):
	if unparalist[3] == 0 or time.time() - systemlist[2] >= unparalist[4]:
		exit(systemlist[0], systemlist[1])
	unparalist[0],unparalist[1] = arduino.monitor(paralist[0], unparalist[0], unparalist[1], systemlist[2], systemlist[3], pinlist[0], pinlist[1], systemlist[1],systemlist[4])
	# if the rat achieve the criterion, that actions according to the time sequence
	# during this section, all actions and presses that do not lead to reward are recorded to file as well
	if unparalist[0] == paralist[0]:
		arduino.recordtime(systemlist[2], systemlist[3], "E")
		arduino.delay(paralist[1],systemlist[2],pinlist[0],systemlist[3],systemlist[0],systemlist[1])
		#record the time that it achieves the criterion				
		unparalist[0] = arduino.us(paralist[2],pinlist[2],pinlist[0],systemlist[2],systemlist[3],systemlist[0],systemlist[1])
		
		# for every certain trails, the criterion need to be increased
		# the trails that increase the criterion is the number that dividable by 'gap'
		if unparalist[2] % paralist[4]==0:
			if paralist[3]=="random":
				s=randint(1,3) # if user select random as step, randomly select it from one to three
				print (s) # and print this step out
				paralist[0] += s
			else:
				paralist[0] += paralist[3]
		unparalist[3] -= 1
		print("current times is: " + str(paralist[0])) # print the current criterion out
		print("times to go: " + str(unparalist[3]))
		print("time already pass: " + str(time.time() - systemlist[2]))
	# recall itself every 1milisecond in order to keep monitoring the press	 
	systemlist[1].after(1,run,systemlist,paralist,unparalist,pinlist)
Exemplo n.º 2
0
def run(systemlist, paralist, unparalist, pinlist):
    if unparalist[3] == 0 or time.time() - systemlist[2] >= unparalist[4]:
        exit(systemlist[0], systemlist[1])
    unparalist[0], unparalist[1] = arduino.monitor(
        paralist[0], unparalist[0], unparalist[1], systemlist[2],
        systemlist[3], pinlist[0], pinlist[1], systemlist[1], systemlist[4])
    # if the rat achieve the criterion, that actions according to the time sequence
    # during this section, all actions and presses that do not lead to reward are recorded to file as well
    if unparalist[0] == paralist[0]:
        arduino.recordtime(systemlist[2], systemlist[3], "E")
        arduino.delay(paralist[1], systemlist[2], pinlist[0], systemlist[3],
                      systemlist[0], systemlist[1])
        #record the time that it achieves the criterion
        unparalist[0] = arduino.us(paralist[2], pinlist[2], pinlist[0],
                                   systemlist[2], systemlist[3], systemlist[0],
                                   systemlist[1])

        # for every certain trails, the criterion need to be increased
        # the trails that increase the criterion is the number that dividable by 'gap'
        if unparalist[2] % paralist[4] == 0:
            if paralist[3] == "random":
                s = randint(
                    1, 3
                )  # if user select random as step, randomly select it from one to three
                print(s)  # and print this step out
                paralist[0] += s
            else:
                paralist[0] += paralist[3]
        unparalist[3] -= 1
        print("current times is: " +
              str(paralist[0]))  # print the current criterion out
        print("times to go: " + str(unparalist[3]))
        print("time already pass: " + str(time.time() - systemlist[2]))
    # recall itself every 1milisecond in order to keep monitoring the press
    systemlist[1].after(1, run, systemlist, paralist, unparalist, pinlist)
Exemplo n.º 3
0
def run():    
    global currenttimes
    global upanddown
    global totaltimes
    global times
    global interval
    global duration
    global step
    global gap
    currenttimes,upanddown = arduino.monitor(times, currenttimes, upanddown, starttime, output, buttonPin, LEDPin, top)
    # if the rat achieve the criterion, that actions according to the time sequence
    # during this section, all actions and presses that do not lead to reward are recorded to file as well
    if currenttimes == times:
        arduino.recordtime(starttime, output, "E")
        arduino.delay(interval,starttime,buttonPin,output,board,top)
        #record the time that it achieves the criterion                
        currenttimes = arduino.us(duration,servoPin,buttonPin,starttime,output,board,top)
        
        # for every certain trails, the criterion need to be increased
        # the trails that increase the criterion is the number that dividable by 'gap'
        if totaltimes % gap==0:
            if step=="random":
                s=randint(1,3) # if user select random as step, randomly select it from one to three
                print (s) # and print this step out
                times+=s
            else:
                times+=step
        print("current times is: " + str(times)) # print the current criterion out
    
    # recall itself every 1milisecond in order to keep monitoring the press     
    top.after(1,run)
Exemplo n.º 4
0
def rangemode():
    global interval
    global duration
    global rangemin
    global rangemax
    global timeslist
    global mode
    global currenttimes
    global upanddown
    global thistimes
    currenttimes, upanddown = arduino.monitor(thistimes, currenttimes,
                                              upanddown, starttime, output,
                                              buttonPin, LEDPin, top)
    if currenttimes == thistimes:
        #record the time that it achieves the criterion
        arduino.recordtime(starttime, output, "E")
        arduino.delay(interval, starttime, buttonPin, output, board, top)
        currenttimes = arduino.us(duration, servoPin, buttonPin, starttime,
                                  output, board, top)
        thistimes = random.randint(
            rangemin, rangemax)  # select another criterion for new trial
        print(thistimes)

    # recall itself every 1milisecond in order to keep monitoring the press
    top.after(1, rangemode)
Exemplo n.º 5
0
def run(systemlist,paralist,unparalist,pinlist):
	if unparalist[2] == 0 or time.time() - systemlist[2] >= unparalist[3]:
		exit(systemlist[0], systemlist[1])
	unparalist[0],unparalist[1] = arduino.monitor(paralist[0], unparalist[0], unparalist[1], systemlist[2], systemlist[3], pinlist[0], pinlist[1], systemlist[1],systemlist[4])
	if unparalist[0] == paralist[0]:
		arduino.recordtime(systemlist[2], systemlist[3], "E")
		arduino.delay(paralist[1],systemlist[2],pinlist[0],systemlist[3],systemlist[0],systemlist[1])
		unparalist[0] = arduino.us(paralist[2],pinlist[2],pinlist[0],systemlist[2],systemlist[3],systemlist[0],systemlist[1])
		unparalist[2] -= 1
		print("times to go: " + str(unparalist[2]))
		print("time already pass: " + str(time.time() - systemlist[2]))
	# recall itself every 1milisecond in order to keep monitoring the press
	systemlist[1].after(1,run,systemlist,paralist,unparalist,pinlist)
Exemplo n.º 6
0
def run():
    global interval
    global duration
    global times
    global currenttimes
    global upanddown
    global temp
    currenttimes,upanddown = arduino.monitor(times, currenttimes, upanddown, starttime, output, buttonPin, LEDPin, top)
    if currenttimes == times:
        arduino.recordtime(starttime, output, "E")
        arduino.delay(interval,starttime,buttonPin,output,board,top)
        currenttimes = arduino.us(duration,servoPin,buttonPin,starttime,output,board,top)
    # recall itself every 1milisecond in order to keep monitoring the press
    top.after(1,run)
Exemplo n.º 7
0
def rangemode(systemlist,paralist,unparalist,pinlist):
	if unparalist[2] == 0 or time.time() - systemlist[2] >= unparalist[3]:
		exit(systemlist[0], systemlist[1])
	unparalist[0],unparalist[1] = arduino.monitor(paralist[8], unparalist[0], unparalist[1], systemlist[2], systemlist[3], pinlist[0], pinlist[1], systemlist[1],systemlist[4])
	if unparalist[0] == paralist[8]:
		#record the time that it achieves the criterion
		arduino.recordtime(systemlist[2], systemlist[3], "E")
		arduino.delay(paralist[0],systemlist[2],pinlist[0],systemlist[3],systemlist[0],systemlist[1])
		unparalist[0] = arduino.us(paralist[1],pinlist[2],pinlist[0],systemlist[2],systemlist[3],systemlist[0],systemlist[1])
		paralist[8] = random.randint(paralist[2], paralist[3]) # select another criterion for new trial
		print("This time is " + str(paralist[8]))
		unparalist[2] -= 1
		print("times to go: " + str(unparalist[2]))
		print("time already pass: " + str(time.time() - systemlist[2]))
	# recall itself every 1milisecond in order to keep monitoring the press
	systemlist[1].after(1,rangemode,systemlist,paralist,unparalist,pinlist)
Exemplo n.º 8
0
def listmode(systemlist,paralist,unparalist,pinlist):
	if unparalist[2] == 0 or time.time() - systemlist[2] >= unparalist[3]:
		exit(systemlist[0], systemlist[1])
	unparalist[0],unparalist[1] = arduino.monitor(paralist[8], unparalist[0], unparalist[1], systemlist[2], systemlist[3], pinlist[0], pinlist[1], systemlist[1],systemlist[4])
	# feed
	if unparalist[0] == paralist[8]:
		#record the time that it achieves the criterion
		arduino.recordtime(systemlist[2], systemlist[3], "E")
		arduino.delay(paralist[0],systemlist[2],pinlist[0],systemlist[3],systemlist[0],systemlist[1])
		unparalist[0] = arduino.us(paralist[1],pinlist[2],pinlist[0],systemlist[2],systemlist[3],systemlist[0],systemlist[1])
		paralist[8]=random.choice(paralist[4])
		print("This time is " + str(paralist[8]))
		unparalist[2] -= 1
		print("times to go: " + str(unparalist[2]))
		print("time already pass: " + str(time.time() - systemlist[2]))
	systemlist[1].after(1,listmode,systemlist,paralist,unparalist,pinlist)
Exemplo n.º 9
0
def run():
    global interval
    global duration
    global times
    global currenttimes
    global upanddown
    global temp
    currenttimes, upanddown = arduino.monitor(times, currenttimes, upanddown,
                                              starttime, output, buttonPin,
                                              LEDPin, top)
    if currenttimes == times:
        arduino.recordtime(starttime, output, "E")
        arduino.delay(interval, starttime, buttonPin, output, board, top)
        currenttimes = arduino.us(duration, servoPin, buttonPin, starttime,
                                  output, board, top)
    # recall itself every 1milisecond in order to keep monitoring the press
    top.after(1, run)
Exemplo n.º 10
0
def loop():
    global estado, estado2, cont
    
    value = arduino.analogRead(13)
    millivolts = 1100 * value / 1.1      #max volts for analog in is 1.1V
    db = millivolts / 10
    print(db, "DB")
    estado2 = arduino.digitalRead(8)
    if estado2:   #this means high  or you can write if estado2==1
        estado = arduino.digitalRead(7)
        if estado:
            arduino.delay(500)
        cont += 1
    if cont==1:
        arduino.digitalWrite(A, 1)
        arduino.digitalWrite(B, 1)
        arduino.digitalWrite(C, 1)
        arduino.digitalWrite(D, 1)
        arduino.digitalWrite(E, 1)
Exemplo n.º 11
0
def listmode():
    global interval
    global duration
    global rangemin
    global rangemax
    global timeslist
    global mode
    global currenttimes
    global upanddown
    global thistimes
    currenttimes,upanddown = arduino.monitor(thistimes, currenttimes, upanddown, starttime, output, buttonPin, LEDPin, top) 
    # feed
    if currenttimes == thistimes:
        arduino.recordtime(starttime, output, "E")
        arduino.delay(interval,starttime,buttonPin,output,board,top)
        currenttimes = arduino.us(duration,servoPin,buttonPin,starttime,output,board,top)
        thistimes=random.choice(timeslist)
        print(thistimes)
            
    top.after(1,listmode)
Exemplo n.º 12
0
def listmode(systemlist, paralist, unparalist, pinlist):
    if unparalist[2] == 0 or time.time() - systemlist[2] >= unparalist[3]:
        exit(systemlist[0], systemlist[1])
    unparalist[0], unparalist[1] = arduino.monitor(
        paralist[8], unparalist[0], unparalist[1], systemlist[2],
        systemlist[3], pinlist[0], pinlist[1], systemlist[1], systemlist[4])
    # feed
    if unparalist[0] == paralist[8]:
        #record the time that it achieves the criterion
        arduino.recordtime(systemlist[2], systemlist[3], "E")
        arduino.delay(paralist[0], systemlist[2], pinlist[0], systemlist[3],
                      systemlist[0], systemlist[1])
        unparalist[0] = arduino.us(paralist[1], pinlist[2], pinlist[0],
                                   systemlist[2], systemlist[3], systemlist[0],
                                   systemlist[1])
        paralist[8] = random.choice(paralist[4])
        print("This time is " + str(paralist[8]))
        unparalist[2] -= 1
        print("times to go: " + str(unparalist[2]))
        print("time already pass: " + str(time.time() - systemlist[2]))
    systemlist[1].after(1, listmode, systemlist, paralist, unparalist, pinlist)
Exemplo n.º 13
0
def rangemode():
    global interval
    global duration
    global rangemin
    global rangemax
    global timeslist
    global mode
    global currenttimes
    global upanddown
    global thistimes
    currenttimes,upanddown = arduino.monitor(thistimes, currenttimes, upanddown, starttime, output, buttonPin, LEDPin, top)
    if currenttimes == thistimes:
        #record the time that it achieves the criterion
        arduino.recordtime(starttime, output, "E")
        arduino.delay(interval,starttime,buttonPin,output,board,top)
        currenttimes = arduino.us(duration,servoPin,buttonPin,starttime,output,board,top)
        thistimes = random.randint(rangemin, rangemax) # select another criterion for new trial
        print(thistimes)

    # recall itself every 1milisecond in order to keep monitoring the press
    top.after(1,rangemode)
Exemplo n.º 14
0
def run(systemlist, paralist, unparalist, pinlist):
    if unparalist[3] == 0 or time.time() - systemlist[2] >= unparalist[4]:
        exit(systemlist[0], systemlist[1], pinlist[1], pinlist[2])
    # if the difference between current and the start point of the trial is the paralist[2] of sd
    # in this statement, use very closing value to represent the equal condition
    # because the loop will be called every 1ms, regarding the deviation, the range is better than exactly equal
    # this means that the rat has not achieved the criterion so that the sd is not turn off
    if (time.time() - unparalist[2]) > (paralist[3] - 0.001) and (
            time.time() - unparalist[2]) < (paralist[3] + 0.001):
        #calculate the relative time for the press
        arduino.recordtime(systemlist[2], systemlist[3], "SDE")
        pinlist[2].write(0)  # turn off SD

        # wait for paralist[4] paralist[1]
        # the reason that break down the delay is in order to update the condition to GUI window
        # to avoid it fall into 'No responding'
        # also, during this process, useless presses can be detected and recorded
        arduino.delay(paralist[4], systemlist[2], pinlist[0], systemlist[3],
                      systemlist[0], systemlist[1])

        unparalist[0] = 0  # reset the value

        arduino.recordtime(systemlist[2], systemlist[3], "SDE")
        # if the count is greater than one,
        # which means there remain some trails, start a new trial

        arduino.recordtime(systemlist[2], systemlist[3], "SDS")
        pinlist[2].write(1)  # turn on SD
        unparalist[2] = time.time()  # get the start time of the new trial

    unparalist[0], unparalist[1] = arduino.monitor(
        paralist[0], unparalist[0], unparalist[1], systemlist[2],
        systemlist[3], pinlist[0], pinlist[1], systemlist[1], systemlist[4])
    # if the rat achieve the criterion, that actions according to the time sequence
    # during this section, all actions and presses that do not lead to reward are recorded to file as well
    if unparalist[0] == paralist[0]:
        pinlist[2].write(0)  # stop SD first
        arduino.recordtime(systemlist[2], systemlist[3], "E")
        arduino.delay(paralist[1], systemlist[2], pinlist[0], systemlist[3],
                      systemlist[0], systemlist[1])
        unparalist[0] = arduino.us(paralist[2], pinlist[3], pinlist[0],
                                   systemlist[2], systemlist[3], systemlist[0],
                                   systemlist[1])
        # after feeding
        # wait for paralist[4] paralist[1] and record the useless presses
        arduino.delay(paralist[4], systemlist[2], pinlist[0], systemlist[3],
                      systemlist[0], systemlist[1])

        # if the count is greater than one,
        # which means there remain some trails, start a new trial
        arduino.recordtime(systemlist[2], systemlist[3], "SDS")
        pinlist[2].write(1)
        unparalist[3] -= 1
        print("times to go: " + str(unparalist[3]))
        print("time already pass: " + str(time.time() - systemlist[2]))
        unparalist[2] = time.time()  # get the start time of the new trial
    # recall itself every 1 milisecond in order to keep monitoring the press
    systemlist[1].after(1, run, systemlist, paralist, unparalist, pinlist)
Exemplo n.º 15
0
def listmode():
    global interval
    global duration
    global rangemin
    global rangemax
    global timeslist
    global mode
    global currenttimes
    global upanddown
    global thistimes
    currenttimes, upanddown = arduino.monitor(thistimes, currenttimes,
                                              upanddown, starttime, output,
                                              buttonPin, LEDPin, top)
    # feed
    if currenttimes == thistimes:
        arduino.recordtime(starttime, output, "E")
        arduino.delay(interval, starttime, buttonPin, output, board, top)
        currenttimes = arduino.us(duration, servoPin, buttonPin, starttime,
                                  output, board, top)
        thistimes = random.choice(timeslist)
        print(thistimes)

    top.after(1, listmode)
Exemplo n.º 16
0
def rangemode(systemlist, paralist, unparalist, pinlist):
    if unparalist[2] == 0 or time.time() - systemlist[2] >= unparalist[3]:
        exit(systemlist[0], systemlist[1])
    unparalist[0], unparalist[1] = arduino.monitor(
        paralist[8], unparalist[0], unparalist[1], systemlist[2],
        systemlist[3], pinlist[0], pinlist[1], systemlist[1], systemlist[4])
    if unparalist[0] == paralist[8]:
        #record the time that it achieves the criterion
        arduino.recordtime(systemlist[2], systemlist[3], "E")
        arduino.delay(paralist[0], systemlist[2], pinlist[0], systemlist[3],
                      systemlist[0], systemlist[1])
        unparalist[0] = arduino.us(paralist[1], pinlist[2], pinlist[0],
                                   systemlist[2], systemlist[3], systemlist[0],
                                   systemlist[1])
        paralist[8] = random.randint(
            paralist[2], paralist[3])  # select another criterion for new trial
        print("This time is " + str(paralist[8]))
        unparalist[2] -= 1
        print("times to go: " + str(unparalist[2]))
        print("time already pass: " + str(time.time() - systemlist[2]))
    # recall itself every 1milisecond in order to keep monitoring the press
    systemlist[1].after(1, rangemode, systemlist, paralist, unparalist,
                        pinlist)
Exemplo n.º 17
0
def run():
    global currenttimes
    global upanddown
    global totaltimes
    global times
    global interval
    global duration
    global step
    global gap
    currenttimes, upanddown = arduino.monitor(times, currenttimes, upanddown,
                                              starttime, output, buttonPin,
                                              LEDPin, top)
    # if the rat achieve the criterion, that actions according to the time sequence
    # during this section, all actions and presses that do not lead to reward are recorded to file as well
    if currenttimes == times:
        arduino.recordtime(starttime, output, "E")
        arduino.delay(interval, starttime, buttonPin, output, board, top)
        #record the time that it achieves the criterion
        currenttimes = arduino.us(duration, servoPin, buttonPin, starttime,
                                  output, board, top)

        # for every certain trails, the criterion need to be increased
        # the trails that increase the criterion is the number that dividable by 'gap'
        if totaltimes % gap == 0:
            if step == "random":
                s = randint(
                    1, 3
                )  # if user select random as step, randomly select it from one to three
                print(s)  # and print this step out
                times += s
            else:
                times += step
        print("current times is: " +
              str(times))  # print the current criterion out

    # recall itself every 1milisecond in order to keep monitoring the press
    top.after(1, run)
Exemplo n.º 18
0
def run(systemlist,paralist,unparalist,pinlist):
	if unparalist[3] == 0 or time.time() - systemlist[2] >= unparalist[4]:
		exit(systemlist[0], systemlist[1],pinlist[1],pinlist[2])
	# if the difference between current and the start point of the trial is the paralist[2] of sd
	# in this statement, use very closing value to represent the equal condition
	# because the loop will be called every 1ms, regarding the deviation, the range is better than exactly equal
	# this means that the rat has not achieved the criterion so that the sd is not turn off
	if (time.time() - unparalist[2]) > (paralist[3] - 0.001) and (time.time() - unparalist[2]) < (paralist[3] + 0.001):
		#calculate the relative time for the press
		arduino.recordtime(systemlist[2], systemlist[3], "SDE")
		pinlist[2].write(0) # turn off SD

		
		# wait for paralist[4] paralist[1]
		# the reason that break down the delay is in order to update the condition to GUI window 
		# to avoid it fall into 'No responding'
		# also, during this process, useless presses can be detected and recorded
		arduino.delay(paralist[4],systemlist[2],pinlist[0],systemlist[3],systemlist[0],systemlist[1])
					
		unparalist[0] = 0 # reset the value
		
		arduino.recordtime(systemlist[2], systemlist[3], "SDE")
		# if the count is greater than one, 
		# which means there remain some trails, start a new trial

		arduino.recordtime(systemlist[2], systemlist[3], "SDS")
		pinlist[2].write(1) # turn on SD
		unparalist[2] = time.time() # get the start time of the new trial
		
	unparalist[0],unparalist[1] = arduino.monitor(paralist[0], unparalist[0], unparalist[1], systemlist[2], systemlist[3], pinlist[0], pinlist[1], systemlist[1],systemlist[4])
			# if the rat achieve the criterion, that actions according to the time sequence
			# during this section, all actions and presses that do not lead to reward are recorded to file as well
	if unparalist[0] == paralist[0]:
		pinlist[2].write(0) # stop SD first
		arduino.recordtime(systemlist[2], systemlist[3], "E")
		arduino.delay(paralist[1],systemlist[2],pinlist[0],systemlist[3],systemlist[0],systemlist[1])
		unparalist[0] = arduino.us(paralist[2],pinlist[3],pinlist[0],systemlist[2],systemlist[3],systemlist[0],systemlist[1])
		# after feeding
		# wait for paralist[4] paralist[1] and record the useless presses
		arduino.delay(paralist[4],systemlist[2],pinlist[0],systemlist[3],systemlist[0],systemlist[1])
					
		# if the count is greater than one, 
		# which means there remain some trails, start a new trial
		arduino.recordtime(systemlist[2], systemlist[3], "SDS")
		pinlist[2].write(1)
		unparalist[3] -= 1
		print("times to go: " + str(unparalist[3]))
		print("time already pass: " + str(time.time() - systemlist[2]))		
		unparalist[2] = time.time() # get the start time of the new trial
	# recall itself every 1 milisecond in order to keep monitoring the press  
	systemlist[1].after(1,run,systemlist,paralist,unparalist,pinlist)
Exemplo n.º 19
0
def run():
    global trials
    global times
    global interval
    global duration
    global sdinterval
    global intertrial
    global upanddown
    global currenttimes
    global looptime
    

    # if the difference between current and the start point of the trial is the duration of sd
    # in this statement, use very closing value to represent the equal condition
    # because the loop will be called every 1ms, regarding the deviation, the range is better than exactly equal
    # this means that the rat has not achieved the criterion so that the sd is not turn off
    if (time.time() - looptime) > (sdinterval - 0.001) and (time.time() - looptime) < (sdinterval + 0.001):
        #calculate the relative time for the press
        arduino.recordtime(starttime, output, "SDE")
        sdPin.write(0) # turn off SD

        
        # wait for intertrial interval
        # the reason that break down the delay is in order to update the condition to GUI window 
        # to avoid it fall into 'No responding'
        # also, during this process, useless presses can be detected and recorded
        arduino.delay(intertrial,starttime,buttonPin,output,board,top)
                    
        currenttimes = 0 # reset the value
        
        arduino.recordtime(starttime, output, "SDE")
        
        trials -= 1 # finish a trial and decrease the count by 1

        # if the count is greater than one, 
        # which means there remain some trails, start a new trial
        if trials == 0:
            exit()
        arduino.recordtime(starttime, output, "SDS")
        sdPin.write(1) # turn on SD
        looptime = time.time() # get the start time of the new trial
        
    currenttimes,upanddown = arduino.monitor(times, currenttimes, upanddown, starttime, output, buttonPin, LEDPin, top)
            # if the rat achieve the criterion, that actions according to the time sequence
            # during this section, all actions and presses that do not lead to reward are recorded to file as well
    if currenttimes == times:
        sdPin.write(0) # stop SD first
        arduino.recordtime(starttime, output, "E")
        arduino.delay(interval,starttime,buttonPin,output,board,top)
        currenttimes = arduino.us(duration,servoPin,buttonPin,starttime,output,board,top)
        trials -= 1 # finish a trial and decrease the trial by 1
        # after feeding
        # wait for intertrial interval and record the useless presses
        arduino.delay(intertrial,starttime,buttonPin,output,board,top)
                    
        # if the count is greater than one, 
        # which means there remain some trails, start a new trial
        if trials == 0:
            exit()
        arduino.recordtime(starttime, output, "SDS")
        sdPin.write(1)
        looptime = time.time() # get the start time of the new trial
    # recall itself every 1 milisecond in order to keep monitoring the press  
    top.after(1,run)