Script Running Slow - Raspberry Pi Forums
hello all!
started messing raspberry pi 3 week ago, i'm total noob.
i've researched gpio control , threaded callbacks. i've written runs slow i'm wanting do, there
i'm doing wrong?
i'm going control of lighting on car 3 pis connected copper make local network, , @ moment
i'm working on tail lights.
works desired reaction time slow.
here's code.
video can see delayed reaction time input interrupt.
https://youtu.be/hikdakztxsq
appreciated!
started messing raspberry pi 3 week ago, i'm total noob.
i've researched gpio control , threaded callbacks. i've written runs slow i'm wanting do, there
i'm doing wrong?
i'm going control of lighting on car 3 pis connected copper make local network, , @ moment
i'm working on tail lights.
works desired reaction time slow.
here's code.
code: select all
pi@anonymous:~/my_python $ cat tail_light_test1.py import time import rpi.gpio gpio # set use board pinout gpio.setmode(gpio.board) # set gpio pines input gpio.setup(32,gpio.in,pull_up_down=gpio.pud_up) gpio.setup(22,gpio.in,pull_up_down=gpio.pud_up) gpio.setup(18,gpio.in,pull_up_down=gpio.pud_up) gpio.setup(16,gpio.in,pull_up_down=gpio.pud_up) gpio.setup(12,gpio.in,pull_up_down=gpio.pud_up) gpio.setup(37,gpio.in,pull_up_down=gpio.pud_up) # set gpio pins output gpio.setup(7,gpio.out) gpio.setup(11,gpio.out) gpio.setup(13,gpio.out) gpio.setup(15,gpio.out) gpio.setup(29,gpio.out) gpio.setup(31,gpio.out) gpio.setup(33,gpio.out) gpio.setup(35,gpio.out) # status buttons bs1=false # left blinker off state, true equals on. bs2=false # right blinker off state, true equals on. bs3=false # left brake light off state, true equals on. bs4=false # park light state, true equals on. bs5=false # low beam state. bs6=false # high beam state. # threaded callbacks def bs1callback(channel): global bs1 print "bs1 callback." if bs1==false: bs1=true else: bs1=false def bs2callback(channel): global bs2 print "bs2 callback." if bs2==false: bs2=true else: bs2=false def bs3callback(channel): global bs3 print "bs3 callback." if bs3==false: bs3=true else: bs3=false # adding event detection pins gpio.add_event_detect(32, gpio.falling, callback=bs1callback, bouncetime=300) gpio.add_event_detect(22, gpio.falling, callback=bs2callback, bouncetime=300) gpio.add_event_detect(18, gpio.falling, callback=bs3callback, bouncetime=300) # function blocks def leftblinkeron(): # turns on blinker leds 1 @ time right left. gpio.output(15,false) time.sleep(.5) gpio.output(13,false) time.sleep(.5) gpio.output(11,false) time.sleep(.5) gpio.output(7,false) time.sleep(.5) # turns of blinker leds off, once have been turned on. gpio.output(15,true) gpio.output(13,true) gpio.output(11,true) gpio.output(7,true) time.sleep(.5) def leftblinkeroff(): # turns of blinker leds off. gpio.output(15,true) gpio.output(13,true) gpio.output(11,true) gpio.output(7,true) def rightblinkeron(): # turns on blinker leds 1 @ time left right. gpio.output(29,false) time.sleep(.5) gpio.output(31,false) time.sleep(.5) gpio.output(33,false) time.sleep(.5) gpio.output(35,false) time.sleep(.5) # turns of blinker leds off, once have been turned on. gpio.output(29,true) gpio.output(31,true) gpio.output(33,true) gpio.output(35,true) time.sleep(.5) def rightblinkeroff(): #turns of blinker leds off. gpio.output(29,true) gpio.output(31,true) gpio.output(33,true) gpio.output(35,true) def leftbrakeon(): gpio.output(15,false) gpio.output(13,false) gpio.output(11,false) gpio.output(7,false) def rightbrakeon(): gpio.output(29,false) gpio.output(31,false) gpio.output(33,false) gpio.output(35,false) # program main code while(true): # left tail light control loop while(bs1==true): if bs1==true: leftblinkeron() break while(bs1==false): if (bs1==false , bs3==false): leftblinkeroff() break elif (bs1==false , bs3==true): leftbrakeon() break # right tail light control loop while(bs2==true): if bs2==true: rightblinkeron() break while(bs2==false): if (bs2==false , bs3==false): rightblinkeroff() break elif (bs2==false , bs3==true): rightbrakeon() break #except keyboardinterrupt: # gpio.cleanup()
https://youtu.be/hikdakztxsq
appreciated!
wow. crazy slow threading.
see in code when calls threaded routine set global variables prints screen. in video don't show screen. when press button there same delay before prints screen or print straight away take time before main routine call actual function blinks light?
me seems long winded way of doing it. u have threaded call set global variable test global variable in main loop call routine changes lights. think done in threaded call routine main program loop waits keyboard input exit clean up.
see in code when calls threaded routine set global variables prints screen. in video don't show screen. when press button there same delay before prints screen or print straight away take time before main routine call actual function blinks light?
me seems long winded way of doing it. u have threaded call set global variable test global variable in main loop call routine changes lights. think done in threaded call routine main program loop waits keyboard input exit clean up.
raspberrypi
Comments
Post a Comment