Created
February 3, 2020 15:40
-
-
Save ustropo/1214ed5774b71063bde8751687372d49 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import RPi.GPIO as GPIO | |
import time | |
LedPin = 12 # pin12 --- led | |
BtnPin = 18 # pin12 --- button | |
GPIO.setmode(GPIO.BOARD) # Pinagem física | |
GPIO.setup(LedPin, GPIO.OUT) # Pino de led como saída | |
GPIO.setup(BtnPin, GPIO.IN, pull_up_down=GPIO.PUD_UP) # Pino do botão como saída e aciona o pull-up | |
GPIO.output(LedPin, GPIO.HIGH) # Desliga o led | |
print('Pressione Ctrl+C para sair') | |
# Loop principal | |
try: | |
while True: | |
# Como estamos usando o botao no pino 18, sem acionar o nivel ja e | |
# alto. Quando pressionado, ele envia o sinal de terra ao pino. | |
# Por isso recebemos nível baixo ao ser pressionado. | |
if GPIO.input(BtnPin) == GPIO.LOW: | |
print('Liga o LED...') | |
GPIO.output(LedPin, 1) | |
else: | |
print('Desliga o LED...') | |
GPIO.output(LedPin, 0) | |
# Aguarda um tempo | |
time.sleep(1) | |
except KeyboardInterrupt: | |
# Ctrl+C foi pressionado | |
pass | |
GPIO.output(LedPin, 0) | |
GPIO.cleanup() # Limpa configuração |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment