Time between button presses - Raspberry Pi Forums


i'm trying code in way of measuring time between presses of switch , stop process if time exceeds set amount.

have automated cycle testing rig set now. cycles thread in , out using stepper motor should take around 40 seconds complete cycle. controlled limit switches @ either end , should return first limit switch within 40 seconds.
should fail return within 40 seconds approx, signifying failure of testing, want kill program , print failure warning.

whats best method this?
thanks!

code: select all

from time import sleep import time import rpi.gpio gpio   dir = 20   # direction gpio pin step = 21  # step gpio pin cw = 1     # clockwise rotation ccw = 0    # counterclockwise rotation spr = 18400   # steps per revolution (360 / 0.067 * 3.5) switch27 = 27 switch13 = 13 cycle_count = 5 number = 0    gpio.setwarnings(false) gpio.setmode(gpio.bcm) gpio.setup(27, gpio.in, pull_up_down=gpio.pud_up) gpio.setup(13, gpio.in, pull_up_down=gpio.pud_up) gpio.setup(5, gpio.in, pull_up_down=gpio.pud_up) gpio.setup(dir, gpio.out) gpio.setup(step, gpio.out) gpio.output(dir, ccw)  mode = (14, 15, 18)   # microstep resolution gpio pins gpio.setup(mode, gpio.out) resolution = {'full': (0, 0, 0),               'half': (1, 0, 0),               '1/4': (0, 1, 0),               '1/8': (1, 1, 0),               '1/16': (0, 0, 1),               '1/32': (1, 0, 1)} gpio.output(mode, resolution['full'])  step_count = spr delay = .0004     while true:     input_value = gpio.input(5)  #set rear switch      if input_value == false:         number += 1         print ('cycle count', (number))         sleep(6)        while 1:     gpio.output(dir, ccw)     x in range(step_count):         gpio.output(step, gpio.high)         sleep(delay)         gpio.output(step, gpio.low)         sleep(delay)         input_state1 = gpio.input(13)         if input_state1 == true:             break     sleep(2)     gpio.output(dir, cw)     x in range(step_count):         gpio.output(step, gpio.high)         sleep(delay)         gpio.output(step, gpio.low)         sleep(delay)         input_state2 = gpio.input(27)         if input_state1 == true:             break            gpio.cleanup() 

take @ apscheduler http://apscheduler.readthedocs.io/en/la ... -trigger-s, background scheduler.

can create background scheduler, , if 1 of limit switches fires, can reschedule job refresh timeout timer. if timeout occurs, gracefully exit program.


raspberrypi



Comments

Popular posts from this blog

Help with Missing Filename Error?

Using phone battery to power a plane.

more info - Joomla! Forum - community, help and support