Page 1 of 1

Noob script question

Posted: Friday 17 January 2020 10:01
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()

Re: Noob script question

Posted: Wednesday 01 April 2020 19:42
by Thuis
import sys
sys.exit()


import os
os._exit(0)



raise SystemExit