From f72538fc63ad07767b3e316eed4fe7d6874bdbba Mon Sep 17 00:00:00 2001 From: Ulf Borcherdt Date: Fri, 6 Jan 2023 23:57:37 +0100 Subject: [PATCH] Code in echten Code konvertiert --- inc/robot_inc.py | 22 ++++++++++++++-------- robot-a.py | 23 ++++++++++++++++------- 2 files changed, 30 insertions(+), 15 deletions(-) diff --git a/inc/robot_inc.py b/inc/robot_inc.py index 8670cbd..75cd49b 100644 --- a/inc/robot_inc.py +++ b/inc/robot_inc.py @@ -1,8 +1,10 @@ #!/usr/bin/env python2 -import RPi.GPIO as GPIO -import time +#-*- coding:utf-8 -*- -valid_led = [32,15,31,22,3,5]; +import RPi.GPIO as GPIO +from time import sleep + +valid_led = [32,15,31,22,3,5] GPIO_23=22 GPIO_17=32 @@ -13,16 +15,20 @@ GPIO_2=3 GPIO_3=5 def gpio_on (theGPIO): - # param1=INT # gpio#Nr + # param1=INT # gpio#Nr GPIO.setup(theGPIO, GPIO.OUT) - GPIO.output(theGPIO,True) # lamp on +# print "GPIO.setup(" + str(theGPIO) + ", GPIO.OUT)" + GPIO.output(theGPIO,True) # lamp on +# print "GPIO.output(" + str(theGPIO) + ",True)" # lamp on + def gpio_off (theGPIO): -# param1=INT # gpio#Nr + # param1=INT # gpio#Nr GPIO.setup(theGPIO, GPIO.OUT) - GPIO.output(theGPIO,False) # lamp on + GPIO.output(theGPIO,False) # lamp off +# 50 milliseconds = miliSec = 0.05 def gpio_on_for (theGPIO, miliSec): gpio_on (theGPIO) - sleep miliSec + sleep (miliSec) gpio_off (theGPIO) diff --git a/robot-a.py b/robot-a.py index e11a8b5..b1c75cc 100644 --- a/robot-a.py +++ b/robot-a.py @@ -1,13 +1,22 @@ -import inc/robot-inc +#!/usr/bin/env python2 +#-*- coding:utf-8 -*- + +import sys +sys.path.append("inc") +from robot_inc import * linkeFlasche=GPIO_17 rechteFlasche=GPIO_27 # Rezept für Apfelsaft -gpio_on linkeFlasche -sleep 0.5 -gpio_off linkeFlasche +gpio_on (linkeFlasche) +sleep (0.5) +gpio_off (linkeFlasche) -gpio_on rechteFlasche -sleep 1.5 -gpio_off rechteFlasche +gpio_on (rechteFlasche) +sleep (1.5) +gpio_off (rechteFlasche) + +# oder in einer Funktion +#gpio_on_for (linkeFlasche, 0.5) +#gpio_on_for (rechteFlasche, 1.5)