Ejemplo n.º 1
0
def servo_berputar():
    try:
        while True:
            p.ChangeDutyCycle(2)
            time.sleep(0.5)
            p.ChangeDutyCycle(6)
            time.sleep(0.5)
    except:
        p.stop()
        GPIO.stop()
Ejemplo n.º 2
0
def test(request):

    p.ChangeDutyCycle(100)
    #�닔
    if 'up' in request.POST:
        print("up")
        GPIO.output(in1, GPIO.LOW)
        GPIO.output(in2, GPIO.HIGH)

    elif 'down' in request.POST:
        print("down")
        GPIO.output(in1, GPIO.HIGH)
        GPIO.output(in2, GPIO.LOW)

    elif 'stop' in request.POST:
        print("stop")
        GPIO.output(in1, GPIO.LOW)
        GPIO.output(in2, GPIO.LOW)

    elif 'upRes' in request.POST:  # time.sleep() �썑 stop   #�떒�쐞 蹂꾩씠�룞
        print("complete")
        global time
        x = int(request.POST.get('time'))
        GPIO.output(in1, GPIO.HIGH)
        GPIO.output(in2, GPIO.LOW)
        i = x * 0.2
        time.sleep(int(i))
        GPIO.output(in1, GPIO.LOW)
        GPIO.output(in2, GPIO.LOW)

    elif 'downRes' in request.POST:
        print("complete")
        global time
        x = int(request.POST.get('time'))
        GPIO.output(in1, GPIO.LOW)
        GPIO.output(in2, GPIO.HIGH)
        i = x * 0.2
        time.sleep(i)
        GPIO.output(in1, GPIO.LOW)
        GPIO.output(in2, GPIO.LOW)

    elif 'off' in request.POST:
        GPIO.stop()
        GPIO.cleanup()
        print("GPIO Clean up")

    else:
        print("<<<  wrong data  >>>")
    return render(request, "test(re).html")
Ejemplo n.º 3
0
def servo_berputar():
    try:
        servoPIN = 19
        GPIO.setmode(GPIO.BCM)
        GPIO.setup(servoPIN, GPIO.OUT)
        GPIO.setwarnings(False)
        p = GPIO.PWM(servoPIN, 50)
        p.start(0)
        repeat = 3
        while repeat > 0:
            p.ChangeDutyCycle(2)
            print(datetime.datetime.now)
            time.sleep(0.5)
            p.ChangeDutyCycle(6)
            time.sleep(0.5)
            repeat = repeat - 1
    except:
        p.stop()
        GPIO.stop()
Ejemplo n.º 4
0
def destroy():
    GPIO.stop()
    GPIO.cleanup()
Ejemplo n.º 5
0
# check your SELECT gpio(BCM) pin number at https://pinout.xyz/
# Joysticks connected to GPIOs at https://github.com/recalbox/mk_arcade_joystick_rpi
SELECT = 21  # GPIO Pin Number
SENSOR = 29  # GPIO Pin Number
DELAY = 1

GPIO.setmode(GPIO.BOARD)

GPIO.setup(SENSOR, GPIO.IN)
GPIO.setup(SELECT, GPIO.OUT)
try:
    while True:

        if GPIO.input(SENSOR) == GPIO.LOW:
            if DELAY == 1:
                time.sleep(0.5)
                GPIO.output(SELECT, GPIO.LOW)  # select ON
                time.sleep(0.05)
                DELAY = 0
                #print "Coin Detected"
            else:
                GPIO.output(SELECT, GPIO.LOW)  # select ON
        else:
            DELAY = 1
            GPIO.output(SELECT, GPIO.HIGH)  # select OFF
            time.sleep(0.05)
            #print "Coin no detected"

except KeyboardInterrupt:
    GPIO.stop()
Ejemplo n.º 6
0
def cleanup():
    print ("Cleaning up")
    GPIO.stop()