I'm using webiopi, and what I basically want to happen is that when the webpage loads, an idle loop which chases some LEDs runs. Then, when someone presses a button on the website, it will stop the idle loop.
Here's what I have so far:
import webiopi
import time
GPIO = webiopi.GPIO
LIGHT1 = 2
LIGHT2 = 3
LIGHT3 = 4
def setup():
GPIO.setFunction(LIGHT1, GPIO.OUT)
GPIO.setFunction(LIGHT2, GPIO.OUT)
GPIO.setFunction(LIGHT3, GPIO.OUT)
a=0
def loop():
webiopi.sleep(1)
@webiopi.macro
def stopLoop():
print("Stopping Loop");
global a
a = 1
return a
@webiopi.macro
def idleLoop():
print("Entering idleLoop");
while (a==0):
GPIO.digitalWrite(LIGHT1, GPIO.HIGH)
time.sleep(0.05)
GPIO.digitalWrite(LIGHT2, GPIO.HIGH)
GPIO.digitalWrite(LIGHT1, GPIO.LOW)
time.sleep(0.05)
GPIO.digitalWrite(LIGHT3, GPIO.HIGH)
GPIO.digitalWrite(LIGHT2, GPIO.LOW)
time.sleep(0.05)
So, I can get it to run the idleLoop, and I have a button hooked up to send the command for stopLoop, and I can see that it goes via POST, however in my debugging window on the PI, I just see it enter idleLoop, but it never enters stopLoop. I'm not sure if I have to write an interrupt, or multithreading, but I just need some guidance. Thanks!