Now that I saw a physical response, I should try to make it similar to how a servo should be controlled.
Servos are actuators that receive (expect) position input (as opposed to motors, which receive speed/intensity input). Simply put, it registers input as pulses, decoding the ratio of high (a "on" signal) to low in a given period as a position value.
A better explanation : http://learn.adafruit.com/adafruits-raspberry-pi-lesson-8-using-a-servo-motor/servo-motors
As I am waiting for my servo to be shipped, I will continue to work with the LED light.
As opposed to my previous setup of having the light turn on every time the request is given, I will have the light turn on and off in a regular pattern until a request is given, upon which the pattern will change for one "cycle" (on-and-off pair).
The on-and-off logic (previously the LED control logic) will be run in a separate thread:
def dCycle(*args):
global dCVal
var = 1
while var==1:
dutyCycle = dCVal
GPIO.output(17, GPIO.HIGH)
time.sleep(dutyCycle)
GPIO.output(17, GPIO.LOW)
time.sleep(2-dutyCycle)
This code says that the total "cycle" will be 2 seconds, with "dutyCycle" being the length of time that the LED will be on. The global value "dCVal" will contain the length of time the light will be on.
In the beginning, "dCVal" will be set to 0.15 seconds:
if __name__ == "__main__":
global dCVal
dCVal = 0.15
.
.
.
thread.start_new_thread(dCycle,())
.
.
.
thread.start_new_thread(dCycle,())
Every time the request is received, the value of dCVal will be changed to give it a different cycle pattern:
(in request received logic)
dCVal = 1
time.sleep(2)
dCVal = 0.15
The LED will be on for a solid second when requests are received then return back to the short length once that is achieved.
The time.sleep value of 2 somewhat resembled a setup/hold time in digital logic (reminded me of it, at least)... but not really at the same time.
Comments
Post a Comment