Mag pi 6 code page 11

English

Fran?ais

#!/usr/bin/pyton
#Input test with visual indication
import RPi.GPIO as GPIO
import time

#Change to BCM GPIO Numbering
GPIO.setmode(GPIO.BCM)

#(pull_up_down be PUD_OFF, PUD_UP or
# PUD_DOWN, default PUD_OFF)
GPIO.setup(4, GPIO.IN, pull_up_down = GPIO.PUD_UP)

# test for pin able to go high
if GPIO.input(4):
    print ('input True Good')
    time.sleep(0.2)
    GPIO.setup(4, GPIO.IN,pull_up_down=GPIO.PUD_DOWN)
else:
    print ('Fault input - pin4')
    time.sleep(1)
    quit()

# test for pin able to go low
if GPIO.input(4):
    print ('Faulty Input - pin4')
    time.sleep(1)
    quit()
else:
    print ('Input False Good')
    time.sleep(1)

#if it gets to here, inputs' states
#are both achievable
print ('Inputs tested Good')

#commence the buton demo

print('Press the Button')

while True:

    # set the pin high and
    # wait for button press
    GPIO.setup(4, GPIO.IN,pull_up_down=GPIO.PUD_UP)

    # button pressed
    if not GPIO.input(4):
        print ('button pressed')
        time.sleep(1)

        # button released
        if GPIO.input(4):
            print ('button pressed')
            flash = 20
            GPIO.setup(4, GPIO.OUT)

            # flash until
            while flash > 0:
                GPIO.output(4, true)
                time.sleep(0.1)
                GPIO.output(4, false)
                time.sleep(0.1)
                flash -=1

            print('press buton')

#!/usr/bin/pyton
#Test d'une entr?e avec indication visuelle
import RPi.GPIO as GPIO
import time

#Utilisation de la num?rotation BCM du GPIO
GPIO.setmode(GPIO.BCM)

#(pull_up_down peut valoir PUD_OFF, PUD_UP ou
#PUD_DOWN, PUD_OFF par d?faut)
GPIO.setup(4, GPIO.IN, pull_up_down = GPIO.PUD_UP)

# test si la broche peut atteindre l'?tat haut
if GPIO.input(4):
    print ('Entr?e ? l'?tat haut -Correct')
    time.sleep(0.2)
    GPIO.setup(4, GPIO.IN,pull_up_down=GPIO.PUD_DOWN)
else:
    print ('Entr?e en d?faut - pin4')
    time.sleep(1)
    quit()

# test si la broche peut atteindre l'?tat bas
if GPIO.input(4):
    print ('Entr?e en d?faut - pin4')
    time.sleep(1)
    quit()
else:
    print ('Entr?e ? l'?tat bas -Correct')
    time.sleep(1)

#Si on arrive ici , Les ?tats haut et bas des entr?es
#sont atteignables
print ('Test des entr?es - Correct')

# D?but de la d?mo avec le bouton

print('Appuyez sur le bouton')

while True:

    # Positionner l'entr?e ? l'?tat haut et
    # attendre un appui sur le bouton
    GPIO.setup(4, GPIO.IN,pull_up_down=GPIO.PUD_UP)

    # bouton enfonc?
    if not GPIO.input(4):
        print ('bouton enfonc?')
        time.sleep(1)

        # Bouton relach?
        if GPIO.input(4):
            print ('Bouton relach?')
            flash = 20
            GPIO.setup(4, GPIO.OUT)

            # Tant que flash >0 (20 fois)
            while flash > 0:
                GPIO.output(4, true)
                time.sleep(0.1)
                GPIO.output(4, false)
                time.sleep(0.1)
                flash -=1

            print('Appuyez sur le bouton')

No module Published on Offcanvas position