jeudi 29 juin 2017

Raspberry pi button delay time to a relay

I am new to Raspberry pi and python and am having a bit of trouble with some code I wish to push a button and have the gpio pin that corresponds to that button trigger a relay to turn on for a given amount of time then turn off. I have it working with the code below but by using the 'time.sleep(my-variable)' it holds up the raspberry pi for the duration of the time and i am unable to do anything else. What i am after is the ability to push one button and get the relay to act for say 10 seconds and within those 10 seconds be able to press another button to fire another relay and do the same thing without tying up the pi

my code below first checks if input_state_LHS is equel to false, then clears the LCD display, writes text to the LCD on one line then on the next line it write the value of my variable(LHS_feedtime) then fires the relay with the time on the next line time.sleep, this is the bit i wish to be rid of but am unable to figure out the code to do it.

if input_state_LHS == False:
        ## calls the LCD_Clear function which has to be in the same folder as this file
        mylcd.lcd_clear()
        mylcd.lcd_display_string("LHS Feedtime",1,2)
        mylcd.lcd_display_string(str(round(LHS_feedtime, 2)) + " sec" , 2,5)
        GPIO.output(27, GPIO.input(12) )
        time.sleep(LHS_feedtime)
        mylcd.lcd_clear()
        mylcd.lcd_display_string("Flatson Feeding", 1)
        mylcd.lcd_display_string("Systems", 2,4)
        GPIO.output(27, GPIO.input(12) )
        menuitem = 0

thanks for the help

Aucun commentaire:

Enregistrer un commentaire