Why does my python script work in Thonny but not from the console? (And yes I've tried running it from the console using python3.) Does Thonny run it in a loop that the console doesn't? Thank you.
# Copyright 2019 PK Holdings LLC
import RPi.GPIO as GPIO
from gpiozero import Button
from time import sleep
import sys
import gpiozero
import threading
# Pin Definitions
buttonPin = 17 # Broadcom pin 17
global alarm_running
alarm_running = False
def run():
# This function sounds the audio alarm(s).
# Set up Sound
global alarm_running
while True:
print("ALARM RUNNING")
sleep(2)
if not alarm_running:
break
def quiet_audio_alarm():
global alarm_running
alarm_running = False
def contact_made():
# This function is called when contact is made between the leads.
global alarm_running
alarm_running = True
global thread1
thread1 = threading.Thread(target = run)
thread1.start()
def no_contact():
quiet_audio_alarm()
global alarm_running
alarm_running = False
# This join should kill the thread thread1.
global thread1
thread1.join()
print("ALARM STOPPED")
print("Assigning button")
button=Button(17)
print("Assigning pressed function")
button.when_pressed = contact_made
print("Assigning release function")
button.when_released = no_contact