Noob script question

Python and python framework

Moderator: leecollings

Post Reply
edwin1234
Posts: 340
Joined: Sunday 09 October 2016 20:20
Target OS: Raspberry Pi / ODroid
Domoticz version: 2021.1
Location: Nederland
Contact:

Noob script question

Post by edwin1234 »

Hi iam a noob at this,
I want to no how to and this script without entering ctrl c
So let the servo turn and then automaticly end this script gracefully.
Heres the script:


#!/bin/python

# importeer de GPIO bibliotheek.
import RPi.GPIO as GPIO
# Importeer de time biblotheek voor tijdfuncties.
from time import sleep

# Zet de pinmode op Broadcom SOC.
GPIO.setmode(GPIO.BCM)
# Zet waarschuwingen uit.
GPIO.setwarnings(False)

# Zet de GPIO pin als uitgang.
GPIO.setup(4, GPIO.OUT)
# Configureer de pin voor PWM met een frequentie van 50Hz.
p = GPIO.PWM(4, 50)
# Start PWM op de GPIO pin met een duty-cycle van 6%
p.start(6)

try:
while True:
# 0 graden (neutraal)
p.ChangeDutyCycle(6)
sleep(1)

# -90 graden (rechts)
p.ChangeDutyCycle(2.5)
sleep(1)

# 0 graden (neutraal)
p.ChangeDutyCycle(6)
sleep(1)

# 90 graden (links)
p.ChangeDutyCycle(11)
sleep(1)

except KeyboardInterrupt:
# Stop PWM op GPIO.
p.stop()
# GPIO netjes afsluiten
GPIO.cleanup()
User avatar
Thuis
Posts: 290
Joined: Tuesday 11 September 2018 11:36
Target OS: Linux
Domoticz version: Beta
Location: The Netherlands
Contact:

Re: Noob script question

Post by Thuis »

import sys
sys.exit()


import os
os._exit(0)



raise SystemExit
Fun for everyone!
Post Reply